From 19fb79c722622ac4a068e258501ab4b161420cda Mon Sep 17 00:00:00 2001 From: bigbiff bigbiff Date: Mon, 5 Sep 2016 21:04:51 -0400 Subject: ADB Backup: add ability for TWRP GUI to restore Restore adb backup files that TWRP made to your PC. Put files in your backup directory to see them. e.g. /sdcard/TWRP/BACKUPS/ Change-Id: I2c57970d77b64c39a302159041456e761c185259 --- gui/action.cpp | 46 ++++++++++++++++++++++++++++-------------- gui/fileselector.cpp | 10 ++++++--- gui/gui.cpp | 8 -------- gui/theme/common/landscape.xml | 3 ++- gui/theme/common/portrait.xml | 3 ++- gui/theme/common/watch.xml | 3 ++- 6 files changed, 44 insertions(+), 29 deletions(-) (limited to 'gui') diff --git a/gui/action.cpp b/gui/action.cpp index 05ae46515..039c4ef43 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -566,6 +566,7 @@ int GUIAction::reload(std::string arg __unused) int GUIAction::readBackup(std::string arg __unused) { string Restore_Name; + DataManager::GetValue("tw_restore", Restore_Name); PartitionManager.Set_Restore_Files(Restore_Name); return 0; @@ -1192,6 +1193,18 @@ int GUIAction::nandroid(std::string arg) string auto_gen = gui_lookup("auto_generate", "(Auto Generate)"); if (Backup_Name == auto_gen || Backup_Name == gui_lookup("curr_date", "(Current Date)") || Backup_Name == "0" || Backup_Name == "(" || PartitionManager.Check_Backup_Name(true) == 0) { ret = PartitionManager.Run_Backup(false); + DataManager::SetValue("tw_encrypt_backup", 0); // reset value so we don't encrypt every subsequent backup + if (!PartitionManager.stop_backup.get_value()) { + if (ret == false) + ret = 1; // 1 for failure + else + ret = 0; // 0 for success + DataManager::SetValue("tw_cancel_backup", 0); + } else { + DataManager::SetValue("tw_cancel_backup", 1); + gui_msg("backup_cancel=Backup Cancelled"); + ret = 0; + } } else { operation_end(1); return -1; @@ -1199,25 +1212,28 @@ int GUIAction::nandroid(std::string arg) DataManager::SetValue(TW_BACKUP_NAME, auto_gen); } else if (arg == "restore") { string Restore_Name; + int gui_adb_backup; + DataManager::GetValue("tw_restore", Restore_Name); - ret = PartitionManager.Run_Restore(Restore_Name); + DataManager::GetValue("tw_enable_adb_backup", gui_adb_backup); + if (gui_adb_backup) { + DataManager::SetValue("tw_operation_state", 1); + if (TWFunc::stream_adb_backup(Restore_Name) == 0) + ret = 0; // success + else + ret = 1; // failure + DataManager::SetValue("tw_enable_adb_backup", 0); + ret = 0; // assume success??? + } else { + if (PartitionManager.Run_Restore(Restore_Name)) + ret = 0; // success + else + ret = 1; // failure + } } else { - operation_end(1); + operation_end(1); // invalid arg specified, fail return -1; } - DataManager::SetValue("tw_encrypt_backup", 0); - if (!PartitionManager.stop_backup.get_value()) { - if (ret == false) - ret = 1; // 1 for failure - else - ret = 0; // 0 for success - DataManager::SetValue("tw_cancel_backup", 0); - } - else { - DataManager::SetValue("tw_cancel_backup", 1); - gui_msg("backup_cancel=Backup Cancelled"); - ret = 0; - } operation_end(ret); return ret; } diff --git a/gui/fileselector.cpp b/gui/fileselector.cpp index a992b80ea..c4aaab168 100644 --- a/gui/fileselector.cpp +++ b/gui/fileselector.cpp @@ -30,6 +30,7 @@ extern "C" { #include "objects.hpp" #include "../data.hpp" #include "../twrp-functions.hpp" +#include "../adbbu/libtwadbbu.hpp" int GUIFileSelector::mSortOrder = 0; @@ -270,7 +271,10 @@ int GUIFileSelector::GetFileList(const std::string folder) mFolderList.push_back(data); } else if (data.fileType == DT_REG || data.fileType == DT_LNK || data.fileType == DT_BLK) { if (mExtn.empty() || (data.fileName.length() > mExtn.length() && data.fileName.substr(data.fileName.length() - mExtn.length()) == mExtn)) { - mFileList.push_back(data); + if (mExtn == ".ab" && twadbbu::Check_ADB_Backup_File(path)) + mFolderList.push_back(data); + else + mFileList.push_back(data); } } } @@ -354,8 +358,8 @@ void GUIFileSelector::NotifySelect(size_t item_selected) cwd += str; } - if (mShowNavFolders == 0 && mShowFiles == 0) { - // nav folders and files are disabled, this is probably the restore list and we need to save chosen location to mVariable instead of mPathVar + if (mShowNavFolders == 0 && (mShowFiles == 0 || mExtn == ".ab")) { + // this is probably the restore list and we need to save chosen location to mVariable instead of mPathVar DataManager::SetValue(mVariable, cwd); } else { // We are changing paths, so we need to set mPathVar diff --git a/gui/gui.cpp b/gui/gui.cpp index 369b6b897..a70dadfd2 100644 --- a/gui/gui.cpp +++ b/gui/gui.cpp @@ -462,14 +462,6 @@ static void ors_command_read() gui_set_FILE(orsout); PageManager::GetResources()->DumpStrings(); ors_command_done(); - //check to see if we should show backup page for parsing adbbackup partitions - } else if (strlen(command) == 23 && strncmp(command, "adbbackup", 9) == 0) { - gui_set_FILE(orsout); - DataManager::SetValue("tw_action", "twcmd"); - DataManager::SetValue("tw_action_param", command); - DataManager::SetValue("tw_enable_adb_backup", 1); - gui_changePage("backup"); - ors_command_done(); } else { // mirror output messages gui_set_FILE(orsout); diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml index c3d89fe2d..f460e6fee 100644 --- a/gui/theme/common/landscape.xml +++ b/gui/theme/common/landscape.xml @@ -2047,7 +2047,7 @@ {@restore_sel_pack_fs=Select Package to Restore:} - + @@ -2273,6 +2273,7 @@ + {@restore_enable_digest_chk=Enable Digest Verification of Backup Files} diff --git a/gui/theme/common/portrait.xml b/gui/theme/common/portrait.xml index f163bea8b..0d1d6d8a2 100644 --- a/gui/theme/common/portrait.xml +++ b/gui/theme/common/portrait.xml @@ -2209,7 +2209,7 @@ {@restore_sel_pack_fs=Select Package to Restore:} - + @@ -2429,6 +2429,7 @@ + {@restore_enable_digest_chk=Enable Digest Verification of Backup Files} diff --git a/gui/theme/common/watch.xml b/gui/theme/common/watch.xml index d5ef86972..152818e72 100644 --- a/gui/theme/common/watch.xml +++ b/gui/theme/common/watch.xml @@ -2551,7 +2551,7 @@ %tw_storage_display_name% - + @@ -2807,6 +2807,7 @@ + -- cgit v1.2.3