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> |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 18 | #include <sys/stat.h> |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 19 | |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 20 | #include <signal.h> |
| 21 | #include <sys/wait.h> |
| 22 | |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 23 | #include "bootloader.h" |
| 24 | #include "common.h" |
| 25 | #include "cutils/properties.h" |
| 26 | #include "firmware.h" |
| 27 | #include "install.h" |
| 28 | #include "minui/minui.h" |
| 29 | #include "minzip/DirUtil.h" |
| 30 | #include "roots.h" |
| 31 | #include "recovery_ui.h" |
| 32 | |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 33 | #include "commands.h" |
| 34 | #include "amend/amend.h" |
| 35 | |
Koushik K. Dutta | a85d7cc | 2010-03-12 17:00:58 -0800 | [diff] [blame] | 36 | #include "mtdutils/dump_image.h" |
| 37 | #include "../../external/yaffs2/yaffs2/utils/mkyaffs2image.h" |
Koushik K. Dutta | 54305a8 | 2010-03-12 17:43:26 -0800 | [diff] [blame] | 38 | #include "../../external/yaffs2/yaffs2/utils/unyaffs.h" |
Koushik K. Dutta | a85d7cc | 2010-03-12 17:00:58 -0800 | [diff] [blame] | 39 | |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 40 | #include "extendedcommands.h" |
| 41 | #include "nandroid.h" |
| 42 | |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 43 | int signature_check_enabled = 1; |
| 44 | int script_assert_enabled = 1; |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 45 | static const char *SDCARD_PACKAGE_FILE = "SDCARD:update.zip"; |
Koushik K. Dutta | 6060e5c | 2010-02-11 22:27:06 -0800 | [diff] [blame] | 46 | |
| 47 | void |
| 48 | toggle_signature_check() |
| 49 | { |
| 50 | signature_check_enabled = !signature_check_enabled; |
| 51 | ui_print("Signature Check: %s\n", signature_check_enabled ? "Enabled" : "Disabled"); |
| 52 | } |
| 53 | |
| 54 | void toggle_script_asserts() |
| 55 | { |
| 56 | script_assert_enabled = !script_assert_enabled; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 57 | ui_print("Script Asserts: %s\n", script_assert_enabled ? "Enabled" : "Disabled"); |
| 58 | } |
| 59 | |
Koushik K. Dutta | ea46fe2 | 2010-03-08 02:58:04 -0800 | [diff] [blame] | 60 | int install_zip(const char* packagefilepath) |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 61 | { |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 62 | ui_print("\n-- Installing: %s\n", packagefilepath); |
| 63 | set_sdcard_update_bootloader_message(); |
| 64 | int status = install_package(packagefilepath); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 65 | ui_reset_progress(); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 66 | if (status != INSTALL_SUCCESS) { |
| 67 | ui_set_background(BACKGROUND_ICON_ERROR); |
| 68 | ui_print("Installation aborted.\n"); |
Koushik K. Dutta | ea46fe2 | 2010-03-08 02:58:04 -0800 | [diff] [blame] | 69 | return 1; |
Koushik K. Dutta | 79ce82c | 2010-02-25 12:03:17 -0800 | [diff] [blame] | 70 | } |
| 71 | if (firmware_update_pending()) { |
| 72 | ui_print("\nReboot via menu to complete\ninstallation.\n"); |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 73 | } |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 74 | ui_set_background(BACKGROUND_ICON_NONE); |
Koushik K. Dutta | 99fb6fe | 2010-03-03 00:42:58 -0800 | [diff] [blame] | 75 | ui_print("\nInstall from sdcard complete.\n"); |
Koushik K. Dutta | ea46fe2 | 2010-03-08 02:58:04 -0800 | [diff] [blame] | 76 | return 0; |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | char* INSTALL_MENU_ITEMS[] = { "apply sdcard:update.zip", |
| 80 | "choose zip from sdcard", |
| 81 | "toggle signature verification", |
| 82 | "toggle script asserts", |
| 83 | NULL }; |
| 84 | #define ITEM_APPLY_SDCARD 0 |
| 85 | #define ITEM_CHOOSE_ZIP 1 |
| 86 | #define ITEM_SIG_CHECK 2 |
| 87 | #define ITEM_ASSERTS 3 |
| 88 | |
| 89 | void show_install_update_menu() |
| 90 | { |
| 91 | static char* headers[] = { "Apply update from .zip file on SD card", |
| 92 | "", |
| 93 | NULL |
| 94 | }; |
| 95 | for (;;) |
| 96 | { |
| 97 | int chosen_item = get_menu_selection(headers, INSTALL_MENU_ITEMS, 0); |
| 98 | switch (chosen_item) |
| 99 | { |
| 100 | case ITEM_ASSERTS: |
| 101 | toggle_script_asserts(); |
| 102 | break; |
| 103 | case ITEM_SIG_CHECK: |
| 104 | toggle_signature_check(); |
| 105 | break; |
| 106 | case ITEM_APPLY_SDCARD: |
| 107 | install_zip(SDCARD_PACKAGE_FILE); |
| 108 | break; |
| 109 | case ITEM_CHOOSE_ZIP: |
| 110 | show_choose_zip_menu(); |
| 111 | break; |
| 112 | default: |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | } |
| 117 | } |
| 118 | |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 119 | void free_string_array(char** array) |
| 120 | { |
| 121 | if (array == NULL) |
| 122 | return; |
| 123 | char* cursor = array[0]; |
| 124 | int i = 0; |
| 125 | while (cursor != NULL) |
| 126 | { |
| 127 | free(cursor); |
| 128 | cursor = array[++i]; |
| 129 | } |
| 130 | free(array); |
| 131 | } |
| 132 | |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 133 | char** gather_files(const char* directory, const char* fileExtensionOrDirectory, int* numFiles) |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 134 | { |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 135 | char path[PATH_MAX] = ""; |
| 136 | DIR *dir; |
| 137 | struct dirent *de; |
| 138 | int total = 0; |
| 139 | int i; |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 140 | char** files = NULL; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 141 | int pass; |
| 142 | *numFiles = 0; |
| 143 | int dirLen = strlen(directory); |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 144 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 145 | dir = opendir(directory); |
| 146 | if (dir == NULL) { |
| 147 | ui_print("Couldn't open directory.\n"); |
| 148 | return NULL; |
| 149 | } |
| 150 | |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 151 | int extension_length = 0; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 152 | if (fileExtensionOrDirectory != NULL) |
| 153 | extension_length = strlen(fileExtensionOrDirectory); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 154 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 155 | int isCounting = 1; |
| 156 | i = 0; |
| 157 | for (pass = 0; pass < 2; pass++) { |
| 158 | while ((de=readdir(dir)) != NULL) { |
| 159 | // skip hidden files |
| 160 | if (de->d_name[0] == '.') |
| 161 | continue; |
| 162 | |
| 163 | // NULL means that we are gathering directories, so skip this |
| 164 | if (fileExtensionOrDirectory != NULL) |
| 165 | { |
| 166 | // make sure that we can have the desired extension (prevent seg fault) |
| 167 | if (strlen(de->d_name) < extension_length) |
| 168 | continue; |
| 169 | // compare the extension |
| 170 | if (strcmp(de->d_name + strlen(de->d_name) - extension_length, fileExtensionOrDirectory) != 0) |
| 171 | continue; |
| 172 | } |
| 173 | else |
| 174 | { |
| 175 | struct stat info; |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 176 | char fullFileName[PATH_MAX]; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 177 | strcpy(fullFileName, directory); |
| 178 | strcat(fullFileName, de->d_name); |
| 179 | stat(fullFileName, &info); |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 180 | // make sure it is a directory |
| 181 | if (!(S_ISDIR(info.st_mode))) |
| 182 | continue; |
| 183 | } |
| 184 | |
| 185 | if (pass == 0) |
| 186 | { |
| 187 | total++; |
| 188 | continue; |
| 189 | } |
| 190 | |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 191 | files[i] = (char*) malloc(dirLen + strlen(de->d_name) + 2); |
| 192 | strcpy(files[i], directory); |
| 193 | strcat(files[i], de->d_name); |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 194 | if (fileExtensionOrDirectory == NULL) |
| 195 | strcat(files[i], "/"); |
| 196 | i++; |
| 197 | } |
| 198 | if (pass == 1) |
| 199 | break; |
| 200 | if (total == 0) |
| 201 | break; |
| 202 | rewinddir(dir); |
| 203 | *numFiles = total; |
| 204 | files = (char**) malloc((total+1)*sizeof(char*)); |
| 205 | files[total]=NULL; |
| 206 | } |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 207 | |
| 208 | if(closedir(dir) < 0) { |
| 209 | LOGE("Failed to close directory."); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | if (total==0) { |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 213 | return NULL; |
| 214 | } |
| 215 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 216 | return files; |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 217 | } |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 218 | |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 219 | // pass in NULL for fileExtensionOrDirectory and you will get a directory chooser |
| 220 | char* choose_file_menu(const char* directory, const char* fileExtensionOrDirectory, const char* headers[]) |
| 221 | { |
| 222 | char path[PATH_MAX] = ""; |
| 223 | DIR *dir; |
| 224 | struct dirent *de; |
| 225 | int numFiles = 0; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 226 | int numDirs = 0; |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 227 | int i; |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 228 | char* return_value = NULL; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 229 | int dir_len = strlen(directory); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 230 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 231 | char** files = gather_files(directory, fileExtensionOrDirectory, &numFiles); |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 232 | char** dirs = NULL; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 233 | if (fileExtensionOrDirectory != NULL) |
| 234 | dirs = gather_files(directory, NULL, &numDirs); |
| 235 | int total = numDirs + numFiles; |
| 236 | if (total == 0) |
| 237 | { |
| 238 | ui_print("No files found.\n"); |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 239 | } |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 240 | else |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 241 | { |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 242 | char** list = (char**) malloc((total + 1) * sizeof(char*)); |
| 243 | list[total] = NULL; |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 244 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 245 | |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 246 | for (i = 0 ; i < numDirs; i++) |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 247 | { |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 248 | list[i] = strdup(dirs[i] + dir_len); |
| 249 | } |
| 250 | |
| 251 | for (i = 0 ; i < numFiles; i++) |
| 252 | { |
| 253 | list[numDirs + i] = strdup(files[i] + dir_len); |
| 254 | } |
| 255 | |
| 256 | for (;;) |
| 257 | { |
| 258 | int chosen_item = get_menu_selection(headers, list, 0); |
| 259 | if (chosen_item == GO_BACK) |
| 260 | break; |
| 261 | static char ret[PATH_MAX]; |
| 262 | if (chosen_item < numDirs) |
| 263 | { |
| 264 | char* subret = choose_file_menu(dirs[chosen_item], fileExtensionOrDirectory, headers); |
| 265 | if (subret != NULL) |
| 266 | { |
| 267 | strcpy(ret, subret); |
| 268 | return_value = ret; |
| 269 | break; |
| 270 | } |
| 271 | continue; |
| 272 | } |
| 273 | strcpy(ret, files[chosen_item - numDirs]); |
| 274 | return_value = ret; |
| 275 | break; |
| 276 | } |
| 277 | free_string_array(list); |
Koushik K. Dutta | 981b0cd | 2010-02-22 08:53:34 -0800 | [diff] [blame] | 278 | } |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 279 | |
| 280 | free_string_array(files); |
| 281 | free_string_array(dirs); |
| 282 | return return_value; |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void show_choose_zip_menu() |
| 286 | { |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 287 | if (ensure_root_path_mounted("SDCARD:") != 0) { |
| 288 | LOGE ("Can't mount /sdcard\n"); |
| 289 | return; |
| 290 | } |
| 291 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 292 | static char* headers[] = { "Choose a zip to apply", |
| 293 | "", |
| 294 | NULL |
| 295 | }; |
| 296 | |
| 297 | char* file = choose_file_menu("/sdcard/", ".zip", headers); |
| 298 | if (file == NULL) |
| 299 | return; |
| 300 | char sdcard_package_file[1024]; |
| 301 | strcpy(sdcard_package_file, "SDCARD:"); |
| 302 | strcat(sdcard_package_file, file + strlen("/sdcard/")); |
| 303 | install_zip(sdcard_package_file); |
| 304 | } |
| 305 | |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 306 | // This was pulled from bionic: The default system command always looks |
| 307 | // for shell in /system/bin/sh. This is bad. |
| 308 | #define _PATH_BSHELL "/sbin/sh" |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 309 | |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 310 | extern char **environ; |
| 311 | int |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 312 | __system(const char *command) |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 313 | { |
| 314 | pid_t pid; |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 315 | sig_t intsave, quitsave; |
| 316 | sigset_t mask, omask; |
| 317 | int pstat; |
| 318 | char *argp[] = {"sh", "-c", NULL, NULL}; |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 319 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 320 | if (!command) /* just checking... */ |
| 321 | return(1); |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 322 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 323 | argp[2] = (char *)command; |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 324 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 325 | sigemptyset(&mask); |
| 326 | sigaddset(&mask, SIGCHLD); |
| 327 | sigprocmask(SIG_BLOCK, &mask, &omask); |
| 328 | switch (pid = vfork()) { |
| 329 | case -1: /* error */ |
| 330 | sigprocmask(SIG_SETMASK, &omask, NULL); |
| 331 | return(-1); |
| 332 | case 0: /* child */ |
| 333 | sigprocmask(SIG_SETMASK, &omask, NULL); |
| 334 | execve(_PATH_BSHELL, argp, environ); |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 335 | _exit(127); |
| 336 | } |
| 337 | |
Koushik K. Dutta | 001c5b5 | 2010-02-25 14:53:57 -0800 | [diff] [blame] | 338 | intsave = (sig_t) bsd_signal(SIGINT, SIG_IGN); |
| 339 | quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN); |
| 340 | pid = waitpid(pid, (int *)&pstat, 0); |
| 341 | sigprocmask(SIG_SETMASK, &omask, NULL); |
| 342 | (void)bsd_signal(SIGINT, intsave); |
| 343 | (void)bsd_signal(SIGQUIT, quitsave); |
| 344 | return (pid == -1 ? -1 : pstat); |
Koushik K. Dutta | 33370db | 2010-02-25 11:39:07 -0800 | [diff] [blame] | 345 | } |
| 346 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 347 | void show_nandroid_restore_menu() |
| 348 | { |
Koushik K. Dutta | 54305a8 | 2010-03-12 17:43:26 -0800 | [diff] [blame] | 349 | if (ensure_root_path_mounted("SDCARD:") != 0) { |
| 350 | LOGE ("Can't mount /sdcard\n"); |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 351 | return; |
Koushik K. Dutta | 54305a8 | 2010-03-12 17:43:26 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 354 | static char* headers[] = { "Choose an image to restore", |
| 355 | "", |
| 356 | NULL |
| 357 | }; |
Koushik K. Dutta | e923487 | 2010-02-12 00:43:24 -0800 | [diff] [blame] | 358 | |
Koushik K. Dutta | 49f5689 | 2010-02-25 14:51:05 -0800 | [diff] [blame] | 359 | char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers); |
Koushik K. Dutta | bcdd003 | 2010-02-21 21:10:25 -0800 | [diff] [blame] | 360 | if (file == NULL) |
| 361 | return; |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 362 | nandroid_restore(file, 1, 1, 1, 1, 1); |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 363 | } |
| 364 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 365 | void show_mount_usb_storage_menu() |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 366 | { |
Koushik K. Dutta | f721594 | 2010-03-16 13:34:51 -0700 | [diff] [blame] | 367 | __system("echo /dev/block/mmcblk0 > /sys/devices/platform/usb_mass_storage/lun0/file"); |
Koushik K. Dutta | 0317378 | 2010-02-26 14:14:23 -0800 | [diff] [blame] | 368 | static char* headers[] = { "USB Mass Storage device", |
| 369 | "Leaving this menu unmount", |
| 370 | "your SD card from your PC.", |
| 371 | "", |
| 372 | NULL |
| 373 | }; |
| 374 | |
| 375 | static char* list[] = { "Unmount", NULL }; |
| 376 | |
| 377 | for (;;) |
| 378 | { |
| 379 | int chosen_item = get_menu_selection(headers, list, 0); |
| 380 | if (chosen_item == GO_BACK || chosen_item == 0) |
| 381 | break; |
| 382 | } |
| 383 | |
Koushik K. Dutta | f721594 | 2010-03-16 13:34:51 -0700 | [diff] [blame] | 384 | __system("echo '' > /sys/devices/platform/usb_mass_storage/lun0/file"); |
| 385 | __system("echo 0 > /sys/devices/platform/usb_mass_storage/lun0/enable"); |
Koushik K. Dutta | e81cb75 | 2010-02-26 17:44:33 -0800 | [diff] [blame] | 386 | } |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 387 | |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 388 | int confirm_format() |
| 389 | { |
| 390 | static char* title_headers[] = { "Confirm format?", |
| 391 | " THIS CAN NOT BE UNDONE.", |
| 392 | "", |
| 393 | NULL, |
| 394 | }; |
| 395 | |
| 396 | char* items[] = { " No", |
| 397 | " No", |
| 398 | " No", |
| 399 | " No", |
| 400 | " No", |
| 401 | " No", |
| 402 | " No", |
| 403 | " Yes -- wipe partition", // [7] |
| 404 | " No", |
| 405 | " No", |
| 406 | " No", |
| 407 | NULL }; |
| 408 | |
| 409 | int chosen_item = get_menu_selection(title_headers, items, 0); |
| 410 | return chosen_item == 7; |
| 411 | } |
| 412 | |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 413 | int format_mmc_device(char* root) |
| 414 | { |
| 415 | char path[PATH_MAX]; |
| 416 | translate_root_path(root, path, PATH_MAX); |
| 417 | if (0 != ensure_root_path_mounted(root)) |
| 418 | { |
| 419 | ui_print("Error mounting %s!\n", path); |
| 420 | return 1; |
| 421 | } |
| 422 | |
| 423 | static char tmp[PATH_MAX]; |
| 424 | sprintf(tmp, "rm -rf %s/*", path); |
| 425 | __system(tmp); |
| 426 | sprintf(tmp, "rm -rf %s/.*", path); |
| 427 | __system(tmp); |
| 428 | |
| 429 | ensure_root_path_unmounted(root); |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | #define MOUNTABLE_COUNT 5 |
| 434 | #define MTD_COUNT 4 |
| 435 | #define MMC_COUNT 2 |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 436 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 437 | void show_partition_menu() |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 438 | { |
| 439 | static char* headers[] = { "Mount and unmount partitions", |
| 440 | "", |
| 441 | NULL |
| 442 | }; |
| 443 | |
| 444 | typedef char* string; |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 445 | string mounts[MOUNTABLE_COUNT][3] = { |
| 446 | { "mount /system", "unmount /system", "SYSTEM:" }, |
| 447 | { "mount /data", "unmount /data", "DATA:" }, |
| 448 | { "mount /cache", "unmount /cache", "CACHE:" }, |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 449 | { "mount /sdcard", "unmount /sdcard", "SDCARD:" }, |
| 450 | { "mount /sd-ext", "unmount /sd-ext", "SDEXT:" } |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 451 | }; |
| 452 | |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 453 | string mtds[MTD_COUNT][2] = { |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 454 | { "format boot", "BOOT:" }, |
| 455 | { "format system", "SYSTEM:" }, |
| 456 | { "format data", "DATA:" }, |
| 457 | { "format cache", "CACHE:" }, |
| 458 | }; |
| 459 | |
| 460 | string mmcs[MMC_COUNT][3] = { |
| 461 | { "format sdcard", "SDCARD:" }, |
| 462 | { "format sd-ext", "SDEXT: " } |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 463 | }; |
| 464 | |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 465 | for (;;) |
| 466 | { |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 467 | int ismounted[MOUNTABLE_COUNT]; |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 468 | int i; |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 469 | static string options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT + 1 + 1]; // mountables, format mtds, format mmcs, usb storage, null |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 470 | for (i = 0; i < MOUNTABLE_COUNT; i++) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 471 | { |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 472 | ismounted[i] = is_root_path_mounted(mounts[i][2]); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 473 | options[i] = ismounted[i] ? mounts[i][1] : mounts[i][0]; |
| 474 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 475 | |
| 476 | for (i = 0; i < MTD_COUNT; i++) |
| 477 | { |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 478 | options[MOUNTABLE_COUNT + i] = mtds[i][0]; |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 479 | } |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 480 | |
| 481 | for (i = 0; i < MMC_COUNT; i++) |
| 482 | { |
| 483 | options[MOUNTABLE_COUNT + MTD_COUNT + i] = mmcs[i][0]; |
| 484 | } |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 485 | |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 486 | options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT] = "mount USB storage"; |
| 487 | options[MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT + 1] = NULL; |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 488 | |
| 489 | int chosen_item = get_menu_selection(headers, options, 0); |
| 490 | if (chosen_item == GO_BACK) |
| 491 | break; |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 492 | if (chosen_item == MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 493 | { |
| 494 | show_mount_usb_storage_menu(); |
| 495 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 496 | else if (chosen_item < MOUNTABLE_COUNT) |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 497 | { |
| 498 | if (ismounted[chosen_item]) |
| 499 | { |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 500 | if (0 != ensure_root_path_unmounted(mounts[chosen_item][2])) |
| 501 | ui_print("Error unmounting %s!\n", mounts[chosen_item][2]); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 502 | } |
| 503 | else |
| 504 | { |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 505 | if (0 != ensure_root_path_mounted(mounts[chosen_item][2])) |
| 506 | ui_print("Error mounting %s!\n", mounts[chosen_item][2]); |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 507 | } |
| 508 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 509 | else if (chosen_item < MOUNTABLE_COUNT + MTD_COUNT) |
| 510 | { |
| 511 | chosen_item = chosen_item - MOUNTABLE_COUNT; |
Koushik K. Dutta | 16f0b49 | 2010-03-19 14:37:11 -0700 | [diff] [blame] | 512 | if (!confirm_format()) |
| 513 | continue; |
| 514 | ui_print("Formatting %s...\n", mtds[chosen_item][1]); |
Koushik K. Dutta | 3f99539 | 2010-03-30 23:29:43 -0700 | [diff] [blame] | 515 | if (0 != format_root_device(mtds[chosen_item][1])) |
| 516 | ui_print("Error formatting %s!\n", mtds[chosen_item][1]); |
| 517 | else |
| 518 | ui_print("Done.\n"); |
| 519 | } |
| 520 | else if (chosen_item < MOUNTABLE_COUNT + MTD_COUNT + MMC_COUNT) |
| 521 | { |
| 522 | chosen_item = chosen_item - MOUNTABLE_COUNT - MTD_COUNT; |
| 523 | if (!confirm_format()) |
| 524 | continue; |
| 525 | ui_print("Formatting %s...\n", mmcs[chosen_item][1]); |
| 526 | if (0 != format_mmc_device(mmcs[chosen_item][1])) |
| 527 | ui_print("Error formatting %s!\n", mmcs[chosen_item][1]); |
| 528 | else |
| 529 | ui_print("Done.\n"); |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 530 | } |
Koushik K. Dutta | b9546a8 | 2010-03-14 22:42:30 -0700 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 534 | #define EXTENDEDCOMMAND_SCRIPT "/cache/recovery/extendedcommand" |
| 535 | |
| 536 | int extendedcommand_file_exists() |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 537 | { |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 538 | struct stat file_info; |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 539 | return 0 == stat(EXTENDEDCOMMAND_SCRIPT, &file_info); |
| 540 | } |
| 541 | |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 542 | int run_script_from_buffer(char* script_data, int script_len, char* filename) |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 543 | { |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 544 | /* Parse the script. Note that the script and parse tree are never freed. |
| 545 | */ |
| 546 | const AmCommandList *commands = parseAmendScript(script_data, script_len); |
| 547 | if (commands == NULL) { |
| 548 | printf("Syntax error in update script\n"); |
| 549 | return 1; |
| 550 | } else { |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 551 | printf("Parsed %.*s\n", script_len, filename); |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* Execute the script. |
| 555 | */ |
| 556 | int ret = execCommandList((ExecContext *)1, commands); |
| 557 | if (ret != 0) { |
| 558 | int num = ret; |
Koushik K. Dutta | ee57bbc | 2010-03-12 23:21:12 -0800 | [diff] [blame] | 559 | char *line = NULL, *next = script_data; |
Koushik K. Dutta | f68aaaf | 2010-03-07 13:39:21 -0800 | [diff] [blame] | 560 | while (next != NULL && ret-- > 0) { |
| 561 | line = next; |
| 562 | next = memchr(line, '\n', script_data + script_len - line); |
| 563 | if (next != NULL) *next++ = '\0'; |
| 564 | } |
| 565 | printf("Failure at line %d:\n%s\n", num, next ? line : "(not found)"); |
| 566 | return 1; |
| 567 | } |
| 568 | |
| 569 | return 0; |
| 570 | } |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 571 | |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame^] | 572 | int run_script(char* filename) |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 573 | { |
| 574 | struct stat file_info; |
| 575 | if (0 != stat(filename, &file_info)) { |
| 576 | printf("Error executing stat on file: %s\n", filename); |
| 577 | return 1; |
| 578 | } |
| 579 | |
| 580 | int script_len = file_info.st_size; |
Koushik K. Dutta | 707fa6d | 2010-03-23 11:44:33 -0700 | [diff] [blame] | 581 | char* script_data = (char*)malloc(script_len + 1); |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 582 | FILE *file = fopen(filename, "rb"); |
| 583 | fread(script_data, script_len, 1, file); |
Koushik K. Dutta | 707fa6d | 2010-03-23 11:44:33 -0700 | [diff] [blame] | 584 | // supposedly not necessary, but let's be safe. |
| 585 | script_data[script_len] = '\0'; |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 586 | fclose(file); |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 587 | |
Koushik K. Dutta | 1d53c4e | 2010-04-02 16:46:21 -0700 | [diff] [blame] | 588 | int ret = run_script_from_buffer(script_data, script_len, filename); |
| 589 | free(script_data); |
| 590 | return ret; |
Koushik K. Dutta | 3836f72 | 2010-03-11 22:17:43 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 593 | int run_and_remove_extendedcommand() |
| 594 | { |
Koushik K. Dutta | da3a582 | 2010-03-23 15:11:16 -0700 | [diff] [blame] | 595 | __system("touch /tmp/.installscript"); |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame^] | 596 | char tmp[PATH_MAX]; |
| 597 | sprintf(tmp, "cp %s /tmp/%s", EXTENDEDCOMMAND_SCRIPT, basename(EXTENDEDCOMMAND_SCRIPT)); |
| 598 | __system(tmp); |
| 599 | remove(EXTENDEDCOMMAND_SCRIPT); |
Koushik K. Dutta | 3a25cf5 | 2010-03-08 19:22:41 -0800 | [diff] [blame] | 600 | int i = 0; |
| 601 | for (i = 20; i > 0; i--) { |
| 602 | ui_print("Waiting for SD Card to mount (%ds)\n", i); |
| 603 | if (ensure_root_path_mounted("SDCARD:") == 0) { |
| 604 | ui_print("SD Card mounted...\n"); |
| 605 | break; |
| 606 | } |
| 607 | sleep(1); |
| 608 | } |
| 609 | if (i == 0) { |
| 610 | ui_print("Timed out waiting for SD card... continuing anyways."); |
| 611 | } |
| 612 | |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame^] | 613 | sprintf(tmp, "/tmp/%s", basename(EXTENDEDCOMMAND_SCRIPT)); |
| 614 | return run_script(tmp); |
Koushik K. Dutta | 72a1db6 | 2010-03-07 14:10:26 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | int amend_main(int argc, char** argv) |
| 618 | { |
| 619 | if (argc != 2) |
| 620 | { |
| 621 | printf("Usage: amend <script>\n"); |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | RecoveryCommandContext ctx = { NULL }; |
| 626 | if (register_update_commands(&ctx)) { |
| 627 | LOGE("Can't install update commands\n"); |
| 628 | } |
Koushik K. Dutta | 6771aca | 2010-04-03 23:28:39 -0700 | [diff] [blame^] | 629 | return run_script(argv[1]); |
Koushik K. Dutta | 5306db5 | 2010-03-08 14:09:35 -0800 | [diff] [blame] | 630 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 631 | |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 632 | void show_nandroid_advanced_restore_menu() |
| 633 | { |
| 634 | if (ensure_root_path_mounted("SDCARD:") != 0) { |
| 635 | LOGE ("Can't mount /sdcard\n"); |
| 636 | return; |
| 637 | } |
| 638 | |
| 639 | static char* advancedheaders[] = { "Choose an image to restore", |
| 640 | "", |
| 641 | "Choose an image to restore", |
| 642 | "first. The next menu will", |
| 643 | "you more options.", |
| 644 | "", |
| 645 | NULL |
| 646 | }; |
| 647 | |
| 648 | char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, advancedheaders); |
| 649 | if (file == NULL) |
| 650 | return; |
| 651 | |
| 652 | static char* headers[] = { "Nandroid Advanced Restore", |
| 653 | "", |
| 654 | NULL |
| 655 | }; |
| 656 | |
| 657 | static char* list[] = { "Restore boot", |
| 658 | "Restore system", |
| 659 | "Restore data", |
| 660 | "Restore cache", |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 661 | "Restore sd-ext", |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 662 | NULL |
| 663 | }; |
| 664 | |
| 665 | int chosen_item = get_menu_selection(headers, list, 0); |
| 666 | switch (chosen_item) |
| 667 | { |
| 668 | case 0: |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 669 | nandroid_restore(file, 1, 0, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 670 | break; |
| 671 | case 1: |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 672 | nandroid_restore(file, 0, 1, 0, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 673 | break; |
| 674 | case 2: |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 675 | nandroid_restore(file, 0, 0, 1, 0, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 676 | break; |
| 677 | case 3: |
Koushik K. Dutta | 68b0190 | 2010-04-01 12:20:39 -0700 | [diff] [blame] | 678 | nandroid_restore(file, 0, 0, 0, 1, 0); |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 679 | break; |
| 680 | } |
| 681 | } |
| 682 | |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 683 | void show_nandroid_menu() |
| 684 | { |
| 685 | static char* headers[] = { "Nandroid", |
| 686 | "", |
| 687 | NULL |
| 688 | }; |
| 689 | |
| 690 | static char* list[] = { "Backup", |
| 691 | "Restore", |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 692 | "Advanced Restore", |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 693 | NULL |
| 694 | }; |
| 695 | |
| 696 | int chosen_item = get_menu_selection(headers, list, 0); |
| 697 | switch (chosen_item) |
| 698 | { |
| 699 | case 0: |
| 700 | { |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 701 | char backup_path[PATH_MAX]; |
Koushik K. Dutta | 6a26e7c | 2010-03-27 15:26:11 -0700 | [diff] [blame] | 702 | time_t t = time(NULL); |
| 703 | struct tm *tmp = localtime(&t); |
| 704 | if (tmp == NULL) |
| 705 | { |
| 706 | struct timeval tp; |
| 707 | gettimeofday(&tp, NULL); |
| 708 | sprintf(backup_path, "/sdcard/clockworkmod/backup/%d", tp.tv_sec); |
| 709 | } |
| 710 | else |
| 711 | { |
| 712 | strftime(backup_path, sizeof(backup_path), "/sdcard/clockworkmod/backup/%F.%H.%M.%S", tmp); |
| 713 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 714 | nandroid_backup(backup_path); |
| 715 | } |
| 716 | break; |
| 717 | case 1: |
| 718 | show_nandroid_restore_menu(); |
| 719 | break; |
Koushik K. Dutta | fe84a7f | 2010-03-25 18:19:23 -0700 | [diff] [blame] | 720 | case 2: |
| 721 | show_nandroid_advanced_restore_menu(); |
| 722 | break; |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 723 | } |
Koushik K. Dutta | a496b51 | 2010-03-19 14:51:45 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | void show_advanced_menu() |
| 727 | { |
| 728 | static char* headers[] = { "Advanced and Debugging Menu", |
| 729 | "", |
| 730 | NULL |
| 731 | }; |
| 732 | |
| 733 | static char* list[] = { "Key Test", |
| 734 | NULL |
| 735 | }; |
| 736 | |
| 737 | for (;;) |
| 738 | { |
| 739 | int chosen_item = get_menu_selection(headers, list, 0); |
| 740 | if (chosen_item == GO_BACK) |
| 741 | break; |
| 742 | switch (chosen_item) |
| 743 | { |
| 744 | case 0: |
| 745 | { |
| 746 | ui_print("Outputting key codes.\n"); |
| 747 | ui_print("Go back to end debugging.\n"); |
| 748 | int key; |
| 749 | int action; |
| 750 | do |
| 751 | { |
| 752 | key = ui_wait_key(); |
| 753 | action = device_handle_key(key, 1); |
| 754 | ui_print("Key: %d\n", key); |
| 755 | } |
| 756 | while (action != GO_BACK); |
| 757 | } |
| 758 | } |
| 759 | } |
Koushik K. Dutta | 5899ac9 | 2010-03-19 13:34:36 -0700 | [diff] [blame] | 760 | } |