static void prompt_and_wait() { char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); allow_display_toggle = 1; int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); allow_display_toggle = 0; // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); int status; switch (chosen_item) { case ITEM_REBOOT: poweroff=0; return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache")) { ui_print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; } break; case ITEM_APPLY_SDCARD: show_install_update_menu(); break; case ITEM_NANDROID: show_nandroid_menu(); break; case ITEM_PARTITION: show_partition_menu(); break; case ITEM_ADVANCED: show_advanced_menu(); break; case ITEM_POWEROFF: poweroff = 1; return; } } }
static void prompt_and_wait() { char** headers = prepend_title(MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); ui_set_background(BACKGROUND_ICON_ERROR); int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_APPLY_SDCARD: show_install_update_menu(); /* ui_print("\n-- Install from sdcard...\n"); set_sdcard_update_bootloader_message(); int status = install_package(SDCARD_PACKAGE_FILE); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else if (!ui_text_visible()) { return; // reboot if logs aren't visible } else { ui_print("\nInstall from sdcard complete.\n"); } */ break; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: ui_print("\n-- Wiping cache...\n"); erase_root("CACHE:"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; break; case ITEM_ADVANCED: show_advanced_menu(); break; } } }
void prompt_and_wait() { char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: printf("\n-- Wiping cache...\n"); erase_volume("/cache"); printf("Cache wipe complete.\n"); if (!ui_text_visible()) return; break; case ITEM_APPLY_SDCARD: ; int status = sdcard_directory(SDCARD_ROOT); if (status >= 0) { if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); printf("Installation aborted.\n"); } else if (!ui_text_visible()) { return; // reboot if logs aren't visible } else { printf("\nInstall from sdcard complete.\n"); } } break; } } }
static void prompt_and_wait(Device* device, int status) { const char* const* headers = prepend_title(device->GetMenuHeaders()); for (;;) { finish_recovery(NULL); switch (status) { case INSTALL_SUCCESS: case INSTALL_NONE: ui->SetBackground(RecoveryUI::NO_COMMAND); break; case INSTALL_ERROR: case INSTALL_CORRUPT: ui->SetBackground(RecoveryUI::ERROR); break; } ui->SetProgressType(RecoveryUI::EMPTY); int chosen_item = get_menu_selection(headers, device->GetMenuItems(), 0, 0, device); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device->InvokeMenuItem(chosen_item); int wipe_cache; switch (chosen_item) { case Device::REBOOT: return; case Device::WIPE_DATA: wipe_data(ui->IsTextVisible(), device); if (!ui->IsTextVisible()) return; break; case Device::WIPE_CACHE: ui->Print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui->Print("Cache wipe complete.\n"); if (!ui->IsTextVisible()) return; break; case Device::APPLY_EXT: status = update_directory(SDCARD_ROOT, SDCARD_ROOT, &wipe_cache, device); if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (!ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); } } break; case Device::APPLY_CACHE: // Don't unmount cache at the end of this. status = update_directory(CACHE_ROOT, NULL, &wipe_cache, device); if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (!ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from cache complete.\n"); } } break; case Device::APPLY_ADB_SIDELOAD: status = apply_from_adb(ui, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status >= 0) { if (status != INSTALL_SUCCESS) { ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); copy_logs(); } else if (!ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from ADB complete.\n"); } } break; } } }
static void prompt_and_wait() { char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); allow_display_toggle = 1; int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); allow_display_toggle = 0; // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); switch (chosen_item) { case ITEM_REBOOT: poweroff=0; return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache")) { ui_print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; } break; case ITEM_APPLY_SDCARD: if (confirm_selection("Confirm install?", "Yes - Install /sdcard/update.zip")) { ui_print("\n-- Install from sdcard...\n"); int status = install_package(SDCARD_PACKAGE_FILE); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else if (!ui_text_visible()) { return; // reboot if logs aren't visible } else { ui_print("\nInstall from sdcard complete.\n"); } } break; case ITEM_INSTALL_ZIP: show_install_update_menu(); break; case ITEM_NANDROID: show_nandroid_menu(); break; case ITEM_PARTITION: show_partition_menu(); break; case ITEM_ADVANCED: show_advanced_menu(); break; case ITEM_POWEROFF: poweroff=1; return; } } }
static void prompt_and_wait() { char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); ui_root_menu = 1; // ui_menu_level is a legacy variable that i am keeping around to prevent build breakage. ui_menu_level = 0; // allow_display_toggle = 1; int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); ui_menu_level = 1; ui_root_menu = 0; // allow_display_toggle = 0; // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); int status; switch (chosen_item) { case ITEM_REBOOT: poweroff=0; return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: if (confirm_selection("确认清空?", "是 - 清空CACHE分区")) { ui_print("\n-- 正在清空CACHE分区...\n"); erase_volume("/cache"); ui_print("CACHE分区已清空.\n"); if (!ui_text_visible()) return; } break; case ITEM_APPLY_ZIP: show_install_update_menu(); break; case ITEM_NANDROID: show_nandroid_menu(); break; case ITEM_PARTITION: show_partition_menu(); break; case ITEM_ADVANCED: show_advanced_menu(); break; case ITEM_POWEROFF: poweroff = 1; return; } } }
// Return REBOOT, SHUTDOWN, or REBOOT_BOOTLOADER. Returning NO_ACTION // means to take the default, which is to reboot or shutdown depending // on if the --shutdown_after flag was passed to recovery. static Device::BuiltinAction prompt_and_wait(Device* device, int status) { const char* const* headers = prepend_title(device->GetMenuHeaders()); for (;;) { finish_recovery(NULL); switch (status) { case INSTALL_SUCCESS: case INSTALL_NONE: ui->SetBackground(RecoveryUI::NO_COMMAND); break; case INSTALL_ERROR: case INSTALL_CORRUPT: ui->SetBackground(RecoveryUI::ERROR); break; } ui->SetProgressType(RecoveryUI::EMPTY); int chosen_item = get_menu_selection(headers, device->GetMenuItems(), 0, 0, device); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. Device::BuiltinAction chosen_action = device->InvokeMenuItem(chosen_item); int wipe_cache = 0; switch (chosen_action) { case Device::NO_ACTION: break; case Device::REBOOT: case Device::SHUTDOWN: case Device::REBOOT_BOOTLOADER: return chosen_action; case Device::WIPE_DATA: wipe_data(ui->IsTextVisible(), device); if (!ui->IsTextVisible()) return Device::NO_ACTION; break; case Device::WIPE_CACHE: ui->Print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui->Print("Cache wipe complete.\n"); if (!ui->IsTextVisible()) return Device::NO_ACTION; break; case Device::APPLY_EXT: { ensure_path_mounted(SDCARD_ROOT); char* path = browse_directory(SDCARD_ROOT, device); if (path == NULL) { ui->Print("\n-- No package file selected.\n", path); break; } ui->Print("\n-- Install %s ...\n", path); set_sdcard_update_bootloader_message(); void* token = start_sdcard_fuse(path); int status = install_package(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache, TEMPORARY_INSTALL_FILE, false); finish_sdcard_fuse(token); ensure_path_unmounted(SDCARD_ROOT); if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (!ui->IsTextVisible()) { return Device::NO_ACTION; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); } } break; } case Device::APPLY_CACHE: ui->Print("\nAPPLY_CACHE is deprecated.\n"); break; case Device::READ_RECOVERY_LASTLOG: choose_recovery_file(device); break; case Device::APPLY_ADB_SIDELOAD: status = apply_from_adb(ui, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status >= 0) { if (status != INSTALL_SUCCESS) { ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); copy_logs(); } else if (!ui->IsTextVisible()) { return Device::NO_ACTION; // reboot if logs aren't visible } else { ui->Print("\nInstall from ADB complete.\n"); } } break; } } }
static int prompt_and_wait() { char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); int status; int wipe_cache; switch (chosen_item) { case ITEM_REBOOT: return REBOOT_NORMAL; #ifdef RECOVERY_HAS_FACTORY_TEST case ITEM_FACTORY_TEST: return REBOOT_FACTORY_TEST; #endif case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return REBOOT_NORMAL; break; case ITEM_WIPE_CACHE: ui_print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return REBOOT_NORMAL; break; #ifdef RECOVERY_HAS_MEDIA case ITEM_WIPE_MEDIA: wipe_media(ui_text_visible()); if (!ui_text_visible()) return REBOOT_NORMAL; break; #endif /* RECOVERY_HAS_MEDIA */ case ITEM_APPLY_SDCARD: #ifdef RECOVERY_HAS_SDCARD_ONLY status = update_directory(SDCARD_ROOT, SDCARD_ROOT, &wipe_cache); #else status = update_directory("/", "/", &wipe_cache); #endif /* RECOVERY_HAS_SDCARD_ONLY */ if (status == INSTALL_SUCCESS && wipe_cache) { ui_print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui_print("Cache wipe failed.\n"); } else { ui_print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else if (!ui_text_visible()) { return REBOOT_NORMAL; // reboot if logs aren't visible } else { #ifdef RECOVERY_HAS_SDCARD_ONLY ui_print("\nInstall from sdcard complete.\n"); #else ui_print("\nInstall complete.\n"); #endif /* RECOVERY_HAS_SDCARD_ONLY */ } } break; case ITEM_APPLY_CACHE: // Don't unmount cache at the end of this. status = update_directory(CACHE_ROOT, NULL, &wipe_cache); if (status == INSTALL_SUCCESS && wipe_cache) { ui_print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui_print("Cache wipe failed.\n"); } else { ui_print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else if (!ui_text_visible()) { return REBOOT_NORMAL; // reboot if logs aren't visible } else { ui_print("\nInstall from cache complete.\n"); } } break; #ifdef RECOVERY_HAS_EFUSE case ITEM_WRITE_EFUSE: recovery_efuse(-1, NULL); if (!ui_text_visible()) return REBOOT_NORMAL; break; #endif /* RECOVERY_HAS_EFUSE */ } } }
static void prompt_and_wait() { char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); ui_root_menu = 1; // ui_menu_level is a legacy variable that i am keeping around to prevent build breakage. ui_menu_level = 0; // allow_display_toggle = 1; int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); ui_menu_level = 1; ui_root_menu = 0; // allow_display_toggle = 0; // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); int status; switch (chosen_item) { case ITEM_REBOOT: poweroff=0; return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: if (confirm_selection("你真的要清除数据?", "我就是要删除缓存数据")) { ui_print("\n-- 正在清除 \n"); erase_volume("/cache"); ui_print("已经成功清除\n"); if (!ui_text_visible()) return; } break; case ITEM_APPLY_SDCARD: show_install_update_menu(); break; case ITEM_APPLY_SIDELOAD: apply_from_adb(); break; case ITEM_NANDROID: show_nandroid_menu(); break; case ITEM_PARTITION: show_partition_menu(); break; case ITEM_ADVANCED: show_advanced_menu(); break; case ITEM_GUOHOWFLASH: // 调用exs.c中该函数 show_guohowflash_menu(); break; case ITEM_GUOHOWWHOLEWIPE: // 调用exs.c中该函数 show_guohowwholewipe_menu(); break; case ITEM_GUOHOWHELP: // 调用exs.c中该函数 show_guohowhelp_menu(); break; case ITEM_GUOHOWABOUT: // 调用exs.c中该函数 show_guohowabout_menu(); break; case ITEM_POWEROFF: poweroff = 1; return; } } }
int GUIAction::doAction(Action action, int isThreaded /* = 0 */) { static string zip_queue[10]; static int zip_queue_index; int simulate; std::string arg = gui_parse_text(action.mArg); std::string function = gui_parse_text(action.mFunction); DataManager::GetValue(TW_SIMULATE_ACTIONS, simulate); if (function == "reboot") { //curtainClose(); this sometimes causes a crash sync(); if (arg == "recovery") tw_reboot(rb_recovery); else if (arg == "poweroff") tw_reboot(rb_poweroff); else if (arg == "bootloader") tw_reboot(rb_bootloader); else if (arg == "download") tw_reboot(rb_download); else tw_reboot(rb_system); // This should never occur return -1; } if (function == "home") { PageManager::SelectPackage("TWRP"); gui_changePage("main"); return 0; } if (function == "key") { PageManager::NotifyKey(getKeyByName(arg)); return 0; } if (function == "page") { std::string page_name = gui_parse_text(arg); return gui_changePage(page_name); } if (function == "reload") { int check = 0, ret_val = 0; std::string theme_path; operation_start("Reload Theme"); theme_path = DataManager::GetSettingsStoragePath(); if (ensure_path_mounted(theme_path.c_str()) < 0) { LOGE("Unable to mount %s during reload function startup.\n", theme_path.c_str()); check = 1; } theme_path += "/TWRP/theme/ui.zip"; if (check != 0 || PageManager::ReloadPackage("TWRP", theme_path) != 0) { // Loading the custom theme failed - try loading the stock theme LOGI("Attempting to reload stock theme...\n"); if (PageManager::ReloadPackage("TWRP", "/res/ui.xml")) { LOGE("Failed to load base packages.\n"); ret_val = 1; } } operation_end(ret_val, simulate); } if (function == "readBackup") { set_restore_files(); return 0; } if (function == "set") { if (arg.find('=') != string::npos) { string varName = arg.substr(0, arg.find('=')); string value = arg.substr(arg.find('=') + 1, string::npos); DataManager::GetValue(value, value); DataManager::SetValue(varName, value); } else DataManager::SetValue(arg, "1"); return 0; } if (function == "clear") { DataManager::SetValue(arg, "0"); return 0; } if (function == "mount") { if (arg == "usb") { DataManager::SetValue(TW_ACTION_BUSY, 1); if (!simulate) usb_storage_enable(); else ui_print("Simulating actions...\n"); } else if (!simulate) { string cmd; if (arg == "EXTERNAL") cmd = "mount " + DataManager::GetStrValue(TW_EXTERNAL_MOUNT); else if (arg == "INTERNAL") cmd = "mount " + DataManager::GetStrValue(TW_INTERNAL_MOUNT); else cmd = "mount " + arg; __system(cmd.c_str()); if (arg == "/data" && DataManager::GetIntValue(TW_HAS_DATADATA) == 1) __system("mount /datadata"); } else ui_print("Simulating actions...\n"); return 0; } if (function == "umount" || function == "unmount") { if (arg == "usb") { if (!simulate) usb_storage_disable(); else ui_print("Simulating actions...\n"); DataManager::SetValue(TW_ACTION_BUSY, 0); } else if (!simulate) { string cmd; if (arg == "EXTERNAL") cmd = "umount " + DataManager::GetStrValue(TW_EXTERNAL_MOUNT); else if (arg == "INTERNAL") cmd = "umount " + DataManager::GetStrValue(TW_INTERNAL_MOUNT); else if (DataManager::GetIntValue(TW_DONT_UNMOUNT_SYSTEM) == 1 && (arg == "system" || arg == "/system")) return 0; else cmd = "umount " + arg; __system(cmd.c_str()); if (arg == "/data" && DataManager::GetIntValue(TW_HAS_DATADATA) == 1) __system("umount /datadata"); } else ui_print("Simulating actions...\n"); return 0; } if (function == "restoredefaultsettings") { operation_start("Restore Defaults"); if (simulate) // Simulated so that people don't accidently wipe out the "simulation is on" setting ui_print("Simulating actions...\n"); else { DataManager::ResetDefaults(); mount_current_storage(); } operation_end(0, simulate); } if (function == "copylog") { operation_start("Copy Log"); if (!simulate) { char command[255]; mount_current_storage(); sprintf(command, "cp /tmp/recovery.log %s", DataManager::GetCurrentStoragePath().c_str()); __system(command); sync(); ui_print("Copied recovery log to %s.\n", DataManager::GetCurrentStoragePath().c_str()); } else simulate_progress_bar(); operation_end(0, simulate); return 0; } if (function == "compute" || function == "addsubtract") { if (arg.find("+") != string::npos) { string varName = arg.substr(0, arg.find('+')); string string_to_add = arg.substr(arg.find('+') + 1, string::npos); int amount_to_add = atoi(string_to_add.c_str()); int value; DataManager::GetValue(varName, value); DataManager::SetValue(varName, value + amount_to_add); return 0; } if (arg.find("-") != string::npos) { string varName = arg.substr(0, arg.find('-')); string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos); int amount_to_subtract = atoi(string_to_subtract.c_str()); int value; DataManager::GetValue(varName, value); value -= amount_to_subtract; if (value <= 0) value = 0; DataManager::SetValue(varName, value); return 0; } } if (function == "setguitimezone") { string SelectedZone; DataManager::GetValue(TW_TIME_ZONE_GUISEL, SelectedZone); // read the selected time zone into SelectedZone string Zone = SelectedZone.substr(0, SelectedZone.find(';')); // parse to get time zone string DSTZone = SelectedZone.substr(SelectedZone.find(';') + 1, string::npos); // parse to get DST component int dst; DataManager::GetValue(TW_TIME_ZONE_GUIDST, dst); // check wether user chose to use DST string offset; DataManager::GetValue(TW_TIME_ZONE_GUIOFFSET, offset); // pull in offset string NewTimeZone = Zone; if (offset != "0") NewTimeZone += ":" + offset; if (dst != 0) NewTimeZone += DSTZone; DataManager::SetValue(TW_TIME_ZONE_VAR, NewTimeZone); update_tz_environment_variables(); return 0; } if (function == "togglestorage") { if (arg == "internal") { DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 0); DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcint.sze - sdcint.used) / 1048576LLU)); } else if (arg == "external") { DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 1); DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcext.sze - sdcext.used) / 1048576LLU)); } if (mount_current_storage() == 0) { if (arg == "internal") { // Save the current zip location to the external variable DataManager::SetValue(TW_ZIP_EXTERNAL_VAR, DataManager::GetStrValue(TW_ZIP_LOCATION_VAR)); // Change the current zip location to the internal variable DataManager::SetValue(TW_ZIP_LOCATION_VAR, DataManager::GetStrValue(TW_ZIP_INTERNAL_VAR)); } else if (arg == "external") { // Save the current zip location to the internal variable DataManager::SetValue(TW_ZIP_INTERNAL_VAR, DataManager::GetStrValue(TW_ZIP_LOCATION_VAR)); // Change the current zip location to the external variable DataManager::SetValue(TW_ZIP_LOCATION_VAR, DataManager::GetStrValue(TW_ZIP_EXTERNAL_VAR)); } } else { // We weren't able to toggle for some reason, restore original setting if (arg == "internal") { DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 1); DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcext.sze - sdcext.used) / 1048576LLU)); } else if (arg == "external") { DataManager::SetValue(TW_USE_EXTERNAL_STORAGE, 0); DataManager::SetValue(TW_STORAGE_FREE_SIZE, (int)((sdcint.sze - sdcint.used) / 1048576LLU)); } } return 0; } if (function == "overlay") return gui_changeOverlay(arg); if (function == "queuezip") { if (zip_queue_index >= 10) { ui_print("Maximum zip queue reached!\n"); return 0; } DataManager::GetValue("tw_filename", zip_queue[zip_queue_index]); if (strlen(zip_queue[zip_queue_index].c_str()) > 0) { zip_queue_index++; DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); } return 0; } if (function == "cancelzip") { if (zip_queue_index <= 0) { ui_print("Minimum zip queue reached!\n"); return 0; } else { zip_queue_index--; DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); } return 0; } if (function == "queueclear") { zip_queue_index = 0; DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); return 0; } if (function == "sleep") { usleep(atoi(arg.c_str())); return 0; } if (isThreaded) { if (function == "flash") { int i, ret_val = 0; for (i=0; i<zip_queue_index; i++) { operation_start("Flashing"); DataManager::SetValue("tw_filename", zip_queue[i]); DataManager::SetValue(TW_ZIP_INDEX, (i + 1)); ret_val = flash_zip(zip_queue[i], arg, simulate); if (ret_val != 0) { ui_print("Error flashing zip '%s'\n", zip_queue[i].c_str()); i = 10; // Error flashing zip - exit queue ret_val = 1; } } zip_queue_index = 0; DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); if (DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) { operation_start("ReinjectTWRP"); ui_print("Injecting TWRP into boot image...\n"); if (simulate) { simulate_progress_bar(); } else { __system("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); ui_print("TWRP injection complete.\n"); } } operation_end(ret_val, simulate); return 0; } if (function == "wipe") { operation_start("Format"); DataManager::SetValue("tw_partition", arg); if (simulate) { simulate_progress_bar(); } else { if (arg == "data") wipe_data(0); else if (arg == "battery") wipe_battery_stats(); else if (arg == "rotate") wipe_rotate_data(); else if (arg == "dalvik") wipe_dalvik_cache(); else erase_volume(arg.c_str()); if (arg == "/sdcard") { ensure_path_mounted(SDCARD_ROOT); mkdir("/sdcard/TWRP", 0777); DataManager::Flush(); } } update_system_details(); operation_end(0, simulate); return 0; } if (function == "refreshsizes") { operation_start("Refreshing Sizes"); if (simulate) { simulate_progress_bar(); } else update_system_details(); operation_end(0, simulate); } if (function == "nandroid") { operation_start("Nandroid"); if (simulate) { DataManager::SetValue("tw_partition", "Simulation"); simulate_progress_bar(); } else { if (arg == "backup") nandroid_back_exe(); else if (arg == "restore") nandroid_rest_exe(); else { operation_end(1, simulate); return -1; } } operation_end(0, simulate); return 0; } if (function == "fixpermissions") { operation_start("Fix Permissions"); LOGI("fix permissions started!\n"); if (simulate) { simulate_progress_bar(); } else fix_perms(); LOGI("fix permissions DONE!\n"); operation_end(0, simulate); return 0; } if (function == "dd") { operation_start("imaging"); if (simulate) { simulate_progress_bar(); } else { char cmd[512]; sprintf(cmd, "dd %s", arg.c_str()); __system(cmd); } operation_end(0, simulate); return 0; } if (function == "partitionsd") { operation_start("Partition SD Card"); if (simulate) { simulate_progress_bar(); } else { int allow_partition; DataManager::GetValue(TW_ALLOW_PARTITION_SDCARD, allow_partition); if (allow_partition == 0) { ui_print("This device does not have a real SD Card!\nAborting!\n"); } else { // Below seen in Koush's recovery char sddevice[256]; Volume *vol = volume_for_path("/sdcard"); strcpy(sddevice, vol->device); // Just need block not whole partition sddevice[strlen("/dev/block/mmcblkX")] = NULL; char es[64]; std::string ext_format; int ext, swap; DataManager::GetValue("tw_sdext_size", ext); DataManager::GetValue("tw_swap_size", swap); DataManager::GetValue("tw_sdpart_file_system", ext_format); sprintf(es, "/sbin/sdparted -es %dM -ss %dM -efs %s -s > /cache/part.log",ext,swap,ext_format.c_str()); LOGI("\nrunning script: %s\n", es); run_script("\nContinue partitioning?", "\nPartitioning sdcard : ", es, "\nunable to execute parted!\n(%s)\n", "\nOops... something went wrong!\nPlease check the recovery log!\n", "\nPartitioning complete!\n\n", "\nPartitioning aborted!\n\n", 0); // recreate TWRP folder and rewrite settings - these will be gone after sdcard is partitioned ensure_path_mounted(SDCARD_ROOT); mkdir("/sdcard/TWRP", 0777); DataManager::Flush(); DataManager::SetValue(TW_ZIP_EXTERNAL_VAR, "/sdcard"); if (DataManager::GetIntValue(TW_USE_EXTERNAL_STORAGE) == 1) DataManager::SetValue(TW_ZIP_LOCATION_VAR, "/sdcard"); update_system_details(); } } operation_end(0, simulate); return 0; } if (function == "installhtcdumlock") { operation_start("Install HTC Dumlock"); if (simulate) { simulate_progress_bar(); } else install_htc_dumlock(); operation_end(0, simulate); return 0; } if (function == "htcdumlockrestoreboot") { operation_start("HTC Dumlock Restore Boot"); if (simulate) { simulate_progress_bar(); } else htc_dumlock_restore_original_boot(); operation_end(0, simulate); return 0; } if (function == "htcdumlockreflashrecovery") { operation_start("HTC Dumlock Reflash Recovery"); if (simulate) { simulate_progress_bar(); } else htc_dumlock_reflash_recovery_to_boot(); operation_end(0, simulate); return 0; } if (function == "cmd") { int op_status = 0; operation_start("Command"); ui_print("Running command: '%s'\n", arg.c_str()); if (simulate) { simulate_progress_bar(); } else { op_status = __system(arg.c_str()); if (op_status != 0) op_status = 1; } operation_end(op_status, simulate); return 0; } if (function == "reinjecttwrp") { int op_status = 0; operation_start("ReinjectTWRP"); ui_print("Injecting TWRP into boot image...\n"); if (simulate) { simulate_progress_bar(); } else { __system("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); ui_print("TWRP injection complete.\n"); } operation_end(op_status, simulate); return 0; } } else { pthread_t t; pthread_create(&t, NULL, thread_start, this); return 0; } return -1; }
static void prompt_and_wait(int status) { const char** headers = prepend_title((const char**)MENU_HEADERS); switch (status) { case INSTALL_SUCCESS: case INSTALL_NONE: #ifndef PHILZ_TOUCH_RECOVERY ui_set_background(BACKGROUND_ICON_CLOCKWORK); #endif break; case INSTALL_ERROR: case INSTALL_CORRUPT: ui_set_background(BACKGROUND_ICON_ERROR); break; } for (;;) { finish_recovery(NULL); ui_root_menu = 1; ui_reset_progress(); int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); ui_root_menu = 0; // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. (this can alter show_text state!!) chosen_item = device_perform_action(chosen_item); int ret = 0; for (;;) { switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_WIPE_DATA: if (ui_IsTextVisible()) wipe_data_menu(); else wipe_data(ui_IsTextVisible()); if (!ui_IsTextVisible()) return; break; case ITEM_WIPE_CACHE: if (ui_IsTextVisible()) { wipe_data_menu(); } else { ui_print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui_print("Cache wipe complete.\n"); } if (!ui_IsTextVisible()) return; break; case ITEM_APPLY_ZIP: ret = show_install_update_menu(); break; case ITEM_NANDROID: ret = show_nandroid_menu(); break; case ITEM_PARTITION: ret = show_partition_mounts_menu(); break; case ITEM_ADVANCED: show_advanced_menu(); break; case ITEM_SETTINGS: show_philz_settings_menu(); break; case ITEM_POWEROFF: show_advanced_power_menu(); break; } if (ret == REFRESH) { // this will restart the for() loop and run switch (chosen_item) action forcing to return to previous menu and refresh it ret = 0; continue; } break; } } }
static void prompt_and_wait() { const char** headers = prepend_title((const char**)MENU_HEADERS); for (;;) { finish_recovery(NULL); ui_reset_progress(); ui_root_menu = 1; // ui_menu_level is a legacy variable that i am keeping around to prevent build breakage. ui_menu_level = 0; int chosen_item = get_menu_selection(headers, MENU_ITEMS, 0, 0); ui_menu_level = 1; ui_root_menu = 0; // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. chosen_item = device_perform_action(chosen_item); int status; int ret = 0; for (;;) { switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; break; case ITEM_WIPE_CACHE: if (confirm_selection("Confirm wipe?", "Yes - Wipe Cache")) { ui_print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; } break; case ITEM_APPLY_ZIP: ret = show_install_update_menu(); break; case ITEM_NANDROID: ret = show_nandroid_menu(); break; case ITEM_PARTITION: ret = show_partition_menu(); break; case ITEM_ADVANCED: ret = show_advanced_menu(); break; } if (ret == REFRESH) { ret = 0; continue; } break; } } }
static void prompt_and_wait(Device* device, int status) { const char* const* headers = prepend_title(device->GetMenuHeaders()); int chosen_item = 6; // add by cjcheng for (;;) { finish_recovery(NULL); switch (status) { case INSTALL_SUCCESS: case INSTALL_NONE: ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); // modify by cjcheng break; } ui->SetProgressType(RecoveryUI::EMPTY); // int chosen_item = get_menu_selection(headers, device->GetMenuItems(), 0, 0, device); // modify by cjcheng // device-specific code may take some action here. It may // return one of the core actions handled in the switch // statement below. // chosen_item = device->InvokeMenuItem(chosen_item); // modify by cjcheng int wipe_cache; switch (chosen_item) { case Device::REBOOT: return; case Device::WIPE_DATA: wipe_data(ui->IsTextVisible(), device); if (!ui->IsTextVisible()) return; break; case Device::WIPE_CACHE: ui->ShowText(false); ui->Print("\n-- Wiping cache...\n"); erase_volume("/cache"); ui->Print("Cache wipe complete.\n"); if (!ui->IsTextVisible()) return; break; case Device::APPLY_CACHE: // Don't unmount cache at the end of this. status = update_directory(CACHE_ROOT, NULL, &wipe_cache, device); if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { // ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (!ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from cache complete.\n"); } } break; case Device::APPLY_ADB_SIDELOAD: ensure_path_mounted(CACHE_ROOT); status = apply_from_adb(ui, &wipe_cache, TEMPORARY_INSTALL_FILE); if (status >= 0) { if (status != INSTALL_SUCCESS) { // ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (!ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from ADB complete.\n"); } } break; /* add by cjcheng start... */ case Device::APPLY_SDCARD: // Some packages expect /cache to be mounted (eg, // standard incremental packages expect to use /cache // as scratch space). ensure_path_mounted(CACHE_ROOT); status = smdt_update_directory(SDCARD_ROOT, SDCARD_ROOT, &wipe_cache); install_flag = status; if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { // ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); chosen_item = 1; } } break; case Device::APPLY_EXT: // Some packages expect /cache to be mounted (eg, // standard incremental packages expect to use /cache // as scratch space). ensure_path_mounted(CACHE_ROOT); status = smdt_update_directory(EXTSD_ROOT, EXTSD_ROOT, &wipe_cache); install_flag = status; if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { // ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); chosen_item = 1; } } break; case Device::APPLY_USB1: // Some packages expect /cache to be mounted (eg, // standard incremental packages expect to use /cache // as scratch space). ensure_path_mounted(CACHE_ROOT); status = smdt_update_directory(USB1_ROOT, USB1_ROOT, &wipe_cache); install_flag = status; if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { // ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); chosen_item = 1; } } break; case Device::APPLY_USB0: // Some packages expect /cache to be mounted (eg, // standard incremental packages expect to use /cache // as scratch space). ensure_path_mounted(CACHE_ROOT); status = smdt_update_directory(USB0_ROOT, USB0_ROOT, &wipe_cache); install_flag = status; if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { // ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); chosen_item = 1; } } break; case Device::APPLY_SATA: // Some packages expect /cache to be mounted (eg, // standard incremental packages expect to use /cache // as scratch space). ensure_path_mounted(CACHE_ROOT); status = smdt_update_directory(SATA_ROOT, SATA_ROOT, &wipe_cache); install_flag = status; if (status == INSTALL_SUCCESS && wipe_cache) { ui->Print("\n-- Wiping cache (at package request)...\n"); if (erase_volume("/cache")) { ui->Print("Cache wipe failed.\n"); } else { ui->Print("Cache wipe complete.\n"); } } if (status >= 0) { if (status != INSTALL_SUCCESS) { // ui->SetBackground(RecoveryUI::ERROR); ui->Print("Installation aborted.\n"); } else if (ui->IsTextVisible()) { return; // reboot if logs aren't visible } else { ui->Print("\nInstall from sdcard complete.\n"); chosen_item = 1; } } break; /* add by cjcheng end... */ } /* add by cjcheng start... */ if (chosen_item < 11 && chosen_item != 1) chosen_item++; else chosen_item = 1; /* add by cjcheng end... */ } }
static void prompt_and_wait() { char* menu_files[MAX_MENU_LEVEL] = { NULL }; char* menu_scripts[MAX_MENU_LEVEL] = { NULL }; int menu_sel[MAX_MENU_LEVEL] = { 0 }; unsigned int menu_level = 0; int menu_result; //always ensure if mountings are good ensure_common_roots_mounted(); //initialize the recovery -> either call the script for initalization, or switch to full version #if !OPEN_RCVR_VERSION_LITE run_shell_script("/bin/init_recovery.sh "OPEN_RECOVERY_PHONE_SWITCH, 1, NULL); #endif menu_files[0] = malloc(strlen(MAIN_MENU_FILE)+1); strcpy(menu_files[0], MAIN_MENU_FILE); ui_led_blink(1); create_menu(menu_files[0], menu_scripts[0]); ui_led_toggle(0); int title_length; char** headers; headers = prepend_title(MENU_HEADERS, &title_length); int override_initial_selection = -1; int call_finish_in_loop = 1; for (;;) { if (call_finish_in_loop) { finish_recovery(NULL); call_finish_in_loop = 0; } int menu_item; if (override_initial_selection != -1) { menu_item = get_menu_selection(headers, MENU_ITEMS, MENU_ITEMS_SELECTABLE, title_length, override_initial_selection, 0); override_initial_selection = -1; } else menu_item = get_menu_selection(headers, MENU_ITEMS, MENU_ITEMS_SELECTABLE, title_length, 0, 0); // Parse open recovery commands int chosen_item = select_action(menu_item); chosen_item = device_perform_action(chosen_item); //if tag, menu, or scripted menu -> don't hide menu //do it here explicitly, it would be a mess in the switch if (chosen_item != ITEM_TAG && chosen_item != ITEM_NEW_MENU && chosen_item != ITEM_NEW_MENU_SCRIPTED) hide_menu_selection(); fprintf(stderr, "Menu: %d, %d, %s\n", menu_item, chosen_item, MENU_ITEMS_TARGET[menu_item]); switch (chosen_item) { case ITEM_REBOOT: return; case ITEM_WIPE_DATA: wipe_data(ui_text_visible()); if (!ui_text_visible()) return; ui_set_background(BACKGROUND_ICON_ERROR); break; case ITEM_WIPE_CACHE: ui_print("\n-- Wiping cache...\n"); ui_led_blink(1); erase_root("CACHE:"); ensure_common_roots_mounted(); ui_led_toggle(0); ui_print("Cache wipe complete.\n"); if (!ui_text_visible()) return; ui_set_background(BACKGROUND_ICON_ERROR); break; case ITEM_APPLY_SDCARD: //HACK for "error: a label can only be part of a statement and a declaration is not a statement" //the rule is retarted, the follwing "dummy" statement is cut in optimization override_initial_selection=override_initial_selection; //confirm it char* confirm_headers[] = { "Confirm installing update package?", MENU_ITEMS[menu_item], "", NULL }; char* confirm_items[] = { "Yes", "No", NULL }; int confirm_item = show_interactive_menu(confirm_headers, confirm_items); if (confirm_item == 1) //YES! { ui_print("\n-- Install from sdcard...\n"); ui_led_blink(1); ensure_common_roots_unmounted(); ensure_root_path_mounted("SDCARD:"); set_sdcard_update_bootloader_message(); call_finish_in_loop = 1; int status = install_package(MENU_ITEMS_TARGET[menu_item]); ensure_common_roots_mounted(); if (status != INSTALL_SUCCESS) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("Installation aborted.\n"); } else if (!ui_text_visible()) return; // reboot if logs aren't visible else { if (firmware_update_pending()) { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("\nReboot via menu to complete\n" "installation.\n"); } else { ui_set_background(BACKGROUND_ICON_ERROR); ui_print("\nInstall from sdcard complete.\n"); } } create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); } override_initial_selection = menu_item; break; case ITEM_SHELL_SCRIPT: ui_print("\n-- Shell script...\n"); ui_print("%s\n", MENU_ITEMS_TARGET[menu_item]); ui_led_blink(1); ensure_common_roots_mounted(); run_shell_script(MENU_ITEMS_TARGET[menu_item], 1, NULL); create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); ui_print("Done.\n"); override_initial_selection = menu_item; break; case ITEM_TAG: if (MENU_ITEMS_TAG[menu_item] == 0x00) { int tag_fd = creat(MENU_ITEMS_TARGET[menu_item], 0644); if (tag_fd < 0) LOGE("Failed to set the tag.\n"); else { MENU_ITEMS_TAG[menu_item] = 0x01; MENU_ITEMS[menu_item][1] = 'X'; close(tag_fd); } } else if (MENU_ITEMS_TAG[menu_item] == 0x01) //just a little check if 0xFF aint there if bug is present { remove(MENU_ITEMS_TARGET[menu_item]); MENU_ITEMS_TAG[menu_item] = 0x00; MENU_ITEMS[menu_item][1] = ' '; } override_initial_selection = menu_item; break; case ITEM_NEW_MENU: if (menu_level + 1 >= MAX_MENU_LEVEL) { //too much menus, ignore break; } ui_led_blink(1); if (!strcmp(MENU_ITEMS_TARGET[menu_item], "..")) { if (menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_sel[menu_level] = 0; menu_level--; override_initial_selection = menu_sel[menu_level]; } } else { menu_sel[menu_level] = menu_item; menu_level++; menu_files[menu_level] = malloc(strlen(MENU_ITEMS_TARGET[menu_item]) + 1); strcpy(menu_files[menu_level], MENU_ITEMS_TARGET[menu_item]); } ensure_common_roots_mounted(); menu_result = create_menu(menu_files[menu_level], menu_scripts[menu_level]); //if fail, remove the new menu if (menu_result && menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_level--; } free(headers); headers = prepend_title(MENU_HEADERS, &title_length); ui_led_toggle(0); break; case ITEM_NEW_MENU_SCRIPTED: if (menu_level + 1 >= MAX_MENU_LEVEL) { //too much menus, ignore break; } ui_led_blink(1); char cmdBuff[MAX_LINE_LENGTH]; strcpy(cmdBuff, MENU_ITEMS_TARGET[menu_item]); char* ptr; //menufile:script ptr = strtok(cmdBuff, ":"); if (ptr != NULL) { menu_sel[menu_level] = menu_item; menu_level++; menu_files[menu_level] = malloc(strlen(ptr) + 1); strcpy(menu_files[menu_level], ptr); ptr = strtok(NULL, ""); if (ptr != NULL) { if (ptr[0] == '/' || (ptr[0] == '\"' && ptr[1] == '/')) { menu_scripts[menu_level] = malloc(strlen(ptr) + 1); strcpy(menu_scripts[menu_level], ptr); } else { menu_scripts[menu_level] = malloc(strlen(CUSTOM_SHELL_SCRIPT_PATH) + strlen(ptr) + 2); if (ptr[0] == '\"') sprintf(menu_scripts[menu_level], "\"%s/%s", CUSTOM_SHELL_SCRIPT_PATH, ptr+1); else sprintf(menu_scripts[menu_level], "%s/%s", CUSTOM_SHELL_SCRIPT_PATH, ptr); } } ensure_common_roots_mounted(); menu_result = create_menu(menu_files[menu_level], menu_scripts[menu_level]); //if fail, remove the new menu if (menu_result && menu_level) { free(menu_files[menu_level]); menu_files[menu_level] = NULL; if (menu_scripts[menu_level]) { free(menu_scripts[menu_level]); menu_scripts[menu_level] = NULL; } menu_level--; } free(headers); headers = prepend_title(MENU_HEADERS, &title_length); } ui_led_toggle(0); break; case ITEM_CONSOLE: #if OPEN_RECOVERY_HAVE_CONSOLE ensure_common_roots_mounted(); ui_print("Opening console...\n"); int console_error = run_console(NULL); if (console_error) if (console_error == CONSOLE_FORCE_QUIT) ui_print("Console was forcibly closed.\n"); else if (console_error == CONSOLE_FAILED_START) ui_print("Console failed to start.\n"); else { ui_print("Closing console...\n"); //don't bother printing error to UI fprintf(stderr, "Console closed with error %d.\n", console_error); } else ui_print("Closing console...\n"); create_menu(menu_files[menu_level], menu_scripts[menu_level]); free(headers); headers = prepend_title(MENU_HEADERS, &title_length); #else LOGE("This phone doesn't support console.\n"); #endif override_initial_selection = menu_item; break; case ITEM_ERROR: LOGE("Unknown command: %s.\n", MENU_ITEMS_ACTION[menu_item]); break; } } }