diff --git a/data.cpp b/data.cpp index c45f27c5..e7b2f613 100755 --- a/data.cpp +++ b/data.cpp @@ -526,7 +526,7 @@ void DataManager::SetBackupFolder() { string str = GetCurrentStoragePath(); TWPartition* partition = PartitionManager.Find_Partition_By_Path(str); - str += "/TWRP/BACKUPS/"; + str += TWFunc::Check_For_TwrpFolder() + "/BACKUPS/"; string dev_id; GetValue("device_id", dev_id); @@ -613,9 +613,11 @@ void DataManager::SetDefaultValues() mConst.SetValue(TW_SHOW_DUMLOCK, "0"); #endif + mData.SetValue(TW_RECOVERY_FOLDER_VAR, TW_DEFAULT_RECOVERY_FOLDER); + str = GetCurrentStoragePath(); mPersist.SetValue(TW_ZIP_LOCATION_VAR, str); - str += "/TWRP/BACKUPS/"; + str += DataManager::GetStrValue(TW_RECOVERY_FOLDER_VAR) + "/BACKUPS/"; string dev_id; mConst.GetValue("device_id", dev_id); @@ -1111,8 +1113,8 @@ void DataManager::ReadSettingsFile(void) memset(mkdir_path, 0, sizeof(mkdir_path)); memset(settings_file, 0, sizeof(settings_file)); - sprintf(mkdir_path, "%s/TWRP", GetSettingsStoragePath().c_str()); - sprintf(settings_file, "%s/.twrps", mkdir_path); + sprintf(mkdir_path, "%s%s", GetSettingsStoragePath().c_str(), GetStrValue(TW_RECOVERY_FOLDER_VAR).c_str()); + sprintf(settings_file, "%s/%s", mkdir_path, TW_SETTINGS_FILE); if (!PartitionManager.Mount_Settings_Storage(false)) { @@ -1152,3 +1154,11 @@ void DataManager::Vibrate(const string& varName) } #endif } + + +void DataManager::LoadTWRPFolderInfo(void) +{ + string mainPath = GetCurrentStoragePath(); + SetValue(TW_RECOVERY_FOLDER_VAR, TWFunc::Check_For_TwrpFolder()); + mBackingFile = mainPath + GetStrValue(TW_RECOVERY_FOLDER_VAR) + '/' + TW_SETTINGS_FILE; +} \ No newline at end of file diff --git a/data.hpp b/data.hpp index bb73c415..843bef20 100755 --- a/data.hpp +++ b/data.hpp @@ -32,6 +32,7 @@ public: static int LoadValues(const string& filename); static int LoadPersistValues(void); static int Flush(); + static void LoadTWRPFolderInfo(void); // Core get routines static int GetValue(const string& varName, string& value); @@ -63,8 +64,10 @@ public: static string GetCurrentStoragePath(void); static string GetSettingsStoragePath(void); -protected: +public: static string mBackingFile; + +protected: static int mInitialized; static InfoManager mPersist; static InfoManager mData; diff --git a/gui/action.cpp b/gui/action.cpp index 20c30748..b67b0da1 100755 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -242,6 +242,7 @@ GUIAction::GUIAction(xml_node<>* node) ADD_ACTION(uninstalltwrpsystemapp); ADD_ACTION(repackimage); ADD_ACTION(fixabrecoverybootloop); + ADD_ACTION(applycustomtwrpfolder); #ifndef TW_EXCLUDE_NANO ADD_ACTION(editfile); #endif @@ -2287,3 +2288,36 @@ int GUIAction::editfile(std::string arg) { return 0; } #endif + +int GUIAction::applycustomtwrpfolder(string arg __unused) +{ + operation_start("ChangingTWRPFolder"); + string storageFolder = DataManager::GetSettingsStoragePath(); + string newFolder = storageFolder + '/' + arg; + string newBackupFolder = newFolder + "/BACKUPS/" + DataManager::GetStrValue("device_id"); + string prevFolder = storageFolder + DataManager::GetStrValue(TW_RECOVERY_FOLDER_VAR); + bool ret = false; + + if (TWFunc::Path_Exists(newFolder)) { + gui_msg(Msg(msg::kError, "tw_folder_exists=A folder with that name already exists!")); + } else { + ret = true; + } + + if (newFolder != prevFolder && ret) { + ret = TWFunc::Exec_Cmd("mv -f \"" + prevFolder + "\" \"" + newFolder + '\"') != 0 ? false : true; + } else { + gui_msg(Msg(msg::kError, "tw_folder_exists=A folder with that name already exists!")); + } + + if (ret) ret = TWFunc::Recursive_Mkdir("\"" + newBackupFolder + "\"") ? true : false; + + + if (ret) { + DataManager::SetValue(TW_RECOVERY_FOLDER_VAR, '/' + arg); + DataManager::SetValue(TW_BACKUPS_FOLDER_VAR, newBackupFolder); + DataManager::mBackingFile = newFolder + '/' + TW_SETTINGS_FILE; + } + operation_end((int)!ret); + return 0; +} diff --git a/gui/objects.hpp b/gui/objects.hpp index 0f2fae58..d4b42c29 100755 --- a/gui/objects.hpp +++ b/gui/objects.hpp @@ -374,9 +374,11 @@ protected: int enableadb(std::string arg); int enablefastboot(std::string arg); int changeterminal(std::string arg); + int applycustomtwrpfolder(std::string arg); #ifndef TW_EXCLUDE_NANO int editfile(std::string arg); #endif + int simulate; }; diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml index cf14acea..b8c20988 100755 --- a/gui/theme/common/landscape.xml +++ b/gui/theme/common/landscape.xml @@ -3627,6 +3627,10 @@ + + + changeTwrpFolder + @@ -5779,5 +5783,102 @@ edi advanced + + +