int GUIAction::fileexists(std::string arg) { struct stat st; string newpath = arg + "/."; operation_start("FileExists"); if (stat(arg.c_str(), &st) == 0 || stat(newpath.c_str(), &st) == 0) operation_end(0); else operation_end(1); return 0; }
int GUIAction::adbsideload(std::string arg) { operation_start("Sideload"); if (simulate) { simulate_progress_bar(); operation_end(0); } else { gui_print("Starting ADB sideload feature...\n"); bool mtp_was_enabled = TWFunc::Toggle_MTP(false); // wait for the adb connection int ret = apply_from_adb("/", &sideload_child_pid); DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start if (ret != 0) { if (ret == -2) gui_print("You need adb 1.0.32 or newer to sideload to this device.\n"); ret = 1; // failure } else { int wipe_cache = 0; int wipe_dalvik = 0; DataManager::GetValue("tw_wipe_dalvik", wipe_dalvik); if (TWinstall_zip(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache) == 0) { if (wipe_cache || DataManager::GetIntValue("tw_wipe_cache")) PartitionManager.Wipe_By_Path("/cache"); if (wipe_dalvik) PartitionManager.Wipe_Dalvik_Cache(); } else { ret = 1; // failure } } if (sideload_child_pid) { LOGINFO("Signaling child sideload process to exit.\n"); struct stat st; // Calling stat() on this magic filename signals the minadbd // subprocess to shut down. stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st); int status; LOGINFO("Waiting for child sideload process to exit.\n"); waitpid(sideload_child_pid, &status, 0); } property_set("ctl.start", "adbd"); TWFunc::Toggle_MTP(mtp_was_enabled); reinject_after_flash(); operation_end(ret); } return 0; }
int GUIAction::nandroid(std::string arg) { if (simulate) { PartitionManager.stop_backup.set_value(0); DataManager::SetValue("tw_partition", "Simulation"); simulate_progress_bar(); operation_end(0); } else { operation_start("Nandroid"); int ret = 0; if (arg == "backup") { string Backup_Name; DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); if (Backup_Name == "(Auto Generate)" || Backup_Name == "(Current Date)" || Backup_Name == "0" || Backup_Name == "(" || PartitionManager.Check_Backup_Name(true) == 0) { ret = PartitionManager.Run_Backup(); } else { operation_end(1); return -1; } DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)"); } else if (arg == "restore") { string Restore_Name; DataManager::GetValue("tw_restore", Restore_Name); ret = PartitionManager.Run_Restore(Restore_Name); } else { operation_end(1); 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_print("Backup Canceled.\n"); ret = 0; } operation_end(ret); return ret; } return 0; }
int GUIAction::flash(std::string arg) { int i, ret_val = 0, wipe_cache = 0; // We're going to jump to this page first, like a loading page gui_changePage(arg); for (i=0; i<zip_queue_index; i++) { operation_start("Flashing"); DataManager::SetValue("tw_filename", zip_queue[i]); DataManager::SetValue(TW_ZIP_INDEX, (i + 1)); TWFunc::SetPerformanceMode(true); ret_val = flash_zip(zip_queue[i], &wipe_cache); TWFunc::SetPerformanceMode(false); if (ret_val != 0) { gui_print("Error flashing zip '%s'\n", zip_queue[i].c_str()); ret_val = 1; break; } } zip_queue_index = 0; if (wipe_cache) { gui_print("One or more zip requested a cache wipe\nWiping cache now.\n"); PartitionManager.Wipe_By_Path("/cache"); } reinject_after_flash(); PartitionManager.Update_System_Details(); operation_end(ret_val); DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); return 0; }
int GUIAction::sleep(std::string arg) { operation_start("Sleep"); usleep(atoi(arg.c_str())); operation_end(0); return 0; }
int GUIAction::mountsystemtoggle(std::string arg) { int op_status = 0; bool remount_system = PartitionManager.Is_Mounted_By_Path("/system"); operation_start("Toggle System Mount"); if (!PartitionManager.UnMount_By_Path("/system", true)) { op_status = 1; // fail } else { TWPartition* Part = PartitionManager.Find_Partition_By_Path("/system"); if (Part) { if (arg == "0") { DataManager::SetValue("tw_mount_system_ro", 0); Part->Change_Mount_Read_Only(false); } else { DataManager::SetValue("tw_mount_system_ro", 1); Part->Change_Mount_Read_Only(true); } if (remount_system) { Part->Mount(true); } op_status = 0; // success } else { op_status = 1; // fail } } operation_end(op_status); return 0; }
int GUIAction::generatebackupname(std::string arg) { operation_start("GenerateBackupName"); TWFunc::Auto_Generate_Backup_Name(); operation_end(0); return 0; }
int GUIAction::decrypt(std::string arg) { int op_status = 0; operation_start("Decrypt"); if (simulate) { simulate_progress_bar(); } else { string Password; DataManager::GetValue("tw_crypto_password", Password); op_status = PartitionManager.Decrypt_Device(Password); if (op_status != 0) op_status = 1; else { DataManager::SetValue(TW_IS_ENCRYPTED, 0); int has_datamedia; // Check for a custom theme and load it if exists DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia); if (has_datamedia != 0) { if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) { LOGINFO("Failed to get default contexts and file mode for storage files.\n"); } else { LOGINFO("Got default contexts and file mode for storage files.\n"); } } } } operation_end(op_status); return 0; }
int GUIAction::refreshsizes(std::string arg) { operation_start("Refreshing Sizes"); if (simulate) { simulate_progress_bar(); } else PartitionManager.Update_System_Details(); operation_end(0); return 0; }
int GUIAction::htcdumlockreflashrecovery(std::string arg) { operation_start("HTC Dumlock Reflash Recovery"); if (simulate) { simulate_progress_bar(); } else TWFunc::htc_dumlock_reflash_recovery_to_boot(); operation_end(0); return 0; }
int GUIAction::htcdumlockrestoreboot(std::string arg) { operation_start("HTC Dumlock Restore Boot"); if (simulate) { simulate_progress_bar(); } else TWFunc::htc_dumlock_restore_original_boot(); operation_end(0); return 0; }
int GUIAction::installhtcdumlock(std::string arg) { operation_start("Install HTC Dumlock"); if (simulate) { simulate_progress_bar(); } else TWFunc::install_htc_dumlock(); operation_end(0); return 0; }
int GUIAction::openrecoveryscript(std::string arg) { int op_status = 1; operation_start("OpenRecoveryScript"); if (simulate) { simulate_progress_bar(); operation_end(0); } else { // Check for the SCRIPT_FILE_TMP first as these are AOSP recovery commands // that we converted to ORS commands during boot in recovery.cpp. // Run those first. int reboot = 0; if (TWFunc::Path_Exists(SCRIPT_FILE_TMP)) { gui_print("Processing AOSP recovery commands...\n"); if (OpenRecoveryScript::run_script_file() == 0) { reboot = 1; op_status = 0; } } // Check for the ORS file in /cache and attempt to run those commands. if (OpenRecoveryScript::check_for_script_file()) { gui_print("Processing OpenRecoveryScript file...\n"); if (OpenRecoveryScript::run_script_file() == 0) { reboot = 1; op_status = 0; } } if (reboot) { // Disable stock recovery reflashing TWFunc::Disable_Stock_Recovery_Replace(); usleep(2000000); // Sleep for 2 seconds before rebooting TWFunc::tw_reboot(rb_system); usleep(5000000); // Sleep for 5 seconds to allow reboot to occur } else { DataManager::SetValue("tw_page_done", 1); } operation_end(op_status); } return 0; }
int GUIAction::appenddatetobackupname(std::string arg) { operation_start("AppendDateToBackupName"); string Backup_Name; DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); Backup_Name += TWFunc::Get_Current_Date(); if (Backup_Name.size() > MAX_BACKUP_NAME_LEN) Backup_Name.resize(MAX_BACKUP_NAME_LEN); DataManager::SetValue(TW_BACKUP_NAME, Backup_Name); operation_end(0); return 0; }
int GUIAction::restoredefaultsettings(std::string arg) { operation_start("Restore Defaults"); if (simulate) // Simulated so that people don't accidently wipe out the "simulation is on" setting gui_print("Simulating actions...\n"); else { DataManager::ResetDefaults(); PartitionManager.Update_System_Details(); PartitionManager.Mount_Current_Storage(true); } operation_end(0); return 0; }
int GUIAction::stopmtp(std::string arg) { int op_status = 0; operation_start("Stop MTP"); if (PartitionManager.Disable_MTP()) op_status = 0; // success else op_status = 1; // fail operation_end(op_status); return 0; }
int GUIAction::dd(std::string arg) { operation_start("imaging"); if (simulate) { simulate_progress_bar(); } else { string cmd = "dd " + arg; TWFunc::Exec_Cmd(cmd); } operation_end(0); return 0; }
int GUIAction::fixsu(std::string arg) { int op_status = 0; operation_start("Fixing Superuser Permissions"); if (simulate) { simulate_progress_bar(); } else { LOGERR("Fixing su permissions was deprecated from TWRP.\n"); LOGERR("4.3+ ROMs with SELinux will always lose su perms.\n"); } operation_end(op_status); return 0; }
int GUIAction::reinjecttwrp(std::string arg) { int op_status = 0; operation_start("ReinjectTWRP"); gui_print("Injecting TWRP into boot image...\n"); if (simulate) { simulate_progress_bar(); } else { TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); gui_print("TWRP injection complete.\n"); } operation_end(op_status); return 0; }
int GUIAction::installsu(std::string arg) { int op_status = 0; operation_start("Install SuperSU"); if (simulate) { simulate_progress_bar(); } else { if (!TWFunc::Install_SuperSU()) op_status = 1; } operation_end(op_status); return 0; }
int GUIAction::checkbackupname(std::string arg) { int op_status = 0; operation_start("CheckBackupName"); if (simulate) { simulate_progress_bar(); } else { op_status = PartitionManager.Check_Backup_Name(true); if (op_status != 0) op_status = 1; } operation_end(op_status); return 0; }
int GUIAction::fixpermissions(std::string arg) { int op_status = 0; operation_start("Fix Permissions"); LOGINFO("fix permissions started!\n"); if (simulate) { simulate_progress_bar(); } else { op_status = PartitionManager.Fix_Permissions(); if (op_status != 0) op_status = 1; // failure } operation_end(op_status); return 0; }
int GUIAction::cmd(std::string arg) { int op_status = 0; operation_start("Command"); LOGINFO("Running command: '%s'\n", arg.c_str()); if (simulate) { simulate_progress_bar(); } else { op_status = TWFunc::Exec_Cmd(arg); if (op_status != 0) op_status = 1; } operation_end(op_status); return 0; }
int GUIAction::copylog(std::string arg) { operation_start("Copy Log"); if (!simulate) { string dst; PartitionManager.Mount_Current_Storage(true); dst = DataManager::GetCurrentStoragePath() + "/recovery.log"; TWFunc::copy_file("/tmp/recovery.log", dst.c_str(), 0755); tw_set_default_metadata(dst.c_str()); sync(); gui_print("Copied recovery log to %s.\n", DataManager::GetCurrentStoragePath().c_str()); } else simulate_progress_bar(); operation_end(0); return 0; }
int GUIAction::flashimage(std::string arg) { int op_status = 0; operation_start("Flash Image"); string path, filename, full_filename; DataManager::GetValue("tw_zip_location", path); DataManager::GetValue("tw_file", filename); full_filename = path + "/" + filename; if (PartitionManager.Flash_Image(full_filename)) op_status = 0; // success else op_status = 1; // fail operation_end(op_status); return 0; }
int GUIAction::checkpartitionlifetimewrites(std::string arg) { int op_status = 0; TWPartition* sys = PartitionManager.Find_Partition_By_Path(arg); operation_start("Check Partition Lifetime Writes"); if (sys) { if (sys->Check_Lifetime_Writes() != 0) DataManager::SetValue("tw_lifetime_writes", 1); else DataManager::SetValue("tw_lifetime_writes", 0); op_status = 0; // success } else { DataManager::SetValue("tw_lifetime_writes", 1); op_status = 1; // fail } operation_end(op_status); return 0; }
int GUIAction::partitionsd(std::string arg) { operation_start("Partition SD Card"); int ret_val = 0; if (simulate) { simulate_progress_bar(); } else { int allow_partition; DataManager::GetValue(TW_ALLOW_PARTITION_SDCARD, allow_partition); if (allow_partition == 0) { gui_print("This device does not have a real SD Card!\nAborting!\n"); } else { if (!PartitionManager.Partition_SDCard()) ret_val = 1; // failed } } operation_end(ret_val); return 0; }
int GUIAction::resize(std::string arg) { int op_status = 0; operation_start("Resize Partition"); if (simulate) { simulate_progress_bar(); } else { string part_path; DataManager::GetValue("tw_partition_mount_point", part_path); if (PartitionManager.Resize_By_Path(part_path, true)) { op_status = 0; // success } else { LOGERR("Error resizing file system.\n"); op_status = 1; // fail } } operation_end(op_status); return 0; }
int GUIAction::changefilesystem(std::string arg) { int op_status = 0; operation_start("Change File System"); if (simulate) { simulate_progress_bar(); } else { string part_path, file_system; DataManager::GetValue("tw_partition_mount_point", part_path); DataManager::GetValue("tw_action_new_file_system", file_system); if (PartitionManager.Wipe_By_Path(part_path, file_system)) { op_status = 0; // success } else { LOGERR("Error changing file system.\n"); op_status = 1; // fail } } PartitionManager.Update_System_Details(); operation_end(op_status); return 0; }
int GUIAction::decrypt_backup(std::string arg) { int op_status = 0; operation_start("Try Restore Decrypt"); if (simulate) { simulate_progress_bar(); } else { string Restore_Path, Filename, Password; DataManager::GetValue("tw_restore", Restore_Path); Restore_Path += "/"; DataManager::GetValue("tw_restore_password", Password); TWFunc::SetPerformanceMode(true); if (TWFunc::Try_Decrypting_Backup(Restore_Path, Password)) op_status = 0; // success else op_status = 1; // fail TWFunc::SetPerformanceMode(false); } operation_end(op_status); return 0; }