blob: 147214931a7ad811954c1def338b59ac6b2e48ee [file] [log] [blame]
Dees_Troy812660f2012-09-20 09:55:17 -04001/* OpenRecoveryScript class for TWRP
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 *
17 * The code was written from scratch by Dees_Troy dees_troy at
18 * yahoo
19 *
20 * Copyright (c) 2012
21 */
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26#include <sys/stat.h>
27#include <sys/vfs.h>
28#include <unistd.h>
29#include <vector>
30#include <dirent.h>
31#include <time.h>
32#include <errno.h>
33
34#include "twrp-functions.hpp"
35#include "partitions.hpp"
36#include "common.h"
37#include "openrecoveryscript.hpp"
38#include "variables.h"
39extern "C" {
40#include "data.h"
41#include "twinstall.h"
42int TWinstall_zip(const char* path, int* wipe_cache);
43}
44
45static const char *SCRIPT_FILE_CACHE = "/cache/recovery/openrecoveryscript";
46static const char *SCRIPT_FILE_TMP = "/tmp/openrecoveryscript";
47#define SCRIPT_COMMAND_SIZE 512
48
49int OpenRecoveryScript::check_for_script_file(void) {
Dees_Troy812660f2012-09-20 09:55:17 -040050 if (!PartitionManager.Mount_By_Path(SCRIPT_FILE_CACHE, false)) {
51 LOGE("Unable to mount /cache for OpenRecoveryScript support.\n");
52 return 0;
53 }
54 if (TWFunc::Path_Exists(SCRIPT_FILE_CACHE)) {
55 LOGI("Script file found: '%s'\n", SCRIPT_FILE_CACHE);
56 // Copy script file to /tmp
bigbiff bigbiff9c754052013-01-09 09:09:08 -050057 TWFunc::copy_file(SCRIPT_FILE_CACHE, SCRIPT_FILE_TMP, 0755);
Dees_Troy812660f2012-09-20 09:55:17 -040058 // Delete the file from /cache
bigbiff bigbiff9c754052013-01-09 09:09:08 -050059 unlink(SCRIPT_FILE_CACHE);
Dees_Troy812660f2012-09-20 09:55:17 -040060 return 1;
61 }
62 return 0;
63}
64
65int OpenRecoveryScript::run_script_file(void) {
66 FILE *fp = fopen(SCRIPT_FILE_TMP, "r");
Dees_Troy06b4fe92012-10-16 11:43:20 -040067 int ret_val = 0, cindex, line_len, i, remove_nl, install_cmd = 0;
Dees_Troy812660f2012-09-20 09:55:17 -040068 char script_line[SCRIPT_COMMAND_SIZE], command[SCRIPT_COMMAND_SIZE],
69 value[SCRIPT_COMMAND_SIZE], mount[SCRIPT_COMMAND_SIZE],
70 value1[SCRIPT_COMMAND_SIZE], value2[SCRIPT_COMMAND_SIZE];
71 char *val_start, *tok;
72
73 if (fp != NULL) {
Dees_Troy3ac71a52012-10-01 19:46:11 -040074 DataManager_SetIntValue(TW_SIMULATE_ACTIONS, 0);
Dees_Troy812660f2012-09-20 09:55:17 -040075 while (fgets(script_line, SCRIPT_COMMAND_SIZE, fp) != NULL && ret_val == 0) {
76 cindex = 0;
77 line_len = strlen(script_line);
78 if (line_len < 2)
79 continue; // there's a blank line or line is too short to contain a command
80 //ui_print("script line: '%s'\n", script_line);
81 for (i=0; i<line_len; i++) {
82 if ((int)script_line[i] == 32) {
83 cindex = i;
84 i = line_len;
85 }
86 }
87 memset(command, 0, sizeof(command));
88 memset(value, 0, sizeof(value));
89 if ((int)script_line[line_len - 1] == 10)
90 remove_nl = 2;
91 else
92 remove_nl = 1;
93 if (cindex != 0) {
94 strncpy(command, script_line, cindex);
95 LOGI("command is: '%s' and ", command);
96 val_start = script_line;
97 val_start += cindex + 1;
98 strncpy(value, val_start, line_len - cindex - remove_nl);
99 LOGI("value is: '%s'\n", value);
100 } else {
101 strncpy(command, script_line, line_len - remove_nl + 1);
102 ui_print("command is: '%s' and there is no value\n", command);
103 }
104 if (strcmp(command, "install") == 0) {
Dees_Troy83a3b122012-10-01 14:16:43 -0400105 // Install Zip
106 ret_val = Install_Command(value);
Dees_Troy06b4fe92012-10-16 11:43:20 -0400107 install_cmd = -1;
Dees_Troy812660f2012-09-20 09:55:17 -0400108 } else if (strcmp(command, "wipe") == 0) {
109 // Wipe
110 if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) {
111 ui_print("-- Wiping Cache Partition...\n");
112 PartitionManager.Wipe_By_Path("/cache");
113 ui_print("-- Cache Partition Wipe Complete!\n");
114 } else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) {
115 ui_print("-- Wiping Dalvik Cache...\n");
116 PartitionManager.Wipe_Dalvik_Cache();
117 ui_print("-- Dalvik Cache Wipe Complete!\n");
118 } else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) {
119 ui_print("-- Wiping Data Partition...\n");
120 PartitionManager.Factory_Reset();
121 ui_print("-- Data Partition Wipe Complete!\n");
122 } else {
123 LOGE("Error with wipe command value: '%s'\n", value);
124 ret_val = 1;
125 }
126 } else if (strcmp(command, "backup") == 0) {
127 // Backup
128 tok = strtok(value, " ");
129 strcpy(value1, tok);
130 tok = strtok(NULL, " ");
131 if (tok != NULL) {
132 memset(value2, 0, sizeof(value2));
133 strcpy(value2, tok);
134 line_len = strlen(tok);
135 if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) {
136 if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13)
137 remove_nl = 2;
138 else
139 remove_nl = 1;
140 } else
141 remove_nl = 0;
142 strncpy(value2, tok, line_len - remove_nl);
143 DataManager_SetStrValue(TW_BACKUP_NAME, value2);
144 ui_print("Backup folder set to '%s'\n", value2);
Dees_Troyc9ff7a32012-09-27 10:09:41 -0400145 if (PartitionManager.Check_Backup_Name(true) != 0) {
146 ret_val = 1;
147 continue;
148 }
Dees_Troy812660f2012-09-20 09:55:17 -0400149 } else {
150 char empt[50];
151 strcpy(empt, "(Current Date)");
152 DataManager_SetStrValue(TW_BACKUP_NAME, empt);
153 }
Dees_Troy83a3b122012-10-01 14:16:43 -0400154 ret_val = Backup_Command(value1);
Dees_Troy812660f2012-09-20 09:55:17 -0400155 } else if (strcmp(command, "restore") == 0) {
156 // Restore
157 PartitionManager.Mount_All_Storage();
158 DataManager_SetIntValue(TW_SKIP_MD5_CHECK_VAR, 0);
159
160 string val = value, restore_folder, restore_partitions;
161 size_t pos = val.find_last_of(" ");
162 if (pos == string::npos) {
163 ui_print("Malformed restore parameter: '%s'\n", value1);
164 ret_val = 1;
165 continue;
166 }
167 restore_folder = val.substr(0, pos);
168 char folder_path[512], partitions[512];
169 strcpy(folder_path, restore_folder.c_str());
170 restore_partitions = val.substr(pos + 1, val.size() - pos - 1);
171 strcpy(partitions, restore_partitions.c_str());
172 LOGI("Restore folder is: '%s' and partitions: '%s'\n", folder_path, partitions);
173 ui_print("Restoring '%s'\n", folder_path);
174
175 if (folder_path[0] != '/') {
176 char backup_folder[512];
177 sprintf(backup_folder, "%s/%s", DataManager_GetStrValue(TW_BACKUPS_FOLDER_VAR), folder_path);
178 LOGI("Restoring relative path: '%s'\n", backup_folder);
179 if (!TWFunc::Path_Exists(backup_folder)) {
180 if (DataManager_GetIntValue(TW_HAS_DUAL_STORAGE)) {
181 if (DataManager_GetIntValue(TW_USE_EXTERNAL_STORAGE)) {
182 LOGI("Backup folder '%s' not found on external storage, trying internal...\n", folder_path);
183 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 0);
184 } else {
185 LOGI("Backup folder '%s' not found on internal storage, trying external...\n", folder_path);
186 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 1);
187 }
188 sprintf(backup_folder, "%s/%s", DataManager_GetStrValue(TW_BACKUPS_FOLDER_VAR), folder_path);
189 LOGI("2Restoring relative path: '%s'\n", backup_folder);
190 }
191 }
192 strcpy(folder_path, backup_folder);
193 } else {
194 if (folder_path[strlen(folder_path) - 1] == '/')
195 strcat(folder_path, ".");
196 else
197 strcat(folder_path, "/.");
198 }
199 if (!TWFunc::Path_Exists(folder_path)) {
200 ui_print("Unable to locate backup '%s'\n", folder_path);
201 ret_val = 1;
202 continue;
203 }
204 DataManager_SetStrValue("tw_restore", folder_path);
205
206 PartitionManager.Set_Restore_Files(folder_path);
207 if (strlen(partitions) != 0) {
208 int tw_restore_system = 0;
209 int tw_restore_data = 0;
210 int tw_restore_cache = 0;
211 int tw_restore_recovery = 0;
212 int tw_restore_boot = 0;
213 int tw_restore_andsec = 0;
214 int tw_restore_sdext = 0;
215 int tw_restore_sp1 = 0;
216 int tw_restore_sp2 = 0;
217 int tw_restore_sp3 = 0;
218
219 memset(value2, 0, sizeof(value2));
220 strcpy(value2, partitions);
221 ui_print("Setting restore options: '%s':\n", value2);
222 line_len = strlen(value2);
223 for (i=0; i<line_len; i++) {
224 if ((value2[i] == 'S' || value2[i] == 's') && DataManager_GetIntValue(TW_RESTORE_SYSTEM_VAR) > 0) {
225 tw_restore_system = 1;
226 ui_print("System\n");
227 } else if ((value2[i] == 'D' || value2[i] == 'd') && DataManager_GetIntValue(TW_RESTORE_DATA_VAR) > 0) {
228 tw_restore_data = 1;
229 ui_print("Data\n");
230 } else if ((value2[i] == 'C' || value2[i] == 'c') && DataManager_GetIntValue(TW_RESTORE_CACHE_VAR) > 0) {
231 tw_restore_cache = 1;
232 ui_print("Cache\n");
233 } else if ((value2[i] == 'R' || value2[i] == 'r') && DataManager_GetIntValue(TW_RESTORE_RECOVERY_VAR) > 0) {
234 tw_restore_recovery = 1;
235 ui_print("Recovery\n");
236 } else if (value2[i] == '1' && DataManager_GetIntValue(TW_RESTORE_SP1_VAR) > 0) {
237 tw_restore_sp1 = 1;
238 ui_print("%s\n", "Special1");
239 } else if (value2[i] == '2' && DataManager_GetIntValue(TW_RESTORE_SP2_VAR) > 0) {
240 tw_restore_sp2 = 1;
241 ui_print("%s\n", "Special2");
242 } else if (value2[i] == '3' && DataManager_GetIntValue(TW_RESTORE_SP3_VAR) > 0) {
243 tw_restore_sp3 = 1;
244 ui_print("%s\n", "Special3");
245 } else if ((value2[i] == 'B' || value2[i] == 'b') && DataManager_GetIntValue(TW_RESTORE_BOOT_VAR) > 0) {
246 tw_restore_boot = 1;
247 ui_print("Boot\n");
248 } else if ((value2[i] == 'A' || value2[i] == 'a') && DataManager_GetIntValue(TW_RESTORE_ANDSEC_VAR) > 0) {
249 tw_restore_andsec = 1;
250 ui_print("Android Secure\n");
251 } else if ((value2[i] == 'E' || value2[i] == 'e') && DataManager_GetIntValue(TW_RESTORE_SDEXT_VAR) > 0) {
252 tw_restore_sdext = 1;
253 ui_print("SD-Ext\n");
254 } else if (value2[i] == 'M' || value2[i] == 'm') {
255 DataManager_SetIntValue(TW_SKIP_MD5_CHECK_VAR, 1);
256 ui_print("MD5 check skip is on\n");
257 }
258 }
259
260 if (DataManager_GetIntValue(TW_RESTORE_SYSTEM_VAR) && !tw_restore_system)
261 DataManager_SetIntValue(TW_RESTORE_SYSTEM_VAR, 0);
262 if (DataManager_GetIntValue(TW_RESTORE_DATA_VAR) && !tw_restore_data)
263 DataManager_SetIntValue(TW_RESTORE_DATA_VAR, 0);
264 if (DataManager_GetIntValue(TW_RESTORE_CACHE_VAR) && !tw_restore_cache)
265 DataManager_SetIntValue(TW_RESTORE_CACHE_VAR, 0);
266 if (DataManager_GetIntValue(TW_RESTORE_RECOVERY_VAR) && !tw_restore_recovery)
267 DataManager_SetIntValue(TW_RESTORE_RECOVERY_VAR, 0);
268 if (DataManager_GetIntValue(TW_RESTORE_BOOT_VAR) && !tw_restore_boot)
269 DataManager_SetIntValue(TW_RESTORE_BOOT_VAR, 0);
270 if (DataManager_GetIntValue(TW_RESTORE_ANDSEC_VAR) && !tw_restore_andsec)
271 DataManager_SetIntValue(TW_RESTORE_ANDSEC_VAR, 0);
272 if (DataManager_GetIntValue(TW_RESTORE_SDEXT_VAR) && !tw_restore_sdext)
273 DataManager_SetIntValue(TW_RESTORE_SDEXT_VAR, 0);
274 if (DataManager_GetIntValue(TW_RESTORE_SP1_VAR) && !tw_restore_sp1)
275 DataManager_SetIntValue(TW_RESTORE_SP1_VAR, 0);
276 if (DataManager_GetIntValue(TW_RESTORE_SP2_VAR) && !tw_restore_sp2)
277 DataManager_SetIntValue(TW_RESTORE_SP2_VAR, 0);
278 if (DataManager_GetIntValue(TW_RESTORE_SP3_VAR) && !tw_restore_sp3)
279 DataManager_SetIntValue(TW_RESTORE_SP3_VAR, 0);
280 } else {
281 ui_print("No restore options set.\n");
282 ret_val = 1;
283 continue;
284 }
285 PartitionManager.Run_Restore(folder_path);
286 ui_print("Restore complete!\n");
287 } else if (strcmp(command, "mount") == 0) {
288 // Mount
289 if (value[0] != '/') {
290 strcpy(mount, "/");
291 strcat(mount, value);
292 } else
293 strcpy(mount, value);
294 if (PartitionManager.Mount_By_Path(mount, true))
295 ui_print("Mounted '%s'\n", mount);
296 } else if (strcmp(command, "unmount") == 0 || strcmp(command, "umount") == 0) {
297 // Unmount
298 if (value[0] != '/') {
299 strcpy(mount, "/");
300 strcat(mount, value);
301 } else
302 strcpy(mount, value);
303 if (PartitionManager.UnMount_By_Path(mount, true))
304 ui_print("Unmounted '%s'\n", mount);
305 } else if (strcmp(command, "set") == 0) {
306 // Set value
307 tok = strtok(value, " ");
308 strcpy(value1, tok);
309 tok = strtok(NULL, " ");
310 strcpy(value2, tok);
311 ui_print("Setting '%s' to '%s'\n", value1, value2);
312 DataManager_SetStrValue(value1, value2);
313 } else if (strcmp(command, "mkdir") == 0) {
314 // Make directory (recursive)
315 ui_print("Making directory (recursive): '%s'\n", value);
316 if (TWFunc::Recursive_Mkdir(value)) {
317 LOGE("Unable to create folder: '%s'\n", value);
318 ret_val = 1;
319 }
320 } else if (strcmp(command, "reboot") == 0) {
321 // Reboot
322 } else if (strcmp(command, "cmd") == 0) {
323 if (cindex != 0) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500324 string status;
325 TWFunc::Exec_Cmd(value, status);
Dees_Troy812660f2012-09-20 09:55:17 -0400326 } else {
327 LOGE("No value given for cmd\n");
328 }
329 } else if (strcmp(command, "print") == 0) {
330 ui_print("%s\n", value);
331 } else {
332 LOGE("Unrecognized script command: '%s'\n", command);
333 ret_val = 1;
334 }
335 }
336 fclose(fp);
337 ui_print("Done processing script file\n");
338 } else {
339 LOGE("Error opening script file '%s'\n", SCRIPT_FILE_TMP);
340 return 1;
341 }
Dees_Troy06b4fe92012-10-16 11:43:20 -0400342 if (install_cmd && DataManager_GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager_GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500343 string status;
Dees_Troy06b4fe92012-10-16 11:43:20 -0400344 ui_print("Injecting TWRP into boot image...\n");
345 TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
346 if (Boot == NULL || Boot->Current_File_System != "emmc")
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500347 TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash", status);
Dees_Troy06b4fe92012-10-16 11:43:20 -0400348 else {
349 string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device;
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500350 TWFunc::Exec_Cmd(injectcmd.c_str(), status);
Dees_Troy06b4fe92012-10-16 11:43:20 -0400351 }
352 ui_print("TWRP injection complete.\n");
353 }
Dees_Troy812660f2012-09-20 09:55:17 -0400354 return ret_val;
355}
356
Dees_Troy83a3b122012-10-01 14:16:43 -0400357int OpenRecoveryScript::Install_Command(string Zip) {
358 // Install zip
359 string ret_string;
360 int ret_val = 0, wipe_cache = 0;
361
362 PartitionManager.Mount_All_Storage();
363 if (Zip.substr(0, 1) != "/") {
364 // Relative path given
365 string Full_Path;
366
367 Full_Path = DataManager_GetCurrentStoragePath();
368 Full_Path += "/" + Zip;
369 LOGI("Full zip path: '%s'\n", Full_Path.c_str());
370 if (!TWFunc::Path_Exists(Full_Path)) {
371 ret_string = Locate_Zip_File(Full_Path, DataManager_GetCurrentStoragePath());
372 if (!ret_string.empty()) {
373 Full_Path = ret_string;
374 } else if (DataManager_GetIntValue(TW_HAS_DUAL_STORAGE)) {
375 if (DataManager_GetIntValue(TW_USE_EXTERNAL_STORAGE)) {
376 LOGI("Zip file not found on external storage, trying internal...\n");
377 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 0);
378 } else {
379 LOGI("Zip file not found on internal storage, trying external...\n");
380 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 1);
381 }
382 Full_Path = DataManager_GetCurrentStoragePath();
383 Full_Path += "/" + Zip;
384 LOGI("Full zip path: '%s'\n", Full_Path.c_str());
385 ret_string = Locate_Zip_File(Full_Path, DataManager_GetCurrentStoragePath());
386 if (!ret_string.empty())
387 Full_Path = ret_string;
388 }
389 }
390 Zip = Full_Path;
391 } else {
392 // Full path given
393 if (!TWFunc::Path_Exists(Zip)) {
394 ret_string = Locate_Zip_File(Zip, DataManager_GetCurrentStoragePath());
395 if (!ret_string.empty())
396 Zip = ret_string;
397 }
398 }
399
400 if (!TWFunc::Path_Exists(Zip)) {
401 // zip file doesn't exist
402 ui_print("Unable to locate zip file '%s'.\n", Zip.c_str());
403 ret_val = 1;
404 } else {
405 ui_print("Installing zip file '%s'\n", Zip.c_str());
406 ret_val = TWinstall_zip(Zip.c_str(), &wipe_cache);
407 }
408 if (ret_val != 0) {
409 LOGE("Error installing zip file '%s'\n", Zip.c_str());
410 ret_val = 1;
411 } else if (wipe_cache)
412 PartitionManager.Wipe_By_Path("/cache");
413
414 return ret_val;
415}
416
Dees_Troy812660f2012-09-20 09:55:17 -0400417string OpenRecoveryScript::Locate_Zip_File(string Zip, string Storage_Root) {
418 string Path = TWFunc::Get_Path(Zip);
419 string File = TWFunc::Get_Filename(Zip);
420 string pathCpy = Path;
421 string wholePath;
422 size_t pos = Path.find("/", 1);
423
424 while (pos != string::npos)
425 {
426 pathCpy = Path.substr(pos, Path.size() - pos);
427 wholePath = pathCpy + "/" + File;
428 if (TWFunc::Path_Exists(wholePath))
429 return wholePath;
430 wholePath = Storage_Root + "/" + wholePath;
431 if (TWFunc::Path_Exists(wholePath))
432 return wholePath;
433
434 pos = Path.find("/", pos + 1);
435 }
436 return "";
Dees_Troy83a3b122012-10-01 14:16:43 -0400437}
438
439int OpenRecoveryScript::Backup_Command(string Options) {
440 char value1[SCRIPT_COMMAND_SIZE];
441 int line_len, i;
442
443 strcpy(value1, Options.c_str());
444
445 DataManager_SetIntValue(TW_BACKUP_SYSTEM_VAR, 0);
446 DataManager_SetIntValue(TW_BACKUP_DATA_VAR, 0);
447 DataManager_SetIntValue(TW_BACKUP_CACHE_VAR, 0);
448 DataManager_SetIntValue(TW_BACKUP_RECOVERY_VAR, 0);
449 DataManager_SetIntValue(TW_BACKUP_SP1_VAR, 0);
450 DataManager_SetIntValue(TW_BACKUP_SP2_VAR, 0);
451 DataManager_SetIntValue(TW_BACKUP_SP3_VAR, 0);
452 DataManager_SetIntValue(TW_BACKUP_BOOT_VAR, 0);
453 DataManager_SetIntValue(TW_BACKUP_ANDSEC_VAR, 0);
454 DataManager_SetIntValue(TW_BACKUP_SDEXT_VAR, 0);
455 DataManager_SetIntValue(TW_BACKUP_SDEXT_VAR, 0);
456 DataManager_SetIntValue(TW_USE_COMPRESSION_VAR, 0);
457 DataManager_SetIntValue(TW_SKIP_MD5_GENERATE_VAR, 0);
458
459 ui_print("Setting backup options:\n");
460 line_len = Options.size();
461 for (i=0; i<line_len; i++) {
462 if (Options.substr(i, 1) == "S" || Options.substr(i, 1) == "s") {
463 DataManager_SetIntValue(TW_BACKUP_SYSTEM_VAR, 1);
464 ui_print("System\n");
465 } else if (Options.substr(i, 1) == "D" || Options.substr(i, 1) == "d") {
466 DataManager_SetIntValue(TW_BACKUP_DATA_VAR, 1);
467 ui_print("Data\n");
468 } else if (Options.substr(i, 1) == "C" || Options.substr(i, 1) == "c") {
469 DataManager_SetIntValue(TW_BACKUP_CACHE_VAR, 1);
470 ui_print("Cache\n");
471 } else if (Options.substr(i, 1) == "R" || Options.substr(i, 1) == "r") {
472 DataManager_SetIntValue(TW_BACKUP_RECOVERY_VAR, 1);
473 ui_print("Recovery\n");
474 } else if (Options.substr(i, 1) == "1") {
475 DataManager_SetIntValue(TW_BACKUP_SP1_VAR, 1);
476 ui_print("%s\n", "Special1");
477 } else if (Options.substr(i, 1) == "2") {
478 DataManager_SetIntValue(TW_BACKUP_SP2_VAR, 1);
479 ui_print("%s\n", "Special2");
480 } else if (Options.substr(i, 1) == "3") {
481 DataManager_SetIntValue(TW_BACKUP_SP3_VAR, 1);
482 ui_print("%s\n", "Special3");
483 } else if (Options.substr(i, 1) == "B" || Options.substr(i, 1) == "b") {
484 DataManager_SetIntValue(TW_BACKUP_BOOT_VAR, 1);
485 ui_print("Boot\n");
486 } else if (Options.substr(i, 1) == "A" || Options.substr(i, 1) == "a") {
487 DataManager_SetIntValue(TW_BACKUP_ANDSEC_VAR, 1);
488 ui_print("Android Secure\n");
489 } else if (Options.substr(i, 1) == "E" || Options.substr(i, 1) == "e") {
490 DataManager_SetIntValue(TW_BACKUP_SDEXT_VAR, 1);
491 ui_print("SD-Ext\n");
492 } else if (Options.substr(i, 1) == "O" || Options.substr(i, 1) == "o") {
493 DataManager_SetIntValue(TW_USE_COMPRESSION_VAR, 1);
494 ui_print("Compression is on\n");
495 } else if (Options.substr(i, 1) == "M" || Options.substr(i, 1) == "m") {
496 DataManager_SetIntValue(TW_SKIP_MD5_GENERATE_VAR, 1);
497 ui_print("MD5 Generation is off\n");
498 }
499 }
500 if (!PartitionManager.Run_Backup()) {
501 LOGE("Backup failed!\n");
502 return 1;
503 }
504 ui_print("Backup complete!\n");
505 return 0;
506}