gui: Handle theme versioning in the specified package
Signed-off-by: Mohd Faraz <androiabledroid@gmail.com>
Change-Id: I40d727cd42c778a2c09a72043ce75c7c8b9cfacb
diff --git a/Android.mk b/Android.mk
index f27ac4b..c759b8b 100755
--- a/Android.mk
+++ b/Android.mk
@@ -566,12 +566,6 @@
LOCAL_REQUIRED_MODULES += $(TWRP_REQUIRED_MODULES)
-TW_THEME_VERSION := $(shell grep TW_THEME_VERSION bootable/recovery/variables.h | cut -d ' ' -f 3)
-
-LOCAL_POST_INSTALL_CMD += \
- sed -i "s/{themeversion}/$(TW_THEME_VERSION)/" $(TARGET_RECOVERY_ROOT_OUT)/twres/splash.xml; \
- sed -i "s/{themeversion}/$(TW_THEME_VERSION)/" $(TARGET_RECOVERY_ROOT_OUT)/twres/ui.xml;
-
include $(BUILD_EXECUTABLE)
# Symlink for file_contexts
diff --git a/gui/libguitwrp_defaults.go b/gui/libguitwrp_defaults.go
index 4c64f50..222564c 100644
--- a/gui/libguitwrp_defaults.go
+++ b/gui/libguitwrp_defaults.go
@@ -4,6 +4,7 @@
"android/soong/android"
"android/soong/cc"
"fmt"
+ "io/ioutil"
"os"
"path"
"strconv"
@@ -64,6 +65,31 @@
fileDest := twRes + path.Base(file)
copyFile(fileToCopy, fileDest)
}
+ data, err := ioutil.ReadFile(recoveryDir + "variables.h")
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ version := "0"
+ for _, line := range strings.Split(string(data), "\n") {
+ if strings.Contains(line, "TW_THEME_VERSION") {
+ version = strings.Split(line, " ")[2]
+ }
+ }
+ _files := [2]string{"splash.xml", "ui.xml"}
+ for _, i := range _files {
+ data, err = ioutil.ReadFile(twRes + i)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ newFile := strings.Replace(string(data), "{themeversion}", version, -1)
+ err = ioutil.WriteFile(twRes + i, []byte(newFile), 0)
+ if err != nil {
+ fmt.Println(err)
+ return
+ }
+ }
}
func copyCustomTheme(ctx android.BaseContext, customTheme string) {