blob: 4fbb6784e5aba145de374ad32088c6dd8fd56f73 [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
Dees_Troydc8bc1b2013-01-17 01:39:28 +0000106 PartitionManager.Mount_All_Storage();
Dees_Troy83a3b122012-10-01 14:16:43 -0400107 ret_val = Install_Command(value);
Dees_Troy06b4fe92012-10-16 11:43:20 -0400108 install_cmd = -1;
Dees_Troy812660f2012-09-20 09:55:17 -0400109 } else if (strcmp(command, "wipe") == 0) {
110 // Wipe
111 if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) {
112 ui_print("-- Wiping Cache Partition...\n");
113 PartitionManager.Wipe_By_Path("/cache");
114 ui_print("-- Cache Partition Wipe Complete!\n");
115 } else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) {
116 ui_print("-- Wiping Dalvik Cache...\n");
117 PartitionManager.Wipe_Dalvik_Cache();
118 ui_print("-- Dalvik Cache Wipe Complete!\n");
119 } else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) {
120 ui_print("-- Wiping Data Partition...\n");
121 PartitionManager.Factory_Reset();
122 ui_print("-- Data Partition Wipe Complete!\n");
123 } else {
124 LOGE("Error with wipe command value: '%s'\n", value);
125 ret_val = 1;
126 }
127 } else if (strcmp(command, "backup") == 0) {
128 // Backup
129 tok = strtok(value, " ");
130 strcpy(value1, tok);
131 tok = strtok(NULL, " ");
132 if (tok != NULL) {
133 memset(value2, 0, sizeof(value2));
134 strcpy(value2, tok);
135 line_len = strlen(tok);
136 if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) {
137 if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13)
138 remove_nl = 2;
139 else
140 remove_nl = 1;
141 } else
142 remove_nl = 0;
143 strncpy(value2, tok, line_len - remove_nl);
144 DataManager_SetStrValue(TW_BACKUP_NAME, value2);
145 ui_print("Backup folder set to '%s'\n", value2);
Dees_Troyc9ff7a32012-09-27 10:09:41 -0400146 if (PartitionManager.Check_Backup_Name(true) != 0) {
147 ret_val = 1;
148 continue;
149 }
Dees_Troy812660f2012-09-20 09:55:17 -0400150 } else {
151 char empt[50];
152 strcpy(empt, "(Current Date)");
153 DataManager_SetStrValue(TW_BACKUP_NAME, empt);
154 }
Dees_Troy83a3b122012-10-01 14:16:43 -0400155 ret_val = Backup_Command(value1);
Dees_Troy812660f2012-09-20 09:55:17 -0400156 } else if (strcmp(command, "restore") == 0) {
157 // Restore
158 PartitionManager.Mount_All_Storage();
159 DataManager_SetIntValue(TW_SKIP_MD5_CHECK_VAR, 0);
Dees_Troydc8bc1b2013-01-17 01:39:28 +0000160 char folder_path[512], partitions[512];
Dees_Troy812660f2012-09-20 09:55:17 -0400161
162 string val = value, restore_folder, restore_partitions;
163 size_t pos = val.find_last_of(" ");
164 if (pos == string::npos) {
Dees_Troydc8bc1b2013-01-17 01:39:28 +0000165 restore_folder = value;
166 partitions[0] = '\0';
167 } else {
168 restore_folder = val.substr(0, pos);
169 restore_partitions = val.substr(pos + 1, val.size() - pos - 1);
170 strcpy(partitions, restore_partitions.c_str());
Dees_Troy812660f2012-09-20 09:55:17 -0400171 }
Dees_Troy812660f2012-09-20 09:55:17 -0400172 strcpy(folder_path, restore_folder.c_str());
Dees_Troy812660f2012-09-20 09:55:17 -0400173 LOGI("Restore folder is: '%s' and partitions: '%s'\n", folder_path, partitions);
174 ui_print("Restoring '%s'\n", folder_path);
175
176 if (folder_path[0] != '/') {
177 char backup_folder[512];
178 sprintf(backup_folder, "%s/%s", DataManager_GetStrValue(TW_BACKUPS_FOLDER_VAR), folder_path);
179 LOGI("Restoring relative path: '%s'\n", backup_folder);
180 if (!TWFunc::Path_Exists(backup_folder)) {
181 if (DataManager_GetIntValue(TW_HAS_DUAL_STORAGE)) {
182 if (DataManager_GetIntValue(TW_USE_EXTERNAL_STORAGE)) {
183 LOGI("Backup folder '%s' not found on external storage, trying internal...\n", folder_path);
184 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 0);
185 } else {
186 LOGI("Backup folder '%s' not found on internal storage, trying external...\n", folder_path);
187 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 1);
188 }
189 sprintf(backup_folder, "%s/%s", DataManager_GetStrValue(TW_BACKUPS_FOLDER_VAR), folder_path);
190 LOGI("2Restoring relative path: '%s'\n", backup_folder);
191 }
192 }
193 strcpy(folder_path, backup_folder);
194 } else {
195 if (folder_path[strlen(folder_path) - 1] == '/')
196 strcat(folder_path, ".");
197 else
198 strcat(folder_path, "/.");
199 }
200 if (!TWFunc::Path_Exists(folder_path)) {
201 ui_print("Unable to locate backup '%s'\n", folder_path);
202 ret_val = 1;
203 continue;
204 }
205 DataManager_SetStrValue("tw_restore", folder_path);
206
207 PartitionManager.Set_Restore_Files(folder_path);
208 if (strlen(partitions) != 0) {
209 int tw_restore_system = 0;
210 int tw_restore_data = 0;
211 int tw_restore_cache = 0;
212 int tw_restore_recovery = 0;
213 int tw_restore_boot = 0;
214 int tw_restore_andsec = 0;
215 int tw_restore_sdext = 0;
216 int tw_restore_sp1 = 0;
217 int tw_restore_sp2 = 0;
218 int tw_restore_sp3 = 0;
219
220 memset(value2, 0, sizeof(value2));
221 strcpy(value2, partitions);
222 ui_print("Setting restore options: '%s':\n", value2);
223 line_len = strlen(value2);
224 for (i=0; i<line_len; i++) {
225 if ((value2[i] == 'S' || value2[i] == 's') && DataManager_GetIntValue(TW_RESTORE_SYSTEM_VAR) > 0) {
226 tw_restore_system = 1;
227 ui_print("System\n");
228 } else if ((value2[i] == 'D' || value2[i] == 'd') && DataManager_GetIntValue(TW_RESTORE_DATA_VAR) > 0) {
229 tw_restore_data = 1;
230 ui_print("Data\n");
231 } else if ((value2[i] == 'C' || value2[i] == 'c') && DataManager_GetIntValue(TW_RESTORE_CACHE_VAR) > 0) {
232 tw_restore_cache = 1;
233 ui_print("Cache\n");
234 } else if ((value2[i] == 'R' || value2[i] == 'r') && DataManager_GetIntValue(TW_RESTORE_RECOVERY_VAR) > 0) {
235 tw_restore_recovery = 1;
236 ui_print("Recovery\n");
237 } else if (value2[i] == '1' && DataManager_GetIntValue(TW_RESTORE_SP1_VAR) > 0) {
238 tw_restore_sp1 = 1;
239 ui_print("%s\n", "Special1");
240 } else if (value2[i] == '2' && DataManager_GetIntValue(TW_RESTORE_SP2_VAR) > 0) {
241 tw_restore_sp2 = 1;
242 ui_print("%s\n", "Special2");
243 } else if (value2[i] == '3' && DataManager_GetIntValue(TW_RESTORE_SP3_VAR) > 0) {
244 tw_restore_sp3 = 1;
245 ui_print("%s\n", "Special3");
246 } else if ((value2[i] == 'B' || value2[i] == 'b') && DataManager_GetIntValue(TW_RESTORE_BOOT_VAR) > 0) {
247 tw_restore_boot = 1;
248 ui_print("Boot\n");
249 } else if ((value2[i] == 'A' || value2[i] == 'a') && DataManager_GetIntValue(TW_RESTORE_ANDSEC_VAR) > 0) {
250 tw_restore_andsec = 1;
251 ui_print("Android Secure\n");
252 } else if ((value2[i] == 'E' || value2[i] == 'e') && DataManager_GetIntValue(TW_RESTORE_SDEXT_VAR) > 0) {
253 tw_restore_sdext = 1;
254 ui_print("SD-Ext\n");
255 } else if (value2[i] == 'M' || value2[i] == 'm') {
256 DataManager_SetIntValue(TW_SKIP_MD5_CHECK_VAR, 1);
257 ui_print("MD5 check skip is on\n");
258 }
259 }
260
261 if (DataManager_GetIntValue(TW_RESTORE_SYSTEM_VAR) && !tw_restore_system)
262 DataManager_SetIntValue(TW_RESTORE_SYSTEM_VAR, 0);
263 if (DataManager_GetIntValue(TW_RESTORE_DATA_VAR) && !tw_restore_data)
264 DataManager_SetIntValue(TW_RESTORE_DATA_VAR, 0);
265 if (DataManager_GetIntValue(TW_RESTORE_CACHE_VAR) && !tw_restore_cache)
266 DataManager_SetIntValue(TW_RESTORE_CACHE_VAR, 0);
267 if (DataManager_GetIntValue(TW_RESTORE_RECOVERY_VAR) && !tw_restore_recovery)
268 DataManager_SetIntValue(TW_RESTORE_RECOVERY_VAR, 0);
269 if (DataManager_GetIntValue(TW_RESTORE_BOOT_VAR) && !tw_restore_boot)
270 DataManager_SetIntValue(TW_RESTORE_BOOT_VAR, 0);
271 if (DataManager_GetIntValue(TW_RESTORE_ANDSEC_VAR) && !tw_restore_andsec)
272 DataManager_SetIntValue(TW_RESTORE_ANDSEC_VAR, 0);
273 if (DataManager_GetIntValue(TW_RESTORE_SDEXT_VAR) && !tw_restore_sdext)
274 DataManager_SetIntValue(TW_RESTORE_SDEXT_VAR, 0);
275 if (DataManager_GetIntValue(TW_RESTORE_SP1_VAR) && !tw_restore_sp1)
276 DataManager_SetIntValue(TW_RESTORE_SP1_VAR, 0);
277 if (DataManager_GetIntValue(TW_RESTORE_SP2_VAR) && !tw_restore_sp2)
278 DataManager_SetIntValue(TW_RESTORE_SP2_VAR, 0);
279 if (DataManager_GetIntValue(TW_RESTORE_SP3_VAR) && !tw_restore_sp3)
280 DataManager_SetIntValue(TW_RESTORE_SP3_VAR, 0);
Dees_Troy812660f2012-09-20 09:55:17 -0400281 }
282 PartitionManager.Run_Restore(folder_path);
283 ui_print("Restore complete!\n");
284 } else if (strcmp(command, "mount") == 0) {
285 // Mount
286 if (value[0] != '/') {
287 strcpy(mount, "/");
288 strcat(mount, value);
289 } else
290 strcpy(mount, value);
291 if (PartitionManager.Mount_By_Path(mount, true))
292 ui_print("Mounted '%s'\n", mount);
293 } else if (strcmp(command, "unmount") == 0 || strcmp(command, "umount") == 0) {
294 // Unmount
295 if (value[0] != '/') {
296 strcpy(mount, "/");
297 strcat(mount, value);
298 } else
299 strcpy(mount, value);
300 if (PartitionManager.UnMount_By_Path(mount, true))
301 ui_print("Unmounted '%s'\n", mount);
302 } else if (strcmp(command, "set") == 0) {
303 // Set value
304 tok = strtok(value, " ");
305 strcpy(value1, tok);
306 tok = strtok(NULL, " ");
307 strcpy(value2, tok);
308 ui_print("Setting '%s' to '%s'\n", value1, value2);
309 DataManager_SetStrValue(value1, value2);
310 } else if (strcmp(command, "mkdir") == 0) {
311 // Make directory (recursive)
312 ui_print("Making directory (recursive): '%s'\n", value);
313 if (TWFunc::Recursive_Mkdir(value)) {
314 LOGE("Unable to create folder: '%s'\n", value);
315 ret_val = 1;
316 }
317 } else if (strcmp(command, "reboot") == 0) {
318 // Reboot
319 } else if (strcmp(command, "cmd") == 0) {
320 if (cindex != 0) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500321 string status;
322 TWFunc::Exec_Cmd(value, status);
Dees_Troy812660f2012-09-20 09:55:17 -0400323 } else {
324 LOGE("No value given for cmd\n");
325 }
326 } else if (strcmp(command, "print") == 0) {
327 ui_print("%s\n", value);
328 } else {
329 LOGE("Unrecognized script command: '%s'\n", command);
330 ret_val = 1;
331 }
332 }
333 fclose(fp);
334 ui_print("Done processing script file\n");
335 } else {
336 LOGE("Error opening script file '%s'\n", SCRIPT_FILE_TMP);
337 return 1;
338 }
Dees_Troy06b4fe92012-10-16 11:43:20 -0400339 if (install_cmd && DataManager_GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager_GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500340 string status;
Dees_Troy06b4fe92012-10-16 11:43:20 -0400341 ui_print("Injecting TWRP into boot image...\n");
342 TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
343 if (Boot == NULL || Boot->Current_File_System != "emmc")
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500344 TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash", status);
Dees_Troy06b4fe92012-10-16 11:43:20 -0400345 else {
346 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 -0500347 TWFunc::Exec_Cmd(injectcmd.c_str(), status);
Dees_Troy06b4fe92012-10-16 11:43:20 -0400348 }
349 ui_print("TWRP injection complete.\n");
350 }
Dees_Troy812660f2012-09-20 09:55:17 -0400351 return ret_val;
352}
353
Dees_Troy83a3b122012-10-01 14:16:43 -0400354int OpenRecoveryScript::Install_Command(string Zip) {
355 // Install zip
356 string ret_string;
357 int ret_val = 0, wipe_cache = 0;
358
359 PartitionManager.Mount_All_Storage();
360 if (Zip.substr(0, 1) != "/") {
361 // Relative path given
362 string Full_Path;
363
364 Full_Path = DataManager_GetCurrentStoragePath();
365 Full_Path += "/" + Zip;
366 LOGI("Full zip path: '%s'\n", Full_Path.c_str());
367 if (!TWFunc::Path_Exists(Full_Path)) {
368 ret_string = Locate_Zip_File(Full_Path, DataManager_GetCurrentStoragePath());
369 if (!ret_string.empty()) {
370 Full_Path = ret_string;
371 } else if (DataManager_GetIntValue(TW_HAS_DUAL_STORAGE)) {
372 if (DataManager_GetIntValue(TW_USE_EXTERNAL_STORAGE)) {
373 LOGI("Zip file not found on external storage, trying internal...\n");
374 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 0);
375 } else {
376 LOGI("Zip file not found on internal storage, trying external...\n");
377 DataManager_SetIntValue(TW_USE_EXTERNAL_STORAGE, 1);
378 }
379 Full_Path = DataManager_GetCurrentStoragePath();
380 Full_Path += "/" + Zip;
381 LOGI("Full zip path: '%s'\n", Full_Path.c_str());
382 ret_string = Locate_Zip_File(Full_Path, DataManager_GetCurrentStoragePath());
383 if (!ret_string.empty())
384 Full_Path = ret_string;
385 }
386 }
387 Zip = Full_Path;
388 } else {
389 // Full path given
390 if (!TWFunc::Path_Exists(Zip)) {
391 ret_string = Locate_Zip_File(Zip, DataManager_GetCurrentStoragePath());
392 if (!ret_string.empty())
393 Zip = ret_string;
394 }
395 }
396
397 if (!TWFunc::Path_Exists(Zip)) {
398 // zip file doesn't exist
399 ui_print("Unable to locate zip file '%s'.\n", Zip.c_str());
400 ret_val = 1;
401 } else {
402 ui_print("Installing zip file '%s'\n", Zip.c_str());
403 ret_val = TWinstall_zip(Zip.c_str(), &wipe_cache);
404 }
405 if (ret_val != 0) {
406 LOGE("Error installing zip file '%s'\n", Zip.c_str());
407 ret_val = 1;
408 } else if (wipe_cache)
409 PartitionManager.Wipe_By_Path("/cache");
410
411 return ret_val;
412}
413
Dees_Troy812660f2012-09-20 09:55:17 -0400414string OpenRecoveryScript::Locate_Zip_File(string Zip, string Storage_Root) {
415 string Path = TWFunc::Get_Path(Zip);
416 string File = TWFunc::Get_Filename(Zip);
417 string pathCpy = Path;
418 string wholePath;
419 size_t pos = Path.find("/", 1);
420
421 while (pos != string::npos)
422 {
423 pathCpy = Path.substr(pos, Path.size() - pos);
424 wholePath = pathCpy + "/" + File;
425 if (TWFunc::Path_Exists(wholePath))
426 return wholePath;
427 wholePath = Storage_Root + "/" + wholePath;
428 if (TWFunc::Path_Exists(wholePath))
429 return wholePath;
430
431 pos = Path.find("/", pos + 1);
432 }
433 return "";
Dees_Troy83a3b122012-10-01 14:16:43 -0400434}
435
436int OpenRecoveryScript::Backup_Command(string Options) {
437 char value1[SCRIPT_COMMAND_SIZE];
438 int line_len, i;
439
440 strcpy(value1, Options.c_str());
441
442 DataManager_SetIntValue(TW_BACKUP_SYSTEM_VAR, 0);
443 DataManager_SetIntValue(TW_BACKUP_DATA_VAR, 0);
444 DataManager_SetIntValue(TW_BACKUP_CACHE_VAR, 0);
445 DataManager_SetIntValue(TW_BACKUP_RECOVERY_VAR, 0);
446 DataManager_SetIntValue(TW_BACKUP_SP1_VAR, 0);
447 DataManager_SetIntValue(TW_BACKUP_SP2_VAR, 0);
448 DataManager_SetIntValue(TW_BACKUP_SP3_VAR, 0);
449 DataManager_SetIntValue(TW_BACKUP_BOOT_VAR, 0);
450 DataManager_SetIntValue(TW_BACKUP_ANDSEC_VAR, 0);
451 DataManager_SetIntValue(TW_BACKUP_SDEXT_VAR, 0);
452 DataManager_SetIntValue(TW_BACKUP_SDEXT_VAR, 0);
453 DataManager_SetIntValue(TW_USE_COMPRESSION_VAR, 0);
454 DataManager_SetIntValue(TW_SKIP_MD5_GENERATE_VAR, 0);
455
456 ui_print("Setting backup options:\n");
457 line_len = Options.size();
458 for (i=0; i<line_len; i++) {
459 if (Options.substr(i, 1) == "S" || Options.substr(i, 1) == "s") {
460 DataManager_SetIntValue(TW_BACKUP_SYSTEM_VAR, 1);
461 ui_print("System\n");
462 } else if (Options.substr(i, 1) == "D" || Options.substr(i, 1) == "d") {
463 DataManager_SetIntValue(TW_BACKUP_DATA_VAR, 1);
464 ui_print("Data\n");
465 } else if (Options.substr(i, 1) == "C" || Options.substr(i, 1) == "c") {
466 DataManager_SetIntValue(TW_BACKUP_CACHE_VAR, 1);
467 ui_print("Cache\n");
468 } else if (Options.substr(i, 1) == "R" || Options.substr(i, 1) == "r") {
469 DataManager_SetIntValue(TW_BACKUP_RECOVERY_VAR, 1);
470 ui_print("Recovery\n");
471 } else if (Options.substr(i, 1) == "1") {
472 DataManager_SetIntValue(TW_BACKUP_SP1_VAR, 1);
473 ui_print("%s\n", "Special1");
474 } else if (Options.substr(i, 1) == "2") {
475 DataManager_SetIntValue(TW_BACKUP_SP2_VAR, 1);
476 ui_print("%s\n", "Special2");
477 } else if (Options.substr(i, 1) == "3") {
478 DataManager_SetIntValue(TW_BACKUP_SP3_VAR, 1);
479 ui_print("%s\n", "Special3");
480 } else if (Options.substr(i, 1) == "B" || Options.substr(i, 1) == "b") {
481 DataManager_SetIntValue(TW_BACKUP_BOOT_VAR, 1);
482 ui_print("Boot\n");
483 } else if (Options.substr(i, 1) == "A" || Options.substr(i, 1) == "a") {
484 DataManager_SetIntValue(TW_BACKUP_ANDSEC_VAR, 1);
485 ui_print("Android Secure\n");
486 } else if (Options.substr(i, 1) == "E" || Options.substr(i, 1) == "e") {
487 DataManager_SetIntValue(TW_BACKUP_SDEXT_VAR, 1);
488 ui_print("SD-Ext\n");
489 } else if (Options.substr(i, 1) == "O" || Options.substr(i, 1) == "o") {
490 DataManager_SetIntValue(TW_USE_COMPRESSION_VAR, 1);
491 ui_print("Compression is on\n");
492 } else if (Options.substr(i, 1) == "M" || Options.substr(i, 1) == "m") {
493 DataManager_SetIntValue(TW_SKIP_MD5_GENERATE_VAR, 1);
494 ui_print("MD5 Generation is off\n");
495 }
496 }
497 if (!PartitionManager.Run_Backup()) {
498 LOGE("Backup failed!\n");
499 return 1;
500 }
501 ui_print("Backup complete!\n");
502 return 0;
503}