From fe84a7ff840badae0e1907c7258b28b77478940f Mon Sep 17 00:00:00 2001 From: "Koushik K. Dutta" Date: Thu, 25 Mar 2010 18:19:23 -0700 Subject: [PATCH] allow selective restore --- Android.mk | 2 +- commands.c | 2 +- extendedcommands.c | 56 +++++++++++++++++++++++++++++++++++++++++++++- nandroid.c | 21 +++++++++-------- nandroid.h | 2 +- 5 files changed, 70 insertions(+), 13 deletions(-) diff --git a/Android.mk b/Android.mk index 749059a..b5def18 100644 --- a/Android.mk +++ b/Android.mk @@ -26,7 +26,7 @@ LOCAL_MODULE := recovery LOCAL_FORCE_STATIC_EXECUTABLE := true -RECOVERY_VERSION := ClockworkMod Recovery v1.7.7.3 +RECOVERY_VERSION := ClockworkMod Recovery v1.7.8.0 LOCAL_CFLAGS := -DRECOVERY_VERSION="$(RECOVERY_VERSION)" RECOVERY_API_VERSION := 2 LOCAL_CFLAGS += -DRECOVERY_API_VERSION=$(RECOVERY_API_VERSION) diff --git a/commands.c b/commands.c index 520c143..3114569 100644 --- a/commands.c +++ b/commands.c @@ -801,7 +801,7 @@ cmd_restore_rom(const char *name, void *cookie, int argc, const char *argv[], return 1; } - return nandroid_restore(argv[0]); + return nandroid_restore(argv[0], 1, 1, 1, 1); } static int diff --git a/extendedcommands.c b/extendedcommands.c index 5b3f7d4..f3ddd00 100644 --- a/extendedcommands.c +++ b/extendedcommands.c @@ -347,7 +347,7 @@ void show_nandroid_restore_menu() char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, headers); if (file == NULL) return; - nandroid_restore(file); + nandroid_restore(file, 1, 1, 1, 1); } void show_mount_usb_storage_menu() @@ -568,6 +568,56 @@ int amend_main(int argc, char** argv) return run_script(argv[1], 0); } +void show_nandroid_advanced_restore_menu() +{ + if (ensure_root_path_mounted("SDCARD:") != 0) { + LOGE ("Can't mount /sdcard\n"); + return; + } + + static char* advancedheaders[] = { "Choose an image to restore", + "", + "Choose an image to restore", + "first. The next menu will", + "you more options.", + "", + NULL + }; + + char* file = choose_file_menu("/sdcard/clockworkmod/backup/", NULL, advancedheaders); + if (file == NULL) + return; + + static char* headers[] = { "Nandroid Advanced Restore", + "", + NULL + }; + + static char* list[] = { "Restore boot", + "Restore system", + "Restore data", + "Restore cache", + NULL + }; + + int chosen_item = get_menu_selection(headers, list, 0); + switch (chosen_item) + { + case 0: + nandroid_restore(file, 1, 0, 0, 0); + break; + case 1: + nandroid_restore(file, 0, 1, 0, 0); + break; + case 2: + nandroid_restore(file, 0, 0, 1, 0); + break; + case 3: + nandroid_restore(file, 0, 0, 0, 1); + break; + } +} + void show_nandroid_menu() { static char* headers[] = { "Nandroid", @@ -577,6 +627,7 @@ void show_nandroid_menu() static char* list[] = { "Backup", "Restore", + "Advanced Restore", NULL }; @@ -595,6 +646,9 @@ void show_nandroid_menu() case 1: show_nandroid_restore_menu(); break; + case 2: + show_nandroid_advanced_restore_menu(); + break; } } diff --git a/nandroid.c b/nandroid.c index 7201438..5a54f45 100644 --- a/nandroid.c +++ b/nandroid.c @@ -174,7 +174,7 @@ int nandroid_restore_partition(char* backup_path, char* root, char* name) { return 0; } -int nandroid_restore(char* backup_path) +int nandroid_restore(char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache) { ui_set_background(BACKGROUND_ICON_INSTALLING); ui_show_indeterminate_progress(); @@ -191,20 +191,23 @@ int nandroid_restore(char* backup_path) return print_and_error("MD5 mismatch!\n"); int ret; - sprintf(tmp, "flash_image boot %s/boot.img", backup_path); - ui_print("Restoring boot image...\n"); - if (0 != (ret = __system(tmp))) { - ui_print("Error while flashing boot image!"); - return ret; + if (restore_boot) + { + sprintf(tmp, "flash_image boot %s/boot.img", backup_path); + ui_print("Restoring boot image...\n"); + if (0 != (ret = __system(tmp))) { + ui_print("Error while flashing boot image!"); + return ret; + } } - if (0 != (ret = nandroid_restore_partition(backup_path, "SYSTEM:", "system"))) + if (restore_system && 0 != (ret = nandroid_restore_partition(backup_path, "SYSTEM:", "system"))) return ret; - if (0 != (ret = nandroid_restore_partition(backup_path, "DATA:", "data"))) + if (restore_data && 0 != (ret = nandroid_restore_partition(backup_path, "DATA:", "data"))) return ret; - if (0 != (ret = nandroid_restore_partition(backup_path, "CACHE:", "cache"))) + if (restore_cache && 0 != (ret = nandroid_restore_partition(backup_path, "CACHE:", "cache"))) return ret; sync(); diff --git a/nandroid.h b/nandroid.h index 3f6c5a8..2ab0308 100644 --- a/nandroid.h +++ b/nandroid.h @@ -3,6 +3,6 @@ int nandroid_main(int argc, char** argv); int nandroid_backup(char* backup_path); -int nandroid_restore(char* backup_path); +int nandroid_restore(char* backup_path, int restore_boot, int restore_system, int restore_data, int restore_cache); #endif \ No newline at end of file