From 7abc5fe195cfa203d215781e2a04672cebecca1e Mon Sep 17 00:00:00 2001 From: bigbiff Date: Sat, 17 Jan 2015 16:53:12 -0500 Subject: Add cancel backup capability. This will stop the iteration of the partition objects, kill the current twrpTar thread and remove the backup directory. Implement TWAtomicInt class to give us a wrapper that automatically uses mutexes before the read and write to help ensure that the reads and writes will be atomic based on documentation. Change-Id: I645b22bc980a292e9c7202acb24ffd22ebe68c63 --- gui/action.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) (limited to 'gui/action.cpp') diff --git a/gui/action.cpp b/gui/action.cpp index d75843044..e7f74d48a 100644 --- a/gui/action.cpp +++ b/gui/action.cpp @@ -56,6 +56,7 @@ extern "C" { #include "rapidxml.hpp" #include "objects.hpp" +#include "../tw_atomic.hpp" void curtainClose(void); @@ -169,6 +170,7 @@ GUIAction::GUIAction(xml_node<>* node) mf["fixsu"] = &GUIAction::fixsu; mf["startmtp"] = &GUIAction::startmtp; mf["stopmtp"] = &GUIAction::stopmtp; + mf["cancelbackup"] = &GUIAction::cancelbackup; // remember actions that run in the caller thread for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it) @@ -314,6 +316,13 @@ void GUIAction::simulate_progress_bar(void) gui_print("Simulating actions...\n"); for (int i = 0; i < 5; i++) { + if (PartitionManager.stop_backup.get_value()) { + DataManager::SetValue("tw_cancel_backup", 1); + gui_print("Backup Canceled.\n"); + DataManager::SetValue("ui_progress", 0); + PartitionManager.stop_backup.set_value(0); + return; + } usleep(500000); DataManager::SetValue("ui_progress", i * 20); } @@ -1087,13 +1096,13 @@ int GUIAction::refreshsizes(std::string arg) int GUIAction::nandroid(std::string arg) { - operation_start("Nandroid"); - int ret = 0; - if (simulate) { DataManager::SetValue("tw_partition", "Simulation"); simulate_progress_bar(); } else { + operation_start("Nandroid"); + int ret = 0; + if (arg == "backup") { string Backup_Name; DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); @@ -1103,7 +1112,6 @@ int GUIAction::nandroid(std::string arg) else { operation_end(1); return -1; - } DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)"); } else if (arg == "restore") { @@ -1112,16 +1120,42 @@ int GUIAction::nandroid(std::string arg) ret = PartitionManager.Run_Restore(Restore_Name); } else { operation_end(1); - return -1; - } - } - DataManager::SetValue("tw_encrypt_backup", 0); + 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); operation_end(ret); - return 0; + } + else { + DataManager::SetValue("tw_cancel_backup", 1); + gui_print("Backup Canceled.\n"); + ret = 0; + } + return ret; + } + return 0; +} + +int GUIAction::cancelbackup(std::string arg) { + if (simulate) { + simulate_progress_bar(); + PartitionManager.stop_backup.set_value(1); + operation_end(0); + } + else { + operation_start("Cancel Backup"); + int op_status = PartitionManager.Cancel_Backup(); + if (op_status != 0) + op_status = 1; // failure + operation_end(op_status); + } + + return 0; } int GUIAction::fixpermissions(std::string arg) -- cgit v1.2.3