GUI: More detailed scanning information
Jeffrey Pfau jeffrey@endrift.com
Sat, 05 Sep 2015 00:51:26 -0700
1 files changed,
44 insertions(+),
12 deletions(-)
jump to
M
src/util/gui/file-select.c
→
src/util/gui/file-select.c
@@ -12,7 +12,13 @@
#include <stdlib.h> #define ITERATION_SIZE 5 -#define SCANNING_THRESHOLD 20 +#define SCANNING_THRESHOLD_1 50 +#ifdef _3DS +// 3DS is slooooow at opening files +#define SCANNING_THRESHOLD_2 10 +#else +#define SCANNING_THRESHOLD_2 50 +#endif static void _cleanFiles(struct GUIMenuItemList* currentFiles) { size_t size = GUIMenuItemListSize(currentFiles);@@ -52,10 +58,11 @@ return false;
} *GUIMenuItemListAppend(currentFiles) = (struct GUIMenuItem) { .title = "(Up)" }; size_t i = 0; + size_t items = 0; struct VDirEntry* de; while ((de = dir->listNext(dir))) { ++i; - if (!(i % SCANNING_THRESHOLD)) { + if (!(i % SCANNING_THRESHOLD_1)) { uint32_t input = 0; GUIPollInput(params, &input, 0); if (input & (1 << GUI_INPUT_CANCEL)) {@@ -67,7 +74,7 @@ if (params->guiPrepare) {
params->guiPrepare(); } 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 item %lu)", i); + GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning for items: %lu)", i); if (params->guiFinish) { params->guiFinish(); }@@ -77,21 +84,46 @@ const char* name = de->name(de);
if (name[0] == '.') { continue; } - if (de->type(de) == VFS_FILE) { - struct VFile* vf = dir->openFile(dir, name, O_RDONLY); - if (!vf) { - continue; + *GUIMenuItemListAppend(currentFiles) = (struct GUIMenuItem) { .title = strdup(name) }; + ++items; + } + qsort(GUIMenuItemListGetPointer(currentFiles, 1), GUIMenuItemListSize(currentFiles) - 1, sizeof(struct GUIMenuItem), _strpcmp); + i = 0; + size_t item = 0; + while (item < GUIMenuItemListSize(currentFiles)) { + ++i; + if (!(i % SCANNING_THRESHOLD_2)) { + uint32_t input = 0; + GUIPollInput(params, &input, 0); + if (input & (1 << GUI_INPUT_CANCEL)) { + return false; } - if (!filter || filter(vf)) { - *GUIMenuItemListAppend(currentFiles) = (struct GUIMenuItem) { .title = strdup(name) }; + + params->drawStart(); + if (params->guiPrepare) { + params->guiPrepare(); } - vf->close(vf); + 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 item %lu of %lu)", i, items); + if (params->guiFinish) { + params->guiFinish(); + } + params->drawEnd(); + } + struct VFile* vf = dir->openFile(dir, GUIMenuItemListGetPointer(currentFiles, item)->title, O_RDONLY); + if (!vf) { + ++item; + continue; + } + if (filter && !filter(vf)) { + free(GUIMenuItemListGetPointer(currentFiles, item)->title); + GUIMenuItemListShift(currentFiles, item, 1); } else { - *GUIMenuItemListAppend(currentFiles) = (struct GUIMenuItem) { .title = strdup(name) }; + ++item; } + vf->close(vf); } dir->close(dir); - qsort(GUIMenuItemListGetPointer(currentFiles, 1), GUIMenuItemListSize(currentFiles) - 1, sizeof(struct GUIMenuItem), _strpcmp); return true; }