Guest User

PhilZ-cwm6 extendedcommands.c

a guest
Nov 9th, 2012
1,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 33.31 KB | None | 0 0
  1. //start PhilZ Menu settings and functions
  2.   // custom open recovery script code
  3. #define SCRIPT_COMMAND_SIZE 512
  4.  
  5. int run_custom_ors(const char* ors_script) {
  6.     FILE *fp = fopen(ors_script, "r");
  7.     int ret_val = 0, cindex, line_len, i, remove_nl;
  8.     char script_line[SCRIPT_COMMAND_SIZE], command[SCRIPT_COMMAND_SIZE],
  9.          value[SCRIPT_COMMAND_SIZE], mount[SCRIPT_COMMAND_SIZE],
  10.          value1[SCRIPT_COMMAND_SIZE], value2[SCRIPT_COMMAND_SIZE];
  11.     char *val_start, *tok;
  12.     int ors_system = 0;
  13.     int ors_data = 0;
  14.     int ors_cache = 0;
  15.     int ors_recovery = 0;
  16.     int ors_boot = 0;
  17.     int ors_andsec = 0;
  18.     int ors_sdext = 0;
  19.  
  20.     if (fp != NULL) {
  21.         while (fgets(script_line, SCRIPT_COMMAND_SIZE, fp) != NULL && ret_val == 0) {
  22.             cindex = 0;
  23.             line_len = strlen(script_line);
  24.             //if (line_len > 2)
  25.                 //continue; // there's a blank line at the end of the file, we're done!
  26.             ui_print("script line: '%s'\n", script_line);
  27.             for (i=0; i<line_len; i++) {
  28.                 if ((int)script_line[i] == 32) {
  29.                     cindex = i;
  30.                     i = line_len;
  31.                 }
  32.             }
  33.             memset(command, 0, sizeof(command));
  34.             memset(value, 0, sizeof(value));
  35.             if ((int)script_line[line_len - 1] == 10)
  36.                 remove_nl = 2;
  37.             else
  38.                 remove_nl = 1;
  39.             if (cindex != 0) {
  40.                 strncpy(command, script_line, cindex);
  41.                 ui_print("command is: '%s' and ", command);
  42.                 val_start = script_line;
  43.                 val_start += cindex + 1;
  44.                 strncpy(value, val_start, line_len - cindex - remove_nl);
  45.                 ui_print("value is: '%s'\n", value);
  46.             } else {
  47.                 strncpy(command, script_line, line_len - remove_nl + 1);
  48.                 ui_print("command is: '%s' and there is no value\n", command);
  49.             }
  50.             if (strcmp(command, "install") == 0) {
  51.                 // Install zip
  52.                 ui_print("Installing zip file '%s'\n", value);
  53.                 ensure_path_mounted("/emmc");
  54.                 ensure_path_mounted("/sdcard");
  55.                 ret_val = install_zip(value);
  56.                 if (ret_val != INSTALL_SUCCESS) {
  57.                     LOGE("Error installing zip file '%s'\n", value);
  58.                     ret_val = 1;
  59.                 }
  60.             } else if (strcmp(command, "wipe") == 0) {
  61.                 // Wipe
  62.                 if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) {
  63.                     ui_print("-- Wiping Cache Partition...\n");
  64.                     erase_volume("/cache");
  65.                     ui_print("-- Cache Partition Wipe Complete!\n");
  66.                 } else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) {
  67.                     ui_print("-- Wiping Dalvik Cache...\n");
  68.                     if (0 != ensure_path_mounted("/data")) {
  69.                         ret_val = 1;
  70.                         break;
  71.                     }
  72.                     ensure_path_mounted("/sd-ext");
  73.                     ensure_path_mounted("/cache");
  74.                     if (confirm_selection( "Confirm wipe?", "Yes - Wipe Dalvik Cache")) {
  75.                         __system("rm -r /data/dalvik-cache");
  76.                         __system("rm -r /cache/dalvik-cache");
  77.                         __system("rm -r /sd-ext/dalvik-cache");
  78.                         ui_print("Dalvik Cache wiped.\n");
  79.                     }
  80.                     ensure_path_unmounted("/data");
  81.                     ui_print("-- Dalvik Cache Wipe Complete!\n");
  82.                 } else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) {
  83.                     ui_print("-- Wiping Data Partition...\n");
  84.                     wipe_data(0);
  85.                     ui_print("-- Data Partition Wipe Complete!\n");
  86.                 } else {
  87.                     LOGE("Error with wipe command value: '%s'\n", value);
  88.                     ret_val = 1;
  89.                 }
  90.             } else if (strcmp(command, "backup") == 0) {
  91.                 // Backup
  92.                 char backup_path[PATH_MAX];
  93.                 tok = strtok(value, " ");
  94.                 strcpy(value1, tok);
  95.                 tok = strtok(NULL, " ");
  96.                 if (tok != NULL) {
  97.                     memset(value2, 0, sizeof(value2));
  98.                     strcpy(value2, tok);
  99.                     line_len = strlen(tok);
  100.                     if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) {
  101.                         if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13)
  102.                             remove_nl = 2;
  103.                         else
  104.                             remove_nl = 1;
  105.                     } else
  106.                         remove_nl = 0;
  107.                     strncpy(value2, tok, line_len - remove_nl);
  108.                     ui_print("Backup folder set to '%s'\n", value2);
  109.                     sprintf(backup_path, "/sdcard/clockworkmod/backup/%s", value2);
  110.                 } else {
  111.                     time_t t = time(NULL);
  112.                     struct tm *tmp = localtime(&t);
  113.                     if (tmp == NULL)
  114.                     {
  115.                         struct timeval tp;
  116.                         gettimeofday(&tp, NULL);
  117.                         sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec);
  118.                     }
  119.                     else
  120.                     {
  121.                         strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
  122.                     }
  123.                 }
  124.                 ui_print("Backup options are ignored in CWMR: '%s'\n", value1);
  125.                 nandroid_backup(backup_path);
  126.                 ui_print("Backup complete!\n");
  127.             } else if (strcmp(command, "restore") == 0) {
  128.                 // Restore
  129.                 tok = strtok(value, " ");
  130.                 strcpy(value1, tok);
  131.                 ui_print("Restoring '%s'\n", value1);
  132.                 tok = strtok(NULL, " ");
  133.                 if (tok != NULL) {
  134.                     ors_system = 0;
  135.                     ors_data = 0;
  136.                     ors_cache = 0;
  137.                     ors_boot = 0;
  138.                     ors_sdext = 0;
  139.                     memset(value2, 0, sizeof(value2));
  140.                     strcpy(value2, tok);
  141.                     ui_print("Setting restore options:\n");
  142.                     line_len = strlen(value2);
  143.                     for (i=0; i<line_len; i++) {
  144.                         if (value2[i] == 'S' || value2[i] == 's') {
  145.                             ors_system = 1;
  146.                             ui_print("System\n");
  147.                         } else if (value2[i] == 'D' || value2[i] == 'd') {
  148.                             ors_data = 1;
  149.                             ui_print("Data\n");
  150.                         } else if (value2[i] == 'C' || value2[i] == 'c') {
  151.                             ors_cache = 1;
  152.                             ui_print("Cache\n");
  153.                         } else if (value2[i] == 'R' || value2[i] == 'r') {
  154.                             ui_print("Option for recovery ignored in CWMR\n");
  155.                         } else if (value2[i] == '1') {
  156.                             ui_print("%s\n", "Option for special1 ignored in CWMR");
  157.                         } else if (value2[i] == '2') {
  158.                             ui_print("%s\n", "Option for special1 ignored in CWMR");
  159.                         } else if (value2[i] == '3') {
  160.                             ui_print("%s\n", "Option for special1 ignored in CWMR");
  161.                         } else if (value2[i] == 'B' || value2[i] == 'b') {
  162.                             ors_boot = 1;
  163.                             ui_print("Boot\n");
  164.                         } else if (value2[i] == 'A' || value2[i] == 'a') {
  165.                             ui_print("Option for android secure ignored in CWMR\n");
  166.                         } else if (value2[i] == 'E' || value2[i] == 'e') {
  167.                             ors_sdext = 1;
  168.                             ui_print("SD-Ext\n");
  169.                         } else if (value2[i] == 'M' || value2[i] == 'm') {
  170.                             ui_print("MD5 check skip option ignored in CWMR\n");
  171.                         }
  172.                     }
  173.                 } else
  174.                     LOGI("No restore options set\n");
  175.                 nandroid_restore(value1, ors_boot, ors_system, ors_data, ors_cache, ors_sdext, 0);
  176.                 ui_print("Restore complete!\n");
  177.             } else if (strcmp(command, "mount") == 0) {
  178.                 // Mount
  179.                 if (value[0] != '/') {
  180.                     strcpy(mount, "/");
  181.                     strcat(mount, value);
  182.                 } else
  183.                     strcpy(mount, value);
  184.                 ensure_path_mounted(mount);
  185.                 ui_print("Mounted '%s'\n", mount);
  186.             } else if (strcmp(command, "unmount") == 0 || strcmp(command, "umount") == 0) {
  187.                 // Unmount
  188.                 if (value[0] != '/') {
  189.                     strcpy(mount, "/");
  190.                     strcat(mount, value);
  191.                 } else
  192.                     strcpy(mount, value);
  193.                 ensure_path_unmounted(mount);
  194.                 ui_print("Unmounted '%s'\n", mount);
  195.             } else if (strcmp(command, "set") == 0) {
  196.                 // Set value
  197.                 tok = strtok(value, " ");
  198.                 strcpy(value1, tok);
  199.                 tok = strtok(NULL, " ");
  200.                 strcpy(value2, tok);
  201.                 ui_print("Setting function disabled in CWMR: '%s' to '%s'\n", value1, value2);
  202.             } else if (strcmp(command, "mkdir") == 0) {
  203.                 // Make directory (recursive)
  204.                 ui_print("Recursive mkdir disabled in CWMR: '%s'\n", value);
  205.             } else if (strcmp(command, "reboot") == 0) {
  206.                 // Reboot
  207.             } else if (strcmp(command, "cmd") == 0) {
  208.                 if (cindex != 0) {
  209.                     __system(value);
  210.                 } else {
  211.                     LOGE("No value given for cmd\n");
  212.                 }
  213.             } else {
  214.                 LOGE("Unrecognized script command: '%s'\n", command);
  215.                 ret_val = 1;
  216.             }
  217.         }
  218.         fclose(fp);
  219.         ui_print("Done processing script file\n");
  220.     } else {
  221.         LOGE("Error opening script file '%s'\n", ors_script);
  222.         return 1;
  223.     }
  224.     return ret_val;
  225. }
  226.   // open recovery script code
  227. static const char *SCRIPT_FILE_CACHE = "/cache/recovery/openrecoveryscript";
  228. static const char *SCRIPT_FILE_TMP = "/tmp/openrecoveryscript";
  229.  
  230. int check_for_script_file(void) {
  231.     FILE *fp = fopen(SCRIPT_FILE_CACHE, "r");
  232.     int ret_val = -1;
  233.     char exec[512];
  234.  
  235.     if (fp != NULL) {
  236.         ret_val = 0;
  237.         LOGI("Script file found: '%s'\n", SCRIPT_FILE_CACHE);
  238.         fclose(fp);
  239.         // Copy script file to /tmp
  240.         strcpy(exec, "cp ");
  241.         strcat(exec, SCRIPT_FILE_CACHE);
  242.         strcat(exec, " ");
  243.         strcat(exec, SCRIPT_FILE_TMP);
  244.         __system(exec);
  245.         // Delete the file from /cache
  246.         strcpy(exec, "rm ");
  247.         strcat(exec, SCRIPT_FILE_CACHE);
  248.         // __system(exec);
  249.     }
  250.     return ret_val;
  251. }
  252.  
  253. int run_script_file(void) {
  254.     FILE *fp = fopen(SCRIPT_FILE_TMP, "r");
  255.     int ret_val = 0, cindex, line_len, i, remove_nl;
  256.     char script_line[SCRIPT_COMMAND_SIZE], command[SCRIPT_COMMAND_SIZE],
  257.          value[SCRIPT_COMMAND_SIZE], mount[SCRIPT_COMMAND_SIZE],
  258.          value1[SCRIPT_COMMAND_SIZE], value2[SCRIPT_COMMAND_SIZE];
  259.     char *val_start, *tok;
  260.     int ors_system = 0;
  261.     int ors_data = 0;
  262.     int ors_cache = 0;
  263.     int ors_recovery = 0;
  264.     int ors_boot = 0;
  265.     int ors_andsec = 0;
  266.     int ors_sdext = 0;
  267.  
  268.     if (fp != NULL) {
  269.         while (fgets(script_line, SCRIPT_COMMAND_SIZE, fp) != NULL && ret_val == 0) {
  270.             cindex = 0;
  271.             line_len = strlen(script_line);
  272.             //if (line_len > 2)
  273.                 //continue; // there's a blank line at the end of the file, we're done!
  274.             ui_print("script line: '%s'\n", script_line);
  275.             for (i=0; i<line_len; i++) {
  276.                 if ((int)script_line[i] == 32) {
  277.                     cindex = i;
  278.                     i = line_len;
  279.                 }
  280.             }
  281.             memset(command, 0, sizeof(command));
  282.             memset(value, 0, sizeof(value));
  283.             if ((int)script_line[line_len - 1] == 10)
  284.                     remove_nl = 2;
  285.                 else
  286.                     remove_nl = 1;
  287.             if (cindex != 0) {
  288.                 strncpy(command, script_line, cindex);
  289.                 ui_print("command is: '%s' and ", command);
  290.                 val_start = script_line;
  291.                 val_start += cindex + 1;
  292.                 strncpy(value, val_start, line_len - cindex - remove_nl);
  293.                 ui_print("value is: '%s'\n", value);
  294.             } else {
  295.                 strncpy(command, script_line, line_len - remove_nl + 1);
  296.                 ui_print("command is: '%s' and there is no value\n", command);
  297.             }
  298.             if (strcmp(command, "install") == 0) {
  299.                 // Install zip
  300.                 ui_print("Installing zip file '%s'\n", value);
  301.                 ensure_path_mounted("/emmc");
  302.                 ensure_path_mounted("/sdcard");
  303.                 ret_val = install_zip(value);
  304.                 if (ret_val != INSTALL_SUCCESS) {
  305.                     LOGE("Error installing zip file '%s'\n", value);
  306.                     ret_val = 1;
  307.                 }
  308.             } else if (strcmp(command, "wipe") == 0) {
  309.                 // Wipe
  310.                 if (strcmp(value, "cache") == 0 || strcmp(value, "/cache") == 0) {
  311.                     ui_print("-- Wiping Cache Partition...\n");
  312.                     erase_volume("/cache");
  313.                     ui_print("-- Cache Partition Wipe Complete!\n");
  314.                 } else if (strcmp(value, "dalvik") == 0 || strcmp(value, "dalvick") == 0 || strcmp(value, "dalvikcache") == 0 || strcmp(value, "dalvickcache") == 0) {
  315.                     ui_print("-- Wiping Dalvik Cache...\n");
  316.                     if (0 != ensure_path_mounted("/data")) {
  317.                         ret_val = 1;
  318.                         break;
  319.                     }
  320.                     ensure_path_mounted("/sd-ext");
  321.                     ensure_path_mounted("/cache");
  322.                     __system("rm -r /data/dalvik-cache");
  323.                     __system("rm -r /cache/dalvik-cache");
  324.                     __system("rm -r /sd-ext/dalvik-cache");
  325.                     ui_print("Dalvik Cache wiped.\n");
  326.                     ensure_path_unmounted("/data");
  327.                     ui_print("-- Dalvik Cache Wipe Complete!\n");
  328.                 } else if (strcmp(value, "data") == 0 || strcmp(value, "/data") == 0 || strcmp(value, "factory") == 0 || strcmp(value, "factoryreset") == 0) {
  329.                     ui_print("-- Wiping Data Partition...\n");
  330.                     wipe_data(0);
  331.                     ui_print("-- Data Partition Wipe Complete!\n");
  332.                 } else {
  333.                     LOGE("Error with wipe command value: '%s'\n", value);
  334.                     ret_val = 1;
  335.                 }
  336.             } else if (strcmp(command, "backup") == 0) {
  337.                 // Backup
  338.                 char backup_path[PATH_MAX];
  339.                 tok = strtok(value, " ");
  340.                 strcpy(value1, tok);
  341.                 tok = strtok(NULL, " ");
  342.                 if (tok != NULL) {
  343.                     memset(value2, 0, sizeof(value2));
  344.                     strcpy(value2, tok);
  345.                     line_len = strlen(tok);
  346.                     if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13) {
  347.                         if ((int)value2[line_len - 1] == 10 || (int)value2[line_len - 1] == 13)
  348.                             remove_nl = 2;
  349.                         else
  350.                             remove_nl = 1;
  351.                     } else
  352.                         remove_nl = 0;
  353.                     strncpy(value2, tok, line_len - remove_nl);
  354.                     ui_print("Backup folder set to '%s'\n", value2);
  355.                     sprintf(backup_path, "/sdcard/clockworkmod/backup/%s", value2);
  356.                 } else {
  357.                     time_t t = time(NULL);
  358.                     struct tm *tmp = localtime(&t);
  359.                     if (tmp == NULL)
  360.                     {
  361.                         struct timeval tp;
  362.                         gettimeofday(&tp, NULL);
  363.                         sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec);
  364.                     }
  365.                     else
  366.                     {
  367.                         strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp);
  368.                     }
  369.                 }
  370.                 ui_print("Backup options are ignored in CWMR: '%s'\n", value1);
  371.                 nandroid_backup(backup_path);
  372.                 ui_print("Backup complete!\n");
  373.             } else if (strcmp(command, "restore") == 0) {
  374.                 // Restore
  375.                 tok = strtok(value, " ");
  376.                 strcpy(value1, tok);
  377.                 ui_print("Restoring '%s'\n", value1);
  378.                 tok = strtok(NULL, " ");
  379.                 if (tok != NULL) {
  380.                     ors_system = 0;
  381.                     ors_data = 0;
  382.                     ors_cache = 0;
  383.                     ors_boot = 0;
  384.                     ors_sdext = 0;
  385.                     memset(value2, 0, sizeof(value2));
  386.                     strcpy(value2, tok);
  387.                     ui_print("Setting restore options:\n");
  388.                     line_len = strlen(value2);
  389.                     for (i=0; i<line_len; i++) {
  390.                         if (value2[i] == 'S' || value2[i] == 's') {
  391.                             ors_system = 1;
  392.                             ui_print("System\n");
  393.                         } else if (value2[i] == 'D' || value2[i] == 'd') {
  394.                             ors_data = 1;
  395.                             ui_print("Data\n");
  396.                         } else if (value2[i] == 'C' || value2[i] == 'c') {
  397.                             ors_cache = 1;
  398.                             ui_print("Cache\n");
  399.                         } else if (value2[i] == 'R' || value2[i] == 'r') {
  400.                             ui_print("Option for recovery ignored in CWMR\n");
  401.                         } else if (value2[i] == '1') {
  402.                             ui_print("%s\n", "Option for special1 ignored in CWMR");
  403.                         } else if (value2[i] == '2') {
  404.                             ui_print("%s\n", "Option for special1 ignored in CWMR");
  405.                         } else if (value2[i] == '3') {
  406.                             ui_print("%s\n", "Option for special1 ignored in CWMR");
  407.                         } else if (value2[i] == 'B' || value2[i] == 'b') {
  408.                             ors_boot = 1;
  409.                             ui_print("Boot\n");
  410.                         } else if (value2[i] == 'A' || value2[i] == 'a') {
  411.                             ui_print("Option for android secure ignored in CWMR\n");
  412.                         } else if (value2[i] == 'E' || value2[i] == 'e') {
  413.                             ors_sdext = 1;
  414.                             ui_print("SD-Ext\n");
  415.                         } else if (value2[i] == 'M' || value2[i] == 'm') {
  416.                             ui_print("MD5 check skip option ignored in CWMR\n");
  417.                         }
  418.                     }
  419.                 } else
  420.                     LOGI("No restore options set\n");
  421.                 nandroid_restore(value1, ors_boot, ors_system, ors_data, ors_cache, ors_sdext, 0);
  422.                 ui_print("Restore complete!\n");
  423.             } else if (strcmp(command, "mount") == 0) {
  424.                 // Mount
  425.                 if (value[0] != '/') {
  426.                     strcpy(mount, "/");
  427.                     strcat(mount, value);
  428.                 } else
  429.                     strcpy(mount, value);
  430.                 ensure_path_mounted(mount);
  431.                 ui_print("Mounted '%s'\n", mount);
  432.             } else if (strcmp(command, "unmount") == 0 || strcmp(command, "umount") == 0) {
  433.                 // Unmount
  434.                 if (value[0] != '/') {
  435.                     strcpy(mount, "/");
  436.                     strcat(mount, value);
  437.                 } else
  438.                     strcpy(mount, value);
  439.                 ensure_path_unmounted(mount);
  440.                 ui_print("Unmounted '%s'\n", mount);
  441.             } else if (strcmp(command, "set") == 0) {
  442.                 // Set value
  443.                 tok = strtok(value, " ");
  444.                 strcpy(value1, tok);
  445.                 tok = strtok(NULL, " ");
  446.                 strcpy(value2, tok);
  447.                 ui_print("Setting function disabled in CWMR: '%s' to '%s'\n", value1, value2);
  448.             } else if (strcmp(command, "mkdir") == 0) {
  449.                 // Make directory (recursive)
  450.                 ui_print("Recursive mkdir disabled in CWMR: '%s'\n", value);
  451.             } else if (strcmp(command, "reboot") == 0) {
  452.                 // Reboot
  453.             } else if (strcmp(command, "cmd") == 0) {
  454.                 if (cindex != 0) {
  455.                     __system(value);
  456.                 } else {
  457.                     LOGE("No value given for cmd\n");
  458.                 }
  459.             } else {
  460.                 LOGE("Unrecognized script command: '%s'\n", command);
  461.                 ret_val = 1;
  462.             }
  463.         }
  464.         fclose(fp);
  465.         ui_print("Done processing script file\n");
  466.     } else {
  467.         LOGE("Error opening script file '%s'\n", SCRIPT_FILE_TMP);
  468.         return 1;
  469.     }
  470.     return ret_val;
  471. }
  472.   //end of open recovery script file code
  473.   //show Default ORS path menu
  474. static int browse_for_ors = 1; // 0 == stop browsing locations for a custom ors script
  475. void choose_default_ors_menu(const char* ors_path)
  476. {
  477.     static char* headers[] = {  "Choose a script to run",
  478.                                 "",
  479.                                 NULL
  480.     };
  481.  
  482.     char tmp[PATH_MAX];
  483.     sprintf(tmp, "%s/clockworkmod/ors/", ors_path);
  484.     char* ors_file = choose_file_menu(tmp, ".ors", headers);
  485.     if (no_files_found == 1) {
  486.         //0 valid files to select, let's continue browsing next locations
  487.         ui_print("No *.ors files in %s/clockworkmod/ors\n", ors_path);
  488.         browse_for_ors = 1;
  489.     } else {
  490.         browse_for_ors = 0; //we found ors scripts in clockworkmod/ors folder: do not proceed other locations even if no file is chosen
  491.     }
  492.     if (ors_file == NULL) {
  493.         //either no valid files found or we selected no files by pressing back menu
  494.         return;
  495.     }
  496.     static char* confirm_install  = "Confirm run script?";
  497.     static char confirm[PATH_MAX];
  498.     sprintf(confirm, "Yes - Run %s", basename(ors_file));
  499.     if (confirm_selection(confirm_install, confirm)) {
  500.         run_custom_ors(ors_file);
  501.     }
  502. }
  503.   //browse for Custom Open Recovery Script
  504. void choose_custom_ors_menu(const char* ors_path)
  505. {
  506.     if (ensure_path_mounted(ors_path) != 0) {
  507.         LOGE("Can't mount %s\n", ors_path);
  508.         return;
  509.     }
  510.  
  511.     static char* headers[] = {  "Choose .ors script to run",
  512.                                 NULL
  513.     };
  514.  
  515.     char* ors_file = choose_file_menu(ors_path, ".ors", headers);
  516.     if (ors_file == NULL)
  517.         return;
  518.     static char* confirm_install  = "Confirm run script?";
  519.     static char confirm[PATH_MAX];
  520.     sprintf(confirm, "Yes - Run %s", basename(ors_file));
  521.     if (confirm_selection(confirm_install, confirm)) {
  522.         run_custom_ors(ors_file);
  523.     }
  524. }
  525.   //show Custom Open Recovery Script menu
  526. void show_custom_ors_menu() {
  527.     static char* headers[] = {  "Search .ors script to run",
  528.                                 "",
  529.                                 NULL
  530.     };
  531.  
  532.     static char* list[] = { "Script From External sdcard",
  533.                             "Script From Internal sdcard",
  534.                              NULL
  535.     };
  536.  
  537.     for (;;) {
  538.         //header function so that "Toggle menu" doesn't reset to main menu on action selected
  539.         int chosen_item = get_filtered_menu_selection(headers, list, 0, 0, sizeof(list) / sizeof(char*));
  540.         if (chosen_item == GO_BACK)
  541.             break;
  542.         switch (chosen_item)
  543.         {
  544.             case 0:
  545.                 choose_custom_ors_menu("/sdcard/");
  546.                 break;
  547.             case 1:
  548.                 choose_custom_ors_menu("/emmc/");
  549.                 break;
  550.         }
  551.     }
  552. }
  553.   //start PhilZ Menu Toggle settings
  554. .
  555. .
  556. .
  557.  
  558.   //end PhilZ Menu Toggle settings
  559.   //start show Touch GUI Setup menu
  560. void show_touch_gui_menu()
  561. {
  562. .
  563. .
  564. .
  565. }
  566.   //start show partition backup/restore menu
  567. void show_efs_menu() {
  568.     static char* headers[] = {  "EFS/Boot Backup & Restore",
  569.                                 "",
  570.                                 NULL
  571.     };
  572.  
  573.     static char* list[] = { "Backup /boot to External",
  574.                      "Backup /efs to Internal SD",
  575.                      "Restore /efs from Internal",
  576.                      "Backup /efs to External",
  577.                      "Restore /efs from External",
  578.                      NULL
  579.     };
  580.  
  581.     for (;;) {
  582.         //header function so that "Toggle menu" doesn't reset to main menu on action selected
  583.         int chosen_item = get_filtered_menu_selection(headers, list, 0, 0, sizeof(list) / sizeof(char*));
  584.         if (chosen_item == GO_BACK)
  585.             break;
  586.         switch (chosen_item)
  587.         {
  588.             case 0:
  589.                     ensure_path_mounted("/sdcard");
  590.                     __system("kernel-backup.sh /sdcard");
  591.                     ui_print("/sdcard/clockworkmod/.kernel_bak/boot.img created\n");
  592.                     break;
  593.             case 1:
  594.                     ensure_path_mounted("/emmc");
  595.                     ensure_path_unmounted("/efs");
  596.                     __system("efs-backup.sh /emmc");
  597.                     ui_print("/emmc/clockworkmod/.efsbackup/efs.img created\n");
  598.                     break;
  599.             case 2:
  600.                     ensure_path_mounted("/emmc");
  601.                     ensure_path_unmounted("/efs");
  602.                     if (access("/emmc/clockworkmod/.efsbackup/efs.img", F_OK ) != -1) {
  603.                         if (confirm_selection("Confirm?", "Yes - Restore EFS")) {
  604.                             __system("efs-restore.sh /emmc");
  605.                             ui_print("/emmc/clockworkmod/.efsbackup/efs.img restored to /efs\n");
  606.                         }
  607.                     } else {
  608.                        ui_print("No efs.img backup found.\n");
  609.                     }
  610.                     break;
  611.             case 3:
  612.                     ensure_path_mounted("/sdcard");
  613.                     ensure_path_unmounted("/efs");
  614.                         __system("efs-backup.sh /sdcard");
  615.                     ui_print("/sdcard/clockworkmod/.efsbackup/efs.img created\n");
  616.                     break;
  617.             case 4:
  618.                     ensure_path_mounted("/sdcard");
  619.                     ensure_path_unmounted("/efs");
  620.                     if (access("/sdcard/clockworkmod/.efsbackup/efs.img", F_OK ) != -1) {
  621.                         if (confirm_selection("Confirm?", "Yes - Restore EFS")) {
  622.                             __system("efs-restore.sh /sdcard");
  623.                             ui_print("/sdcard/clockworkmod/.efsbackup/efs.img restored to /efs\n");
  624.                         }
  625.                     } else {
  626.                        ui_print("No efs.img backup found.\n");
  627.                     }
  628.                     break;
  629.         }
  630.     }
  631. }
  632.   //browse for Aroma File Manager menu
  633. void choose_aromafm_menu(const char* aromafm_path)
  634. {
  635.     if (ensure_path_mounted(aromafm_path) != 0) {
  636.         LOGE("Can't mount %s\n", aromafm_path);
  637.         return;
  638.     }
  639.  
  640.     static char* headers[] = {  "Browse for aromafm.zip",
  641.                                 NULL
  642.     };
  643.  
  644.     char* aroma_file = choose_file_menu(aromafm_path, "aromafm.zip", headers);
  645.     if (aroma_file == NULL)
  646.         return;
  647.     static char* confirm_install  = "Confirm Run Aroma?";
  648.     static char confirm[PATH_MAX];
  649.     sprintf(confirm, "Yes - Run %s", basename(aroma_file));
  650.     if (confirm_selection(confirm_install, confirm)) {
  651.         install_zip(aroma_file);
  652.     }
  653. }
  654.   //show Aroma file manager menu
  655. void show_aromafm_menu() {
  656.     static char* headers[] = {  "Browse for aromafm.zip",
  657.                                 "",
  658.                                 NULL
  659.     };
  660.  
  661.     static char* list[] = { "Search External sdcard",
  662.                             "Search Internal sdcard",
  663.                              NULL
  664.     };
  665.  
  666.     for (;;) {
  667.         //header function so that "Toggle menu" doesn't reset to main menu on action selected
  668.         int chosen_item = get_filtered_menu_selection(headers, list, 0, 0, sizeof(list) / sizeof(char*));
  669.         if (chosen_item == GO_BACK)
  670.             break;
  671.         switch (chosen_item)
  672.         {
  673.             case 0:
  674.                 choose_aromafm_menu("/sdcard/");
  675.                 break;
  676.             case 1:
  677.                 choose_aromafm_menu("/emmc/");
  678.                 break;
  679.         }
  680.     }
  681. }
  682.   //start show PhilZ Settings Menu
  683. void show_philz_settings()
  684. {
  685.     static char* headers[] = {  "PhilZ Settings",
  686.                                 NULL
  687.     };
  688.  
  689.     static char* list[] = { "Open Recovery Script",
  690.                             "EFS/Boot Backup & Restore",
  691.                             "Aroma File Manager",
  692.                             "GUI Preferences",
  693.                             "About",
  694.                              NULL
  695.     };
  696.  
  697.     for (;;) {
  698.         //header function so that "Toggle menu" doesn't reset to main menu on action selected
  699.         int chosen_item = get_filtered_menu_selection(headers, list, 0, 0, sizeof(list) / sizeof(char*));
  700.         if (chosen_item == GO_BACK)
  701.             break;
  702.         switch (chosen_item)
  703.         {
  704.             case 0:
  705.                 __system("ors-mount.sh");
  706.                 if (0 == check_for_script_file()) { //we found script from goomanager in /cache/recovery/openrecoveryscript
  707.                     if (0 != run_script_file()) //let's run it
  708.                         // run_script_file == 0 = no errors, so proceed to reboot. Else (!=0) there were errors: we do not reboot (break)
  709.                     break;
  710.                 } else { //we did not find goomanager script: let's look for custom ors
  711.                     ui_print("/cache/recovery/openrecoveryscript not found.\n");
  712.                     ui_print("Trying default ORS path...\n");
  713.                     //let's look in default custom ors locations
  714.                     ensure_path_mounted("/sdcard");
  715.                     if (access("/sdcard/clockworkmod/ors", F_OK) != -1) { //Without this check, we get 2 errors in log: "directory not found"
  716.                         //folder exists, but could be empty!
  717.                         choose_default_ors_menu("/sdcard"); //we search for .ors files in /sdcard/clockworkmod/ors
  718.                     } else {
  719.                         ui_print("/sdcard/clockworkmod/ors not found.\n");
  720.                         browse_for_ors = 1;
  721.                     }
  722.                     if (browse_for_ors == 1) {
  723.                         //browse_for_ors == 1 = we did not find any ors script in /sdcard default folder
  724.                         //let's look in /emmc/clockworkmod/ors
  725.                         ensure_path_mounted("/emmc");
  726.                         if (access("/emmc/clockworkmod/ors", F_OK) != -1) {
  727.                             //folder exists, but could be empty!
  728.                             choose_default_ors_menu("/emmc");
  729.                         } else {
  730.                             ui_print("/emmc/clockworkmod/ors not found.\n");
  731.                         }
  732.                     }
  733.                     if (browse_for_ors == 1) {
  734.                         //no files found in default locations, let's search manually for a custom ors
  735.                         ui_print("Manually search .ors file...\n");
  736.                         show_custom_ors_menu();
  737.                     }
  738.                     break; //no reboot after custom ors script install
  739.                 }
  740.                 usleep(2000000); //we reboot after goomanager successful flash
  741.                 android_reboot(ANDROID_RB_RESTART, 0, 0);
  742.                 break;
  743.             case 1:
  744.                 show_efs_menu();
  745.                 break;
  746.             case 2:
  747.                 ensure_path_mounted("/emmc");
  748.                 ensure_path_mounted("/sdcard");
  749.                 if (access("/emmc/clockworkmod/.aromafm/aromafm.zip", F_OK) != -1) {
  750.                     install_zip("/emmc/clockworkmod/.aromafm/aromafm.zip");
  751.                 } else if (access("/sdcard/clockworkmod/.aromafm/aromafm.zip", F_OK) != -1) {
  752.                     install_zip("/sdcard/clockworkmod/.aromafm/aromafm.zip");
  753.                 } else {
  754.                     ui_print("No aromafm.zip in clockworkmod/.aromafm\n");
  755.                     show_aromafm_menu();
  756.                 }
  757.                 break;
  758.             case 3:
  759.                 show_touch_gui_menu();
  760.                 break;
  761.             case 4:
  762.                 ui_print("CWM Base 6.0.1.5\n");
  763.                 ui_print("PhilZ Touch 3.00 (n7000)\n");
  764.                 ui_print("Compiled in 2012 Nov 09\n");
  765.                 break;
  766.         }
  767.     }
  768. }
  769.   //end show PhilZ Menu
  770. //end PhilZ Menu settings and functions
Advertisement
Add Comment
Please, Sign In to add comment