diff --git a/CHANGES b/CHANGES index 42fea400e..847865d26 100644 --- a/CHANGES +++ b/CHANGES @@ -22,6 +22,7 @@ Other fixes: - GBA: Fix getting game info for multiboot ROMs - GBA Core: Fix booting into BIOS when skip BIOS is enabled - GBA Hardware: Fix loading states unconditionally overwriting GPIO memory + - mGUI: Load parent directory if last used directory is missing (fixes mgba.io/i/3379) - Qt: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560) - Qt: Fix potential crash when configuring shortcuts Misc: diff --git a/include/mgba-util/gui/menu.h b/include/mgba-util/gui/menu.h index 399ddd8c3..4a1c3651a 100644 --- a/include/mgba-util/gui/menu.h +++ b/include/mgba-util/gui/menu.h @@ -10,9 +10,12 @@ CXX_GUARD_START +#include <mgba/core/log.h> #include <mgba-util/gui.h> #include <mgba-util/vector.h> +mLOG_DECLARE_CATEGORY(GUI_MENU); + #define GUI_V_V (struct GUIVariant) { .type = GUI_VARIANT_VOID } #define GUI_V_U(U) (struct GUIVariant) { .type = GUI_VARIANT_UNSIGNED, .v.u = (U) } #define GUI_V_I(I) (struct GUIVariant) { .type = GUI_VARIANT_INT, .v.i = (I) } diff --git a/src/util/gui/file-select.c b/src/util/gui/file-select.c index 0cdfba35d..f13668c3f 100644 --- a/src/util/gui/file-select.c +++ b/src/util/gui/file-select.c @@ -163,7 +163,16 @@ bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool .subtitle = params->currentPath, }; GUIMenuItemListInit(&menu.items, 0); - _refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, preselect); + while (true) { + if (_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, preselect)) { + break; + } + if (strncmp(params->currentPath, params->basePath, PATH_MAX) == 0 || !params->currentPath[0]) { + mLOG(GUI_MENU, ERROR, "Failed to load base directory"); + return false; + } + _upDirectory(params->currentPath); + } menu.index = params->fileIndex; while (true) { diff --git a/src/util/gui/menu.c b/src/util/gui/menu.c index f0c624f17..2109bf8e1 100644 --- a/src/util/gui/menu.c +++ b/src/util/gui/menu.c @@ -17,6 +17,8 @@ DEFINE_VECTOR(GUIMenuItemList, struct GUIMenuItem); DEFINE_VECTOR(GUIMenuSavedList, struct GUIMenuSavedState); +mLOG_DEFINE_CATEGORY(GUI_MENU, "GUI Menu", "gui.menu"); + void _itemNext(struct GUIMenuItem* item, bool wrap) { if (wrap || item->state < item->nStates - 1) { unsigned oldState = item->state;