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