Dees Troy | 3be70a8 | 2013-10-22 14:25:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | Copyright 2012 bigbiff/Dees_Troy TeamWin |
| 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 18 | |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <string.h> |
| 22 | #include <sys/stat.h> |
| 23 | #include <sys/vfs.h> |
| 24 | #include <unistd.h> |
| 25 | #include <vector> |
| 26 | #include <dirent.h> |
| 27 | #include <time.h> |
| 28 | #include <errno.h> |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 29 | #include <iostream> |
| 30 | #include <fstream> |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 31 | |
| 32 | #include "twrp-functions.hpp" |
| 33 | #include "partitions.hpp" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 34 | #include "twcommon.h" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 35 | #include "openrecoveryscript.hpp" |
| 36 | #include "variables.h" |
Dees_Troy | 4fc0024 | 2013-01-17 19:22:12 +0000 | [diff] [blame] | 37 | #include "adb_install.h" |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 38 | #include "data.hpp" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 39 | extern "C" { |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 40 | #include "twinstall.h" |
| 41 | #include "gui/gui.h" |
| 42 | int TWinstall_zip(const char* path, int* wipe_cache); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 43 | } |
| 44 | |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 45 | #define SCRIPT_COMMAND_SIZE 512 |
| 46 | |
| 47 | int OpenRecoveryScript::check_for_script_file(void) { |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 48 | if (!PartitionManager.Mount_By_Path(SCRIPT_FILE_CACHE, false)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 49 | LOGERR("Unable to mount /cache for OpenRecoveryScript support.\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 50 | return 0; |
| 51 | } |
| 52 | if (TWFunc::Path_Exists(SCRIPT_FILE_CACHE)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 53 | LOGINFO("Script file found: '%s'\n", SCRIPT_FILE_CACHE); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 54 | // Copy script file to /tmp |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 55 | TWFunc::copy_file(SCRIPT_FILE_CACHE, SCRIPT_FILE_TMP, 0755); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 56 | // Delete the file from /cache |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 57 | unlink(SCRIPT_FILE_CACHE); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 58 | return 1; |
| 59 | } |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | int OpenRecoveryScript::run_script_file(void) { |
| 64 | FILE *fp = fopen(SCRIPT_FILE_TMP, "r"); |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 65 | int ret_val = 0, cindex, line_len, i, remove_nl, install_cmd = 0, sideload = 0; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 66 | char script_line[SCRIPT_COMMAND_SIZE], command[SCRIPT_COMMAND_SIZE], |
| 67 | value[SCRIPT_COMMAND_SIZE], mount[SCRIPT_COMMAND_SIZE], |
| 68 | value1[SCRIPT_COMMAND_SIZE], value2[SCRIPT_COMMAND_SIZE]; |
| 69 | char *val_start, *tok; |
| 70 | |
| 71 | if (fp != NULL) { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 72 | DataManager::SetValue(TW_SIMULATE_ACTIONS, 0); |
Dees_Troy | 6bdcbb1 | 2013-01-26 14:07:43 +0000 | [diff] [blame] | 73 | DataManager::SetValue("ui_progress", 0); // Reset the progress bar |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 74 | while (fgets(script_line, SCRIPT_COMMAND_SIZE, fp) != NULL && ret_val == 0) { |
| 75 | cindex = 0; |
| 76 | line_len = strlen(script_line); |
| 77 | if (line_len < 2) |
| 78 | continue; // there's a blank line or line is too short to contain a command |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 79 | //gui_print("script line: '%s'\n", script_line); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 80 | for (i=0; i<line_len; i++) { |
| 81 | if ((int)script_line[i] == 32) { |
| 82 | cindex = i; |
| 83 | i = line_len; |
| 84 | } |
| 85 | } |
| 86 | memset(command, 0, sizeof(command)); |
| 87 | memset(value, 0, sizeof(value)); |
| 88 | if ((int)script_line[line_len - 1] == 10) |
| 89 | remove_nl = 2; |
| 90 | else |
| 91 | remove_nl = 1; |
| 92 | if (cindex != 0) { |
| 93 | strncpy(command, script_line, cindex); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 94 | LOGINFO("command is: '%s' and ", command); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 95 | val_start = script_line; |
| 96 | val_start += cindex + 1; |
bigbiff bigbiff | c03121d | 2013-09-09 19:14:35 -0400 | [diff] [blame] | 97 | if ((int) *val_start == 32) |
| 98 | val_start++; //get rid of space |
bigbiff bigbiff | 72e9554 | 2013-08-29 21:01:02 -0400 | [diff] [blame] | 99 | if ((int) *val_start == 51) |
| 100 | val_start++; //get rid of = at the beginning |
bigbiff bigbiff | a6c5f4e | 2013-09-17 20:01:14 -0400 | [diff] [blame] | 101 | if ((int) *val_start == 32) |
| 102 | val_start++; //get rid of space |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 103 | strncpy(value, val_start, line_len - cindex - remove_nl); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 104 | LOGINFO("value is: '%s'\n", value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 105 | } else { |
| 106 | strncpy(command, script_line, line_len - remove_nl + 1); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 107 | gui_print("command is: '%s' and there is no value\n", command); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 108 | } |
| 109 | if (strcmp(command, "install") == 0) { |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 110 | // Install Zip |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 111 | DataManager::SetValue("tw_action_text2", "Installing Zip"); |
Dees_Troy | dc8bc1b | 2013-01-17 01:39:28 +0000 | [diff] [blame] | 112 | PartitionManager.Mount_All_Storage(); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 113 | ret_val = Install_Command(value); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 114 | install_cmd = -1; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 115 | } else if (strcmp(command, "wipe") == 0) { |
| 116 | // Wipe |
| 117 | if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 118 | gui_print("-- Wiping Cache Partition...\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 119 | PartitionManager.Wipe_By_Path("/cache"); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 120 | gui_print("-- Cache Partition Wipe Complete!\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 121 | } else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 122 | gui_print("-- Wiping Dalvik Cache...\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 123 | PartitionManager.Wipe_Dalvik_Cache(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 124 | gui_print("-- Dalvik Cache Wipe Complete!\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 125 | } else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 126 | gui_print("-- Wiping Data Partition...\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 127 | PartitionManager.Factory_Reset(); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 128 | gui_print("-- Data Partition Wipe Complete!\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 129 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 130 | LOGERR("Error with wipe command value: '%s'\n", value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 131 | ret_val = 1; |
| 132 | } |
| 133 | } else if (strcmp(command, "backup") == 0) { |
| 134 | // Backup |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 135 | DataManager::SetValue("tw_action_text2", "Backing Up"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 136 | tok = strtok(value, " "); |
| 137 | strcpy(value1, tok); |
| 138 | tok = strtok(NULL, " "); |
| 139 | if (tok != NULL) { |
| 140 | memset(value2, 0, sizeof(value2)); |
| 141 | strcpy(value2, tok); |
| 142 | line_len = strlen(tok); |
| 143 | if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) { |
| 144 | if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) |
| 145 | remove_nl = 2; |
| 146 | else |
| 147 | remove_nl = 1; |
| 148 | } else |
| 149 | remove_nl = 0; |
| 150 | strncpy(value2, tok, line_len - remove_nl); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 151 | DataManager::SetValue(TW_BACKUP_NAME, value2); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 152 | gui_print("Backup folder set to '%s'\n", value2); |
Dees_Troy | c9ff7a3 | 2012-09-27 10:09:41 -0400 | [diff] [blame] | 153 | if (PartitionManager.Check_Backup_Name(true) != 0) { |
| 154 | ret_val = 1; |
| 155 | continue; |
| 156 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 157 | } else { |
| 158 | char empt[50]; |
| 159 | strcpy(empt, "(Current Date)"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 160 | DataManager::SetValue(TW_BACKUP_NAME, empt); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 161 | } |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 162 | ret_val = Backup_Command(value1); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 163 | } else if (strcmp(command, "restore") == 0) { |
| 164 | // Restore |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 165 | DataManager::SetValue("tw_action_text2", "Restoring"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 166 | PartitionManager.Mount_All_Storage(); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 167 | DataManager::SetValue(TW_SKIP_MD5_CHECK_VAR, 0); |
Dees_Troy | dc8bc1b | 2013-01-17 01:39:28 +0000 | [diff] [blame] | 168 | char folder_path[512], partitions[512]; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 169 | |
| 170 | string val = value, restore_folder, restore_partitions; |
| 171 | size_t pos = val.find_last_of(" "); |
| 172 | if (pos == string::npos) { |
Dees_Troy | dc8bc1b | 2013-01-17 01:39:28 +0000 | [diff] [blame] | 173 | restore_folder = value; |
| 174 | partitions[0] = '\0'; |
| 175 | } else { |
| 176 | restore_folder = val.substr(0, pos); |
| 177 | restore_partitions = val.substr(pos + 1, val.size() - pos - 1); |
| 178 | strcpy(partitions, restore_partitions.c_str()); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 179 | } |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 180 | strcpy(folder_path, restore_folder.c_str()); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 181 | LOGINFO("Restore folder is: '%s' and partitions: '%s'\n", folder_path, partitions); |
| 182 | gui_print("Restoring '%s'\n", folder_path); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 183 | |
| 184 | if (folder_path[0] != '/') { |
| 185 | char backup_folder[512]; |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 186 | string folder_var; |
| 187 | DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, folder_var); |
| 188 | sprintf(backup_folder, "%s/%s", folder_var.c_str(), folder_path); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 189 | LOGINFO("Restoring relative path: '%s'\n", backup_folder); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 190 | if (!TWFunc::Path_Exists(backup_folder)) { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 191 | if (DataManager::GetIntValue(TW_HAS_DUAL_STORAGE)) { |
| 192 | if (DataManager::GetIntValue(TW_USE_EXTERNAL_STORAGE)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 193 | LOGINFO("Backup folder '%s' not found on external storage, trying internal...\n", folder_path); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 194 | DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 0); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 195 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 196 | LOGINFO("Backup folder '%s' not found on internal storage, trying external...\n", folder_path); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 197 | DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 1); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 198 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 199 | DataManager::GetValue(TW_BACKUPS_FOLDER_VAR, folder_var); |
| 200 | sprintf(backup_folder, "%s/%s", folder_var.c_str(), folder_path); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 201 | LOGINFO("2Restoring relative path: '%s'\n", backup_folder); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | strcpy(folder_path, backup_folder); |
| 205 | } else { |
| 206 | if (folder_path[strlen(folder_path) - 1] == '/') |
| 207 | strcat(folder_path, "."); |
| 208 | else |
| 209 | strcat(folder_path, "/."); |
| 210 | } |
| 211 | if (!TWFunc::Path_Exists(folder_path)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 212 | gui_print("Unable to locate backup '%s'\n", folder_path); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 213 | ret_val = 1; |
| 214 | continue; |
| 215 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 216 | DataManager::SetValue("tw_restore", folder_path); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 217 | |
| 218 | PartitionManager.Set_Restore_Files(folder_path); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 219 | string Partition_List; |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 220 | int is_encrypted = 0; |
| 221 | DataManager::GetValue("tw_restore_encrypted", is_encrypted); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 222 | DataManager::GetValue("tw_restore_list", Partition_List); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 223 | if (strlen(partitions) != 0) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 224 | string Restore_List; |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 225 | |
| 226 | memset(value2, 0, sizeof(value2)); |
| 227 | strcpy(value2, partitions); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 228 | gui_print("Setting restore options: '%s':\n", value2); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 229 | line_len = strlen(value2); |
| 230 | for (i=0; i<line_len; i++) { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 231 | if ((value2[i] == 'S' || value2[i] == 's') && Partition_List.find("/system;") != string::npos) { |
| 232 | Restore_List += "/system;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 233 | gui_print("System\n"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 234 | } else if ((value2[i] == 'D' || value2[i] == 'd') && Partition_List.find("/data;") != string::npos) { |
| 235 | Restore_List += "/data;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 236 | gui_print("Data\n"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 237 | } else if ((value2[i] == 'C' || value2[i] == 'c') && Partition_List.find("/cache;") != string::npos) { |
| 238 | Restore_List += "/cache;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 239 | gui_print("Cache\n"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 240 | } else if ((value2[i] == 'R' || value2[i] == 'r') && Partition_List.find("/recovery;") != string::npos) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 241 | gui_print("Recovery -- Not allowed to restore recovery\n"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 242 | } else if (value2[i] == '1' && DataManager::GetIntValue(TW_RESTORE_SP1_VAR) > 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 243 | gui_print("%s\n", "Special1 -- No Longer Supported..."); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 244 | } else if (value2[i] == '2' && DataManager::GetIntValue(TW_RESTORE_SP2_VAR) > 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 245 | gui_print("%s\n", "Special2 -- No Longer Supported..."); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 246 | } else if (value2[i] == '3' && DataManager::GetIntValue(TW_RESTORE_SP3_VAR) > 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 247 | gui_print("%s\n", "Special3 -- No Longer Supported..."); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 248 | } else if ((value2[i] == 'B' || value2[i] == 'b') && Partition_List.find("/boot;") != string::npos) { |
| 249 | Restore_List += "/boot;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 250 | gui_print("Boot\n"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 251 | } else if ((value2[i] == 'A' || value2[i] == 'a') && Partition_List.find("/and-sec;") != string::npos) { |
| 252 | Restore_List += "/and-sec;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 253 | gui_print("Android Secure\n"); |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 254 | } else if ((value2[i] == 'E' || value2[i] == 'e') && Partition_List.find("/sd-ext;") != string::npos) { |
| 255 | Restore_List += "/sd-ext;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 256 | gui_print("SD-Ext\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 257 | } else if (value2[i] == 'M' || value2[i] == 'm') { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 258 | DataManager::SetValue(TW_SKIP_MD5_CHECK_VAR, 1); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 259 | gui_print("MD5 check skip is on\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 260 | } |
| 261 | } |
| 262 | |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 263 | DataManager::SetValue("tw_restore_selected", Restore_List); |
| 264 | } else { |
| 265 | DataManager::SetValue("tw_restore_selected", Partition_List); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 266 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 267 | if (is_encrypted) { |
| 268 | LOGERR("Unable to use OpenRecoveryScript to restore an encrypted backup.\n"); |
| 269 | ret_val = 1; |
| 270 | } else if (!PartitionManager.Run_Restore(folder_path)) |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 271 | ret_val = 1; |
| 272 | else |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 273 | gui_print("Restore complete!\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 274 | } else if (strcmp(command, "mount") == 0) { |
| 275 | // Mount |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 276 | DataManager::SetValue("tw_action_text2", "Mounting"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 277 | if (value[0] != '/') { |
| 278 | strcpy(mount, "/"); |
| 279 | strcat(mount, value); |
| 280 | } else |
| 281 | strcpy(mount, value); |
| 282 | if (PartitionManager.Mount_By_Path(mount, true)) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 283 | gui_print("Mounted '%s'\n", mount); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 284 | } else if (strcmp(command, "unmount") == 0 || strcmp(command, "umount") == 0) { |
| 285 | // Unmount |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 286 | DataManager::SetValue("tw_action_text2", "Unmounting"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 287 | if (value[0] != '/') { |
| 288 | strcpy(mount, "/"); |
| 289 | strcat(mount, value); |
| 290 | } else |
| 291 | strcpy(mount, value); |
| 292 | if (PartitionManager.UnMount_By_Path(mount, true)) |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 293 | gui_print("Unmounted '%s'\n", mount); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 294 | } else if (strcmp(command, "set") == 0) { |
| 295 | // Set value |
| 296 | tok = strtok(value, " "); |
| 297 | strcpy(value1, tok); |
| 298 | tok = strtok(NULL, " "); |
| 299 | strcpy(value2, tok); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 300 | gui_print("Setting '%s' to '%s'\n", value1, value2); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 301 | DataManager::SetValue(value1, value2); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 302 | } else if (strcmp(command, "mkdir") == 0) { |
| 303 | // Make directory (recursive) |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 304 | DataManager::SetValue("tw_action_text2", "Making Directory"); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 305 | gui_print("Making directory (recursive): '%s'\n", value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 306 | if (TWFunc::Recursive_Mkdir(value)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 307 | LOGERR("Unable to create folder: '%s'\n", value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 308 | ret_val = 1; |
| 309 | } |
| 310 | } else if (strcmp(command, "reboot") == 0) { |
| 311 | // Reboot |
| 312 | } else if (strcmp(command, "cmd") == 0) { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 313 | DataManager::SetValue("tw_action_text2", "Running Command"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 314 | if (cindex != 0) { |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 315 | TWFunc::Exec_Cmd(value); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 316 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 317 | LOGERR("No value given for cmd\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 318 | } |
| 319 | } else if (strcmp(command, "print") == 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 320 | gui_print("%s\n", value); |
Dees_Troy | 4fc0024 | 2013-01-17 19:22:12 +0000 | [diff] [blame] | 321 | } else if (strcmp(command, "sideload") == 0) { |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 322 | // ADB Sideload |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 323 | DataManager::SetValue("tw_action_text2", "ADB Sideload"); |
| 324 | install_cmd = -1; |
| 325 | |
| 326 | int wipe_cache = 0; |
| 327 | string result, Sideload_File; |
| 328 | |
| 329 | if (!PartitionManager.Mount_Current_Storage(true)) { |
| 330 | ret_val = 1; // failure |
| 331 | } else { |
| 332 | Sideload_File = DataManager::GetCurrentStoragePath() + "/sideload.zip"; |
| 333 | if (TWFunc::Path_Exists(Sideload_File)) { |
| 334 | unlink(Sideload_File.c_str()); |
| 335 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 336 | gui_print("Starting ADB sideload feature...\n"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 337 | DataManager::SetValue("tw_has_cancel", 1); |
| 338 | DataManager::SetValue("tw_cancel_action", "adbsideloadcancel"); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 339 | ret_val = apply_from_adb(Sideload_File.c_str()); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 340 | DataManager::SetValue("tw_has_cancel", 0); |
| 341 | if (ret_val != 0) |
| 342 | ret_val = 1; // failure |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 343 | else if (TWinstall_zip(Sideload_File.c_str(), &wipe_cache) == 0) { |
| 344 | if (wipe_cache) |
| 345 | PartitionManager.Wipe_By_Path("/cache"); |
| 346 | } else { |
| 347 | ret_val = 1; // failure |
| 348 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 349 | sideload = 1; // Causes device to go to the home screen afterwards |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 350 | gui_print("Sideload finished.\n"); |
Dees_Troy | 4fc0024 | 2013-01-17 19:22:12 +0000 | [diff] [blame] | 351 | } |
Ethan Yonker | aae6e8c | 2014-02-11 21:37:36 -0600 | [diff] [blame] | 352 | } else if (strcmp(command, "fixperms") == 0 || strcmp(command, "fixpermissions") == 0) { |
| 353 | ret_val = PartitionManager.Fix_Permissions(); |
| 354 | if (ret_val != 0) |
| 355 | ret_val = 1; // failure |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 356 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 357 | LOGERR("Unrecognized script command: '%s'\n", command); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 358 | ret_val = 1; |
| 359 | } |
| 360 | } |
| 361 | fclose(fp); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 362 | gui_print("Done processing script file\n"); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 363 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 364 | LOGERR("Error opening script file '%s'\n", SCRIPT_FILE_TMP); |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 365 | return 1; |
| 366 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 367 | if (install_cmd && DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 368 | gui_print("Injecting TWRP into boot image...\n"); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 369 | TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); |
| 370 | if (Boot == NULL || Boot->Current_File_System != "emmc") |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 371 | TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 372 | else { |
| 373 | string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device; |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 374 | TWFunc::Exec_Cmd(injectcmd.c_str()); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 375 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 376 | gui_print("TWRP injection complete.\n"); |
Dees_Troy | 06b4fe9 | 2012-10-16 11:43:20 -0400 | [diff] [blame] | 377 | } |
Dees_Troy | 4bc09ae | 2013-01-18 17:00:54 +0000 | [diff] [blame] | 378 | if (sideload) |
| 379 | ret_val = 1; // Forces booting to the home page after sideload |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 380 | return ret_val; |
| 381 | } |
| 382 | |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 383 | int OpenRecoveryScript::Insert_ORS_Command(string Command) { |
| 384 | ofstream ORSfile(SCRIPT_FILE_TMP); |
| 385 | if (ORSfile.is_open()) { |
| 386 | //if (Command.substr(Command.size() - 1, 1) != "\n") |
| 387 | // Command += "\n"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 388 | LOGINFO("Inserting '%s'\n", Command.c_str()); |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 389 | ORSfile << Command.c_str(); |
| 390 | ORSfile.close(); |
| 391 | return 1; |
| 392 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 393 | LOGERR("Unable to append '%s' to '%s'\n", Command.c_str(), SCRIPT_FILE_TMP); |
Dees_Troy | 01b6d0c | 2013-01-22 01:41:09 +0000 | [diff] [blame] | 394 | return 0; |
| 395 | } |
| 396 | |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 397 | int OpenRecoveryScript::Install_Command(string Zip) { |
| 398 | // Install zip |
| 399 | string ret_string; |
| 400 | int ret_val = 0, wipe_cache = 0; |
| 401 | |
| 402 | PartitionManager.Mount_All_Storage(); |
| 403 | if (Zip.substr(0, 1) != "/") { |
| 404 | // Relative path given |
| 405 | string Full_Path; |
| 406 | |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 407 | Full_Path = DataManager::GetCurrentStoragePath(); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 408 | Full_Path += "/" + Zip; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 409 | LOGINFO("Full zip path: '%s'\n", Full_Path.c_str()); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 410 | if (!TWFunc::Path_Exists(Full_Path)) { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 411 | ret_string = Locate_Zip_File(Full_Path, DataManager::GetCurrentStoragePath()); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 412 | if (!ret_string.empty()) { |
| 413 | Full_Path = ret_string; |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 414 | } else if (DataManager::GetIntValue(TW_HAS_DUAL_STORAGE)) { |
| 415 | if (DataManager::GetIntValue(TW_USE_EXTERNAL_STORAGE)) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 416 | LOGINFO("Zip file not found on external storage, trying internal...\n"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 417 | DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 0); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 418 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 419 | LOGINFO("Zip file not found on internal storage, trying external...\n"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 420 | DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 1); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 421 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 422 | Full_Path = DataManager::GetCurrentStoragePath(); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 423 | Full_Path += "/" + Zip; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 424 | LOGINFO("Full zip path: '%s'\n", Full_Path.c_str()); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 425 | ret_string = Locate_Zip_File(Full_Path, DataManager::GetCurrentStoragePath()); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 426 | if (!ret_string.empty()) |
| 427 | Full_Path = ret_string; |
| 428 | } |
| 429 | } |
| 430 | Zip = Full_Path; |
| 431 | } else { |
| 432 | // Full path given |
| 433 | if (!TWFunc::Path_Exists(Zip)) { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 434 | ret_string = Locate_Zip_File(Zip, DataManager::GetCurrentStoragePath()); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 435 | if (!ret_string.empty()) |
| 436 | Zip = ret_string; |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | if (!TWFunc::Path_Exists(Zip)) { |
| 441 | // zip file doesn't exist |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 442 | gui_print("Unable to locate zip file '%s'.\n", Zip.c_str()); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 443 | ret_val = 1; |
| 444 | } else { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 445 | gui_print("Installing zip file '%s'\n", Zip.c_str()); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 446 | ret_val = TWinstall_zip(Zip.c_str(), &wipe_cache); |
| 447 | } |
| 448 | if (ret_val != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 449 | LOGERR("Error installing zip file '%s'\n", Zip.c_str()); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 450 | ret_val = 1; |
| 451 | } else if (wipe_cache) |
| 452 | PartitionManager.Wipe_By_Path("/cache"); |
| 453 | |
| 454 | return ret_val; |
| 455 | } |
| 456 | |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 457 | string OpenRecoveryScript::Locate_Zip_File(string Zip, string Storage_Root) { |
| 458 | string Path = TWFunc::Get_Path(Zip); |
| 459 | string File = TWFunc::Get_Filename(Zip); |
| 460 | string pathCpy = Path; |
| 461 | string wholePath; |
| 462 | size_t pos = Path.find("/", 1); |
| 463 | |
| 464 | while (pos != string::npos) |
| 465 | { |
| 466 | pathCpy = Path.substr(pos, Path.size() - pos); |
| 467 | wholePath = pathCpy + "/" + File; |
| 468 | if (TWFunc::Path_Exists(wholePath)) |
| 469 | return wholePath; |
| 470 | wholePath = Storage_Root + "/" + wholePath; |
| 471 | if (TWFunc::Path_Exists(wholePath)) |
| 472 | return wholePath; |
| 473 | |
| 474 | pos = Path.find("/", pos + 1); |
| 475 | } |
| 476 | return ""; |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | int OpenRecoveryScript::Backup_Command(string Options) { |
| 480 | char value1[SCRIPT_COMMAND_SIZE]; |
| 481 | int line_len, i; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 482 | string Backup_List; |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 483 | |
| 484 | strcpy(value1, Options.c_str()); |
| 485 | |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 486 | DataManager::SetValue(TW_USE_COMPRESSION_VAR, 0); |
| 487 | DataManager::SetValue(TW_SKIP_MD5_GENERATE_VAR, 0); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 488 | |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 489 | gui_print("Setting backup options:\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 490 | line_len = Options.size(); |
| 491 | for (i=0; i<line_len; i++) { |
| 492 | if (Options.substr(i, 1) == "S" || Options.substr(i, 1) == "s") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 493 | Backup_List += "/system;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 494 | gui_print("System\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 495 | } else if (Options.substr(i, 1) == "D" || Options.substr(i, 1) == "d") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 496 | Backup_List += "/data;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 497 | gui_print("Data\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 498 | } else if (Options.substr(i, 1) == "C" || Options.substr(i, 1) == "c") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 499 | Backup_List += "/cache;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 500 | gui_print("Cache\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 501 | } else if (Options.substr(i, 1) == "R" || Options.substr(i, 1) == "r") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 502 | Backup_List += "/recovery;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 503 | gui_print("Recovery\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 504 | } else if (Options.substr(i, 1) == "1") { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 505 | gui_print("%s\n", "Special1 -- No Longer Supported..."); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 506 | } else if (Options.substr(i, 1) == "2") { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 507 | gui_print("%s\n", "Special2 -- No Longer Supported..."); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 508 | } else if (Options.substr(i, 1) == "3") { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 509 | gui_print("%s\n", "Special3 -- No Longer Supported..."); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 510 | } else if (Options.substr(i, 1) == "B" || Options.substr(i, 1) == "b") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 511 | Backup_List += "/boot;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 512 | gui_print("Boot\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 513 | } else if (Options.substr(i, 1) == "A" || Options.substr(i, 1) == "a") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 514 | Backup_List += "/and-sec;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 515 | gui_print("Android Secure\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 516 | } else if (Options.substr(i, 1) == "E" || Options.substr(i, 1) == "e") { |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 517 | Backup_List += "/sd-ext;"; |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 518 | gui_print("SD-Ext\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 519 | } else if (Options.substr(i, 1) == "O" || Options.substr(i, 1) == "o") { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 520 | DataManager::SetValue(TW_USE_COMPRESSION_VAR, 1); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 521 | gui_print("Compression is on\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 522 | } else if (Options.substr(i, 1) == "M" || Options.substr(i, 1) == "m") { |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 523 | DataManager::SetValue(TW_SKIP_MD5_GENERATE_VAR, 1); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 524 | gui_print("MD5 Generation is off\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 525 | } |
| 526 | } |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 527 | DataManager::SetValue("tw_backup_list", Backup_List); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 528 | if (!PartitionManager.Run_Backup()) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 529 | LOGERR("Backup failed!\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 530 | return 1; |
| 531 | } |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 532 | gui_print("Backup complete!\n"); |
Dees_Troy | 83a3b12 | 2012-10-01 14:16:43 -0400 | [diff] [blame] | 533 | return 0; |
| 534 | } |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 535 | |
| 536 | void OpenRecoveryScript::Run_OpenRecoveryScript(void) { |
| 537 | DataManager::SetValue("tw_back", "main"); |
| 538 | DataManager::SetValue("tw_action", "openrecoveryscript"); |
| 539 | DataManager::SetValue("tw_has_action2", "0"); |
| 540 | DataManager::SetValue("tw_action2", ""); |
| 541 | DataManager::SetValue("tw_action2_param", ""); |
| 542 | DataManager::SetValue("tw_action_text1", "Running OpenRecoveryScript"); |
| 543 | DataManager::SetValue("tw_action_text2", ""); |
| 544 | DataManager::SetValue("tw_complete_text1", "OpenRecoveryScript Complete"); |
| 545 | DataManager::SetValue("tw_has_cancel", 0); |
| 546 | DataManager::SetValue("tw_show_reboot", 0); |
| 547 | if (gui_startPage("action_page") != 0) { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 548 | LOGERR("Failed to load OpenRecoveryScript GUI page.\n"); |
Dees_Troy | 6ed34b7 | 2013-01-25 15:01:29 +0000 | [diff] [blame] | 549 | } |
Dees_Troy | 6bdcbb1 | 2013-01-26 14:07:43 +0000 | [diff] [blame] | 550 | } |