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