diff --git a/include/arm11/menu/menu_util.h b/include/arm11/menu/menu_util.h index 4022932..77bdfc0 100644 --- a/include/arm11/menu/menu_util.h +++ b/include/arm11/menu/menu_util.h @@ -33,6 +33,7 @@ u32 ee_printf_progress(const char *const fmt, u32 w, u64 curr, u64 max); void updateScreens(void); +bool askConfirmation(const char *const fmt, ...); void outputEndWait(void); bool userCancelHandler(bool cancelAllowed); void sleepmode(void); diff --git a/source/arm11/menu/menu_func.c b/source/arm11/menu/menu_func.c index be40d1a..5b7289d 100644 --- a/source/arm11/menu/menu_func.c +++ b/source/arm11/menu/menu_func.c @@ -506,11 +506,21 @@ if (!menuFileSelector(fpath, menu_con, NAND_BACKUP_PATH, "*.bin", false)) return 1; // canceled by user - // select & clear console consoleSelect(term_con); consoleClear(); + // ask the user for confirmation + if (forced) + { + if (!askConfirmation(ESC_SCHEME_BAD "WARNING:" ESC_RESET "\nYou're about to force-restore a NAND image to\nyour system. Doing this with an incompatible\nNAND image will **BRICK** your console! Make\nsure you backed up your important data!")) return 1; + } + else + { + if (!askConfirmation(ESC_SCHEME_BAD "WARNING:" ESC_RESET "\nYou're about to restore a NAND image to\nyour system. Make sure you have backups of\nyour important data!")) return 1; + } + consoleClear(); + // check NAND backup (when not forced) if (!forced && (fVerifyNandImage(fpath) != 0)) { @@ -641,10 +651,14 @@ return 1; // cancel by user - // load and install firm + // select and clear console consoleSelect(term_con); consoleClear(); + // ask the user for confirmation + if (!askConfirmation(ESC_SCHEME_BAD "WARNING:" ESC_RESET "\nYou're about to install a firmware to %s.\nFlashing incompatible firmwares may lead to\nunexpected results.", firm_drv)) return 1; + consoleClear(); + ee_printf(ESC_SCHEME_ACCENT1 "Flashing firmware to %s:\n%s\n" ESC_RESET "\nLoading firmware... ", firm_drv, firm_path); updateScreens(); diff --git a/source/arm11/menu/menu_util.c b/source/arm11/menu/menu_util.c index 95c2ff1..bac4f6e 100644 --- a/source/arm11/menu/menu_util.c +++ b/source/arm11/menu/menu_util.c @@ -158,10 +158,10 @@ { u32 res = 0; - char buf[256]; + char buf[512]; va_list args; va_start(args, fmt); - ee_vsnprintf(buf, 256, fmt, args); + ee_vsnprintf(buf, 512, fmt, args); va_end(args); PrintConsole *con = consoleGet(); @@ -223,6 +223,40 @@ GFX_waitForEvent(GFX_EVENT_PDC0, true); // VBlank } +bool askConfirmation(const char *const fmt, ...) +{ + char buf[512]; + char* instr = buf; + u32 kDown = 0, kHeld = 0; + + va_list args; + va_start(args, fmt); + instr += ee_vsnprintf(buf, 512, fmt, args); + va_end(args); + + ee_snprintf(instr, 512 - (instr-buf), "\n \nPress [A] + [LEFT] to confirm\nPress [B] or [HOME] to cancel"); + ee_printf_screen_center(buf); + updateScreens(); + + do + { + GFX_waitForEvent(GFX_EVENT_PDC0, true); + + if(hidGetPowerButton(false)) // handle power button + break; + + hidScanInput(); + kDown = hidKeysDown(); + kHeld = hidKeysHeld(); + + if ((kHeld & KEY_A) && (kHeld & KEY_DLEFT)) return true; + if (kDown & (KEY_SHELL)) sleepmode(); + } + while (!(kDown & (KEY_B|KEY_HOME))); + + return false; +} + void outputEndWait(void) { u32 kDown = 0;