Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 1 | #include <ctype.h> |
| 2 | #include <errno.h> |
| 3 | #include <fcntl.h> |
| 4 | #include <getopt.h> |
| 5 | #include <limits.h> |
| 6 | #include <linux/input.h> |
| 7 | #include <stdio.h> |
| 8 | #include <stdlib.h> |
| 9 | #include <string.h> |
| 10 | #include <sys/reboot.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <time.h> |
| 13 | #include <unistd.h> |
| 14 | |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 15 | #include <sys/wait.h> |
| 16 | #include <sys/limits.h> |
| 17 | #include <dirent.h> |
| 18 | |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 19 | #include "bootloader.h" |
| 20 | #include "common.h" |
| 21 | #include "cutils/properties.h" |
| 22 | #include "firmware.h" |
| 23 | #include "install.h" |
| 24 | #include "minui/minui.h" |
| 25 | #include "minzip/DirUtil.h" |
| 26 | #include "roots.h" |
| 27 | #include "recovery_ui.h" |
| 28 | |
| 29 | int signature_check_enabled = 1; |
| 30 | int script_assert_enabled = 1; |
| 31 | |
| 32 | void |
| 33 | toggle_signature_check() |
| 34 | { |
| 35 | signature_check_enabled = !signature_check_enabled; |
| 36 | ui_print("Signature Check: %s\n", signature_check_enabled ? "Enabled" : "Disabled"); |
| 37 | } |
| 38 | |
| 39 | void toggle_script_asserts() |
| 40 | { |
| 41 | script_assert_enabled = !script_assert_enabled; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 42 | ui_print("Script Asserts: %s\n", script_assert_enabled ? "Enabled" : "Disabled"); |
| 43 | } |
| 44 | |
| 45 | void show_choose_zip_menu() |
| 46 | { |
| 47 | static char* headers[] = { "Choose a zip or press POWER to return", |
| 48 | "", |
| 49 | NULL }; |
| 50 | |
| 51 | char path[PATH_MAX] = ""; |
| 52 | DIR *dir; |
| 53 | struct dirent *de; |
| 54 | int total = 0; |
| 55 | int i; |
| 56 | char** files; |
| 57 | char** list; |
| 58 | |
| 59 | if (ensure_root_path_mounted("SDCARD:") != 0) { |
| 60 | LOGE ("Can't mount /sdcard\n"); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | dir = opendir("/sdcard"); |
| 65 | if (dir == NULL) { |
| 66 | LOGE("Couldn't open /sdcard"); |
| 67 | return; |
| 68 | } |
| 69 | |
| 70 | const char *extension = ".zip"; |
| 71 | const int extension_length = strlen(extension); |
| 72 | |
| 73 | while ((de=readdir(dir)) != NULL) { |
| 74 | if (de->d_name[0] != '.' && strlen(de->d_name) > extension_length && strcmp(de->d_name + strlen(de->d_name) - extension_length, extension) == 0) { |
| 75 | total++; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | if (total==0) { |
| 80 | LOGE("No tar archives found\n"); |
| 81 | if(closedir(dir) < 0) { |
| 82 | LOGE("Failed to close directory /sdcard"); |
| 83 | return; |
| 84 | } |
| 85 | } |
| 86 | else { |
| 87 | files = (char**) malloc((total+1)*sizeof(char*)); |
| 88 | files[total]=NULL; |
| 89 | |
| 90 | list = (char**) malloc((total+1)*sizeof(char*)); |
| 91 | list[total]=NULL; |
| 92 | |
| 93 | rewinddir(dir); |
| 94 | |
| 95 | i = 0; |
| 96 | while ((de = readdir(dir)) != NULL) { |
| 97 | if (de->d_name[0] != '.' && strlen(de->d_name) > extension_length && strcmp(de->d_name + strlen(de->d_name) - extension_length, extension) == 0) { |
| 98 | files[i] = (char*) malloc(strlen("/sdcard/")+strlen(de->d_name)+1); |
| 99 | strcpy(files[i], "/sdcard/"); |
| 100 | strcat(files[i], de->d_name); |
| 101 | |
| 102 | list[i] = (char*) malloc(strlen(de->d_name)+1); |
| 103 | strcpy(list[i], de->d_name); |
| 104 | |
| 105 | i++; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | if (closedir(dir) <0) { |
| 110 | LOGE("Failure closing directory /sdcard\n"); |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | int chosen_item = get_menu_selection(headers, list, 1); |
| 115 | if (chosen_item >= 0 && chosen_item != GO_BACK) { |
| 116 | char sdcard_package_file[1024]; |
| 117 | strcpy(sdcard_package_file, "SDCARD:"); |
| 118 | strcat(sdcard_package_file, files[chosen_item] + strlen("/sdcard")); |
| 119 | |
| 120 | ui_print("\n-- Install from sdcard...\n"); |
| 121 | set_sdcard_update_bootloader_message(); |
| 122 | int status = install_package(sdcard_package_file); |
| 123 | if (status != INSTALL_SUCCESS) { |
| 124 | ui_set_background(BACKGROUND_ICON_ERROR); |
| 125 | ui_print("Installation aborted.\n"); |
| 126 | } else if (!ui_text_visible()) { |
| 127 | return; // reboot if logs aren't visible |
| 128 | } else { |
| 129 | if (firmware_update_pending()) { |
| 130 | ui_print("\nReboot via menu to complete\n" |
| 131 | "installation.\n"); |
| 132 | } else { |
| 133 | ui_print("\nInstall from sdcard complete.\n"); |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 138 | } |