diff --git a/source/arm11/menu/menu_fsel.c b/source/arm11/menu/menu_fsel.c index e919824..f0582b8 100644 --- a/source/arm11/menu/menu_fsel.c +++ b/source/arm11/menu/menu_fsel.c @@ -356,6 +356,27 @@ *res_path = '\0'; // root dir if start is NULL if(start) strncpy(res_path, start, 256); + // check res_path, fix if required + char* fname = NULL; + FsFileInfo fno; + if (fStat(res_path, &fno) != FR_OK) + { + *res_path = '\0'; + } + // not a dir -> must be a file + else if (!(fno.fattrib & AM_DIR)) + { + fname = strrchr(res_path, '/'); + if (!fname) + panicMsg("Invalid path"); + *(fname++) = '\0'; + + s32 dhandle = fOpenDir(res_path); + if (dhandle < 0) + panicMsg("Filesystem error"); + fCloseDir(dhandle); + } + bool is_dir = true; // we are not finished while we have a dir in res_path while(is_dir) { @@ -367,6 +388,19 @@ if(n_entries < 0) panicMsg("Error reading dir!"); + // find fname in listing + if (fname) + { + for (s32 i = 0; i < n_entries; i++) + { + if (strncmp(dir_buffer[i].fname, fname, 256) == 0) + { + index = i; + break; + } + } + } + while(true) { // update file browser (on demand) diff --git a/source/arm11/menu/menu_func.c b/source/arm11/menu/menu_func.c index 25e848e..4fc49f7 100644 --- a/source/arm11/menu/menu_func.c +++ b/source/arm11/menu/menu_func.c @@ -89,8 +89,12 @@ u32 menuSetupBootSlot(PrintConsole* con, u32 param) { char res_path[256]; + char* start = NULL; - menuFileSelector(res_path, con, NULL, "*.firm"); + if (configDataExist(KBootOption1 + param)) + start = (char*) configGetData(KBootOption1 + param); + + menuFileSelector(res_path, con, start, "*.firm"); u32 res = (configSetKeyData(KBootOption1 + param, res_path)) ? 0 : 1; writeConfigFile();