mirror of https://github.com/mgba-emu/mgba.git
GUI: Allow canceling out of file refresh
This commit is contained in:
parent
f3b4855b06
commit
dd3b56eb7a
|
@ -15,7 +15,7 @@ DECLARE_VECTOR(FileList, char*);
|
||||||
DEFINE_VECTOR(FileList, char*);
|
DEFINE_VECTOR(FileList, char*);
|
||||||
|
|
||||||
#define ITERATION_SIZE 5
|
#define ITERATION_SIZE 5
|
||||||
#define SCANNING_THRESHOLD 20
|
#define SCANNING_THRESHOLD 15
|
||||||
|
|
||||||
static void _cleanFiles(struct FileList* currentFiles) {
|
static void _cleanFiles(struct FileList* currentFiles) {
|
||||||
size_t size = FileListSize(currentFiles);
|
size_t size = FileListSize(currentFiles);
|
||||||
|
@ -58,7 +58,11 @@ static bool _refreshDirectory(const struct GUIParams* params, const char* curren
|
||||||
struct VDirEntry* de;
|
struct VDirEntry* de;
|
||||||
while ((de = dir->listNext(dir))) {
|
while ((de = dir->listNext(dir))) {
|
||||||
++i;
|
++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();
|
params->drawStart();
|
||||||
GUIFontPrintf(params->font, 0, GUIFontHeight(params->font), GUI_TEXT_LEFT, 0xFFFFFFFF, "%s", currentPath);
|
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)");
|
GUIFontPrintf(params->font, 0, GUIFontHeight(params->font) * 2, GUI_TEXT_LEFT, 0xFFFFFFFF, "(scanning)");
|
||||||
|
@ -147,14 +151,14 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
|
||||||
++start;
|
++start;
|
||||||
}
|
}
|
||||||
if (newInput & (1 << GUI_INPUT_CANCEL)) {
|
if (newInput & (1 << GUI_INPUT_CANCEL)) {
|
||||||
_cleanFiles(¤tFiles);
|
break;
|
||||||
FileListDeinit(¤tFiles);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
if (newInput & (1 << GUI_INPUT_SELECT)) {
|
if (newInput & (1 << GUI_INPUT_SELECT)) {
|
||||||
if (fileIndex == 0) {
|
if (fileIndex == 0) {
|
||||||
_upDirectory(currentPath);
|
_upDirectory(currentPath);
|
||||||
_refreshDirectory(params, currentPath, ¤tFiles, filter);
|
if (!_refreshDirectory(params, currentPath, ¤tFiles, filter)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
size_t len = strlen(currentPath);
|
size_t len = strlen(currentPath);
|
||||||
const char* sep = PATH_SEP;
|
const char* sep = PATH_SEP;
|
||||||
|
@ -163,20 +167,32 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
|
||||||
}
|
}
|
||||||
snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex));
|
snprintf(outPath, outLen, "%s%s%s", currentPath, sep, *FileListGetPointer(¤tFiles, fileIndex));
|
||||||
if (!_refreshDirectory(params, outPath, ¤tFiles, filter)) {
|
if (!_refreshDirectory(params, outPath, ¤tFiles, filter)) {
|
||||||
|
struct VFile* vf = VFileOpen(currentPath, O_RDONLY);
|
||||||
|
if (!vf) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!filter || filter(vf)) {
|
||||||
|
vf->close(vf);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
vf->close(vf);
|
||||||
|
_upDirectory(currentPath);
|
||||||
|
if (!_refreshDirectory(params, currentPath, ¤tFiles, filter)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
strncpy(currentPath, outPath, outLen);
|
strncpy(currentPath, outPath, outLen);
|
||||||
}
|
}
|
||||||
fileIndex = 0;
|
fileIndex = 0;
|
||||||
}
|
}
|
||||||
if (newInput & (1 << GUI_INPUT_BACK)) {
|
if (newInput & (1 << GUI_INPUT_BACK)) {
|
||||||
if (strncmp(currentPath, basePath, outLen) == 0) {
|
if (strncmp(currentPath, basePath, outLen) == 0) {
|
||||||
_cleanFiles(¤tFiles);
|
break;
|
||||||
FileListDeinit(¤tFiles);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
_upDirectory(currentPath);
|
_upDirectory(currentPath);
|
||||||
_refreshDirectory(params, currentPath, ¤tFiles, filter);
|
if (!_refreshDirectory(params, currentPath, ¤tFiles, filter)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
fileIndex = 0;
|
fileIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,4 +218,8 @@ bool selectFile(const struct GUIParams* params, const char* basePath, char* outP
|
||||||
|
|
||||||
params->drawEnd();
|
params->drawEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_cleanFiles(¤tFiles);
|
||||||
|
FileListDeinit(¤tFiles);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue