diff --git a/include/arm11/menu/menu_util.h b/include/arm11/menu/menu_util.h index 9db047b..f54d27b 100644 --- a/include/arm11/menu/menu_util.h +++ b/include/arm11/menu/menu_util.h @@ -29,6 +29,7 @@ u32 stringGetWidth(const char* str); u32 ee_printf_line_center(const char *const fmt, ...); +u32 ee_printf_screen_center(const char *const fmt, ...); void updateScreens(void); void outputEndWait(void); diff --git a/source/arm11/menu/menu.c b/source/arm11/menu/menu.c index b65dc8b..8d2e141 100644 --- a/source/arm11/menu/menu.c +++ b/source/arm11/menu/menu.c @@ -128,7 +128,8 @@ ee_printf(ESC_SCHEME_ACCENT1 "%s:\n" ESC_RESET, name); ee_printf(ESC_SCHEME_WEAK); - for (char* str = strtok(desc_ww, "\n"); str != NULL; str = strtok(NULL, "\n")) { + for (char* str = strtok(desc_ww, "\n"); str != NULL; str = strtok(NULL, "\n")) + { consoleSetCursor(desc_con, desc_x, desc_y++); ee_printf(str); } diff --git a/source/arm11/menu/menu_fsel.c b/source/arm11/menu/menu_fsel.c index 704dd88..ec42597 100644 --- a/source/arm11/menu/menu_fsel.c +++ b/source/arm11/menu/menu_fsel.c @@ -104,6 +104,7 @@ break; // this should never happen free (dir_buffer[i].fname); + dir_buffer[i].fname = NULL; } } @@ -169,12 +170,14 @@ // open directory s32 dhandle = fOpenDir(path); - if(dhandle < 0) - return -1; + if(dhandle < 0) return -1; FsFileInfo* finfo = (FsFileInfo*) malloc(N_DIR_READ * sizeof(FsFileInfo)); if (!finfo) // out of memory - return -1; + { + fCloseDir(dhandle); + return -1; + } s32 n_read = 0; while((n_read = fReadDir(dhandle, finfo, N_DIR_READ)) != 0) @@ -297,7 +300,7 @@ * @param res_path The selected path will end up here. * @param menu_con Console that the file browser is displayed on. * @param start Starting path (must be a dir). - * @param patter Only files matching this wildcard pattern will be displayed. + * @param pattern Only files matching this wildcard pattern will be displayed. */ bool menuFileSelector(char* res_path, PrintConsole* menu_con, const char* start, const char* pattern) { @@ -329,7 +332,7 @@ s32 dhandle = fOpenDir(res_path); if (dhandle < 0) - panicMsg("Filesystem error"); + panicMsg("Filesystem corruption"); fCloseDir(dhandle); } @@ -342,7 +345,7 @@ s32 index = 0; if(n_entries < 0) - panicMsg("Error reading dir!"); + panicMsg("Filesystem corruption in dir"); // find lastname in listing if (lastname) diff --git a/source/arm11/menu/menu_func.c b/source/arm11/menu/menu_func.c index ab66d68..9989add 100644 --- a/source/arm11/menu/menu_func.c +++ b/source/arm11/menu/menu_func.c @@ -129,7 +129,7 @@ { (void) term_con; - u32 slot = param & 0xF; + const u32 slot = param & 0xF; char* res_path = NULL; char* start = NULL; @@ -147,6 +147,9 @@ res_path = (char*) malloc(256); if (!res_path) panicMsg("Out of memory"); + ee_printf_screen_center("Select a firmware file for slot #%lu.\nPress [HOME] to cancel.", slot + 1); + updateScreens(); + u32 res = 0; if (menuFileSelector(res_path, menu_con, start, "*.firm")) res = (configSetKeyData(KBootOption1 + slot, res_path)) ? 0 : 1; @@ -161,6 +164,7 @@ const u32 y_center = 7; const u32 y_instr = 21; + const u32 slot = param & 0xF; hidScanInput(); u32 kHeld = hidKeysHeld(); @@ -187,10 +191,10 @@ // draw instructions term_con->cursorY = y_instr; ee_printf(ESC_SCHEME_WEAK); - if (configDataExist(KBootOption1Buttons + param)) + if (configDataExist(KBootOption1Buttons + slot)) { char* currentSetting = - (char*) configCopyText(KBootOption1Buttons + param); + (char*) configCopyText(KBootOption1Buttons + slot); if (!currentSetting) panicMsg("Config error"); ee_printf_line_center("Current: %s", currentSetting); free(currentSetting); @@ -229,7 +233,7 @@ } // if we arrive here, we have a button combo - u32 res = (configSetKeyData(KBootOption1Buttons + param, &kHeld)) ? 0 : 1; + u32 res = (configSetKeyData(KBootOption1Buttons + slot, &kHeld)) ? 0 : 1; return res; } @@ -239,12 +243,12 @@ char path_store[256]; char* path; + // select & clear console + consoleSelect(term_con); + consoleClear(); + if (param < 3) // loading from bootslot { - // clear console - consoleSelect(term_con); - consoleClear(); - // check if bootslot exists ee_printf("Checking bootslot...\n"); if (!configDataExist(KBootOption1 + param)) @@ -260,18 +264,14 @@ } else if (param == 0xFF) // user decision { + ee_printf_screen_center("Select a firmware file to boot.\nPress [HOME] to cancel."); + updateScreens(); + path = path_store; if (!menuFileSelector(path, menu_con, NULL, "*.firm")) return 1; } - // clear console - if (param >= 3) - { - consoleSelect(term_con); - consoleClear(); - } - // try load and verify ee_printf("\nLoading %s...\n", path); s32 res = loadVerifyFirm(path, false); diff --git a/source/arm11/menu/menu_util.c b/source/arm11/menu/menu_util.c index 1fc938d..b738315 100644 --- a/source/arm11/menu/menu_util.c +++ b/source/arm11/menu/menu_util.c @@ -153,6 +153,30 @@ return ee_printf("%*.*s%s\n", pad, pad, "", buf); } +u32 ee_printf_screen_center(const char *const fmt, ...) +{ + u32 res = 0; + + char buf[256]; + va_list args; + va_start(args, fmt); + ee_vsnprintf(buf, 256, fmt, args); + va_end(args); + + PrintConsole *con = consoleGet(); + int x = (con->consoleWidth - stringGetWidth(buf)) >> 1; + int y = (con->consoleHeight - stringGetHeight(buf)) >> 1; + + consoleClear(); + for (char* str = strtok(buf, "\n"); str != NULL; str = strtok(NULL, "\n")) + { + consoleSetCursor(con, x, y++); + res += ee_printf(str); + } + + return res; +} + // only intended to be ran when the shell is closed void sleepmode(void) {