From 11e90832d3834f2ecf32c5e1508d25c96df1a646 Mon Sep 17 00:00:00 2001 From: epicX Date: Mon, 1 Mar 2021 00:02:57 +0530 Subject: [PATCH] Fixes for Add support to change TWRP Folder Change-Id: I66a66cc6b952c1aae45c50a8f40c00febce69462 --- gui/action.cpp | 2 +- twrp-functions.cpp | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/gui/action.cpp b/gui/action.cpp index b67b0da1..a3108579 100755 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -2310,7 +2310,7 @@ int GUIAction::applycustomtwrpfolder(string arg __unused) 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) ret = TWFunc::Recursive_Mkdir(newBackupFolder) ? true : false; if (ret) { diff --git a/twrp-functions.cpp b/twrp-functions.cpp index 20f2e950..16a3653f 100755 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -1422,7 +1422,7 @@ string TWFunc::Check_For_TwrpFolder() { DIR* d; struct dirent* de; - if(DataManager::GetIntValue(TW_IS_ENCRYPTED)) { + if (DataManager::GetIntValue(TW_IS_ENCRYPTED)) { goto exit; } @@ -1437,14 +1437,14 @@ string TWFunc::Check_For_TwrpFolder() { string fullPath = mainPath + '/' + name; unsigned char type = de->d_type; - if(name == "." || name == "..") continue; + if (name == "." || name == "..") continue; - if(type == DT_UNKNOWN) { + if (type == DT_UNKNOWN) { type = Get_D_Type_From_Stat(fullPath); } - if(type == DT_DIR && Path_Exists(fullPath + '/' + TW_SETTINGS_FILE)) { - if('/' + name == TW_DEFAULT_RECOVERY_FOLDER){ + if (type == DT_DIR && Path_Exists(fullPath + '/' + TW_SETTINGS_FILE)) { + if ('/' + name == TW_DEFAULT_RECOVERY_FOLDER) { oldFolder = name; } else { customTWRPFolders.push_back(name); @@ -1454,25 +1454,25 @@ string TWFunc::Check_For_TwrpFolder() { closedir(d); - if(oldFolder == "" && customTWRPFolders.empty()) { + if (oldFolder == "" && customTWRPFolders.empty()) { LOGINFO("No recovery folder found. Using default folder.\n"); goto exit; - } else if(customTWRPFolders.empty()) { + } else if (customTWRPFolders.empty()) { LOGINFO("No custom recovery folder found. Using TWRP as default.\n"); goto exit; } else { - if(customTWRPFolders.size() > 1) { + if (customTWRPFolders.size() > 1) { LOGINFO("More than one custom recovery folder found. Using first one from the list.\n"); } else { LOGINFO("One custom recovery folder found.\n"); } string customPath = '/' + customTWRPFolders.at(0); - if(Path_Exists(mainPath + TW_DEFAULT_RECOVERY_FOLDER)) { + if (Path_Exists(mainPath + TW_DEFAULT_RECOVERY_FOLDER)) { string oldBackupFolder = mainPath + TW_DEFAULT_RECOVERY_FOLDER + "/BACKUPS/" + DataManager::GetStrValue("device_id"); string newBackupFolder = mainPath + customPath + "/BACKUPS/" + DataManager::GetStrValue("device_id"); - if(Path_Exists(oldBackupFolder)) { + if (Path_Exists(oldBackupFolder)) { vector backups; d = opendir(oldBackupFolder.c_str()); @@ -1481,20 +1481,20 @@ string TWFunc::Check_For_TwrpFolder() { string name = de->d_name; unsigned char type = de->d_type; - if(name == "." || name == "..") continue; + if (name == "." || name == "..") continue; - if(type == DT_UNKNOWN) { + if (type == DT_UNKNOWN) { type = Get_D_Type_From_Stat(mainPath + '/' + name); } - if(type == DT_DIR) { + if (type == DT_DIR) { backups.push_back(name); } } closedir(d); } - for(auto it = backups.begin(); it != backups.end(); it++) { + for (auto it = backups.begin(); it != backups.end(); it++) { Exec_Cmd("mv -f \"" + oldBackupFolder + '/' + *it + "\" \"" + newBackupFolder + '/' + *it + (Path_Exists(newBackupFolder + '/' + *it) ? "_new\"" : "\"")); } }