mGUI: Remmeber name and position of last loaded game
Vicki Pfau vi@endrift.com
Fri, 07 Jun 2019 12:26:40 -0700
5 files changed,
25 insertions(+),
13 deletions(-)
M
CHANGES
→
CHANGES
@@ -54,6 +54,7 @@ - Qt: Improve sync code
- Switch: Dynamic display resizing - Qt: Make mute menu option also toggle fast-forward mute (fixes mgba.io/i/1424) - Vita: L2/R2 and L3/R3 can now be mapped on PSTV (fixes mgba.io/i/1292) + - mGUI: Remember name and position of last loaded game 0.7.2: (2019-05-25) Emulation fixes:
M
include/mgba-util/gui/file-select.h
→
include/mgba-util/gui/file-select.h
@@ -14,7 +14,7 @@ #include <mgba-util/gui.h>
struct VFile; -bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*)); +bool GUISelectFile(struct GUIParams*, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*), const char* preselect); CXX_GUARD_END
M
src/feature/gui/gui-config.c
→
src/feature/gui/gui-config.c
@@ -303,7 +303,7 @@ continue;
} if (!strcmp(item->data, "gba.bios")) { // TODO: show box if failed - if (!GUISelectFile(&runner->params, gbaBiosPath, sizeof(gbaBiosPath), _biosNamed, GBAIsBIOS)) { + if (!GUISelectFile(&runner->params, gbaBiosPath, sizeof(gbaBiosPath), _biosNamed, GBAIsBIOS, NULL)) { gbaBiosPath[0] = '\0'; } continue;@@ -311,21 +311,21 @@ }
#ifdef M_CORE_GB if (!strcmp(item->data, "gb.bios")) { // TODO: show box if failed - if (!GUISelectFile(&runner->params, gbBiosPath, sizeof(gbBiosPath), _biosNamed, GBIsBIOS)) { + if (!GUISelectFile(&runner->params, gbBiosPath, sizeof(gbBiosPath), _biosNamed, GBIsBIOS, NULL)) { gbBiosPath[0] = '\0'; } continue; } if (!strcmp(item->data, "gbc.bios")) { // TODO: show box if failed - if (!GUISelectFile(&runner->params, gbcBiosPath, sizeof(gbcBiosPath), _biosNamed, GBIsBIOS)) { + if (!GUISelectFile(&runner->params, gbcBiosPath, sizeof(gbcBiosPath), _biosNamed, GBIsBIOS, NULL)) { gbcBiosPath[0] = '\0'; } continue; } if (!strcmp(item->data, "sgb.bios")) { // TODO: show box if failed - if (!GUISelectFile(&runner->params, sgbBiosPath, sizeof(sgbBiosPath), _biosNamed, GBIsBIOS)) { + if (!GUISelectFile(&runner->params, sgbBiosPath, sizeof(sgbBiosPath), _biosNamed, GBIsBIOS, NULL)) { sgbBiosPath[0] = '\0'; } continue;
M
src/feature/gui/gui-runner.c
→
src/feature/gui/gui-runner.c
@@ -628,10 +628,18 @@ }
} while (true) { char path[PATH_MAX]; - if (!GUISelectFile(&runner->params, path, sizeof(path), _testExtensions, NULL)) { + const char* preselect = mCoreConfigGetValue(&runner->config, "lastGame"); + if (preselect) { + preselect = strrchr(preselect, '/'); + } + if (preselect) { + ++preselect; + } + if (!GUISelectFile(&runner->params, path, sizeof(path), _testExtensions, NULL, preselect)) { break; } mCoreConfigSetValue(&runner->config, "lastDirectory", runner->params.currentPath); + mCoreConfigSetValue(&runner->config, "lastGame", path); mCoreConfigSave(&runner->config); mGUIRun(runner, path); }
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -47,7 +47,7 @@ static int _strpcmp(const void* a, const void* b) {
return strcasecmp(((const struct GUIMenuItem*) a)->title, ((const struct GUIMenuItem*) b)->title); } -static bool _refreshDirectory(struct GUIParams* params, const char* currentPath, struct GUIMenuItemList* currentFiles, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*)) { +static bool _refreshDirectory(struct GUIParams* params, const char* currentPath, struct GUIMenuItemList* currentFiles, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*), const char* preselect) { _cleanFiles(currentFiles); struct VDir* dir = VDirOpen(currentPath);@@ -144,6 +144,9 @@ if (failed) {
free((char*) testItem->title); GUIMenuItemListShift(currentFiles, item, 1); } else { + if (preselect && strncmp(testItem->title, preselect, PATH_MAX) == 0) { + params->fileIndex = item; + } ++item; } }@@ -152,14 +155,14 @@
return true; } -bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*)) { +bool GUISelectFile(struct GUIParams* params, char* outPath, size_t outLen, bool (*filterName)(const char* name), bool (*filterContents)(struct VFile*), const char* preselect) { struct GUIMenu menu = { .title = "Select file", .subtitle = params->currentPath, - .index = params->fileIndex, }; GUIMenuItemListInit(&menu.items, 0); - _refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents); + _refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, preselect); + menu.index = params->fileIndex; while (true) { struct GUIMenuItem* item;@@ -174,7 +177,7 @@ if (strncmp(params->currentPath, params->basePath, PATH_MAX) == 0) {
continue; } _upDirectory(params->currentPath); - if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents)) { + if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, NULL)) { break; } } else {@@ -187,7 +190,7 @@ snprintf(outPath, outLen, "%s%s%s", params->currentPath, sep, item->title);
struct GUIMenuItemList newFiles; GUIMenuItemListInit(&newFiles, 0); - if (!_refreshDirectory(params, outPath, &newFiles, filterName, filterContents)) { + if (!_refreshDirectory(params, outPath, &newFiles, filterName, filterContents, NULL)) { _cleanFiles(&newFiles); GUIMenuItemListDeinit(&newFiles); _cleanFiles(&menu.items);@@ -208,7 +211,7 @@ if (strncmp(params->currentPath, params->basePath, PATH_MAX) == 0) {
break; } _upDirectory(params->currentPath); - if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents)) { + if (!_refreshDirectory(params, params->currentPath, &menu.items, filterName, filterContents, NULL)) { break; } params->fileIndex = 0;