all repos — mgba @ dd3b56eb7a3d6fc30f59267bb3b444b611380f8b

mGBA Game Boy Advance Emulator

GUI: Allow canceling out of file refresh
Jeffrey Pfau jeffrey@endrift.com
Sat, 29 Aug 2015 22:59:22 -0700
commit

dd3b56eb7a3d6fc30f59267bb3b444b611380f8b

parent

f3b4855b06a69b60dbf4d134b0326b42b5e29831

1 files changed, 31 insertions(+), 11 deletions(-)

jump to
M src/util/gui/file-select.csrc/util/gui/file-select.c

@@ -15,7 +15,7 @@ DECLARE_VECTOR(FileList, char*);

DEFINE_VECTOR(FileList, char*); #define ITERATION_SIZE 5 -#define SCANNING_THRESHOLD 20 +#define SCANNING_THRESHOLD 15 static void _cleanFiles(struct FileList* currentFiles) { size_t size = FileListSize(currentFiles);

@@ -58,7 +58,11 @@ size_t i = 0;

struct VDirEntry* de; while ((de = dir->listNext(dir))) { ++i; - if (i == SCANNING_THRESHOLD) { + if (i % SCANNING_THRESHOLD == SCANNING_THRESHOLD - 1) { + int input = params->pollInput(); + if (input & (1 << GUI_INPUT_CANCEL)) { + return false; + } params->drawStart(); GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_TEXT_LEFT, 0xFFFFFFFF, "%s", currentPath); GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning)");

@@ -147,14 +151,14 @@ while ((fileIndex - start + 4) * GUIFontHeight(params->font) > params->height) {

++start; } if (newInput & (1 << GUI_INPUT_CANCEL)) { - _cleanFiles(&currentFiles); - FileListDeinit(&currentFiles); - return false; + break; } if (newInput & (1 << GUI_INPUT_SELECT)) { if (fileIndex == 0) { _upDirectory(currentPath); - _refreshDirectory(params, currentPath, &currentFiles, filter); + if (!_refreshDirectory(params, currentPath, &currentFiles, filter)) { + break; + } } else { size_t len = strlen(currentPath); const char* sep = PATH_SEP;

@@ -163,7 +167,19 @@ sep = "";

} snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(&currentFiles, fileIndex)); if (!_refreshDirectory(params, outPath, &currentFiles, filter)) { - return true; + struct VFile* vf = VFileOpen(currentPath, O_RDONLY); + if (!vf) { + break; + } + if (!filter || filter(vf)) { + vf->close(vf); + return true; + } + vf->close(vf); + _upDirectory(currentPath); + if (!_refreshDirectory(params, currentPath, &currentFiles, filter)) { + break; + } } strncpy(currentPath, outPath, outLen); }

@@ -171,12 +187,12 @@ fileIndex = 0;

} if (newInput & (1 << GUI_INPUT_BACK)) { if (strncmp(currentPath, basePath, outLen) == 0) { - _cleanFiles(&currentFiles); - FileListDeinit(&currentFiles); - return false; + break; } _upDirectory(currentPath); - _refreshDirectory(params, currentPath, &currentFiles, filter); + if (!_refreshDirectory(params, currentPath, &currentFiles, filter)) { + break; + } fileIndex = 0; }

@@ -202,4 +218,8 @@ y += GUIFontHeight(params->font) * 2;

params->drawEnd(); } + + _cleanFiles(&currentFiles); + FileListDeinit(&currentFiles); + return false; }