1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-02-08 08:51:25 +00:00

Gracefully handle more than 8 directories in the root dir

This commit is contained in:
Till Harbaum
2016-05-10 14:38:58 +02:00
parent e5a83da6df
commit 24fc9b1e61

40
menu.c
View File

@@ -132,33 +132,47 @@ void SelectFile(char* pFileExt, unsigned char Options, unsigned char MenuSelect,
// for 8 bit cores try to
if((user_io_core_type() == CORE_TYPE_8BIT) && chdir) {
int n;
user_io_create_config_name(s);
// try to change into subdir named after the core
strcpy(s+8, " ");
iprintf("Trying to open work dir \"%s\"\n", s);
ScanDirectory(SCAN_INIT, "", SCAN_DIR | FIND_DIR);
// no return flag :(, so scan 10 times blindly...
for(n=0; n<10; n++) {
int i;
char res = 0;
for(i=0;i<nDirEntries;i++) {
//iprintf("cmp %11s %11s\n", DirEntry[i].Name, s);
// no return flag :(, so scan 10 times blindly...
for(;;) {
int i;
char res = 0;
unsigned short last_StartCluster = DirEntry[0].StartCluster;
if(strncasecmp(DirEntry[i].Name, s, 11) == 0) {
ChangeDirectory(DirEntry[i].StartCluster + (fat32 ? (DirEntry[i].HighCluster & 0x0FFF) << 16 : 0));
res = 1;
for(i=0;i<nDirEntries;i++) {
//iprintf("cmp %11s %11s\n", DirEntry[i].Name, s);
if(strncasecmp(DirEntry[i].Name, s, 11) == 0) {
ChangeDirectory(DirEntry[i].StartCluster + (fat32 ? (DirEntry[i].HighCluster & 0x0FFF) << 16 : 0));
res = 1;
break;
}
}
// found directory: stop searching
if(res) break;
iSelectedEntry = MAXDIRENTRIES -1;
ScanDirectory(SCAN_NEXT_PAGE, "", SCAN_DIR | FIND_DIR);
// last search returned less than 8 entries: Stop searching since
// there sure aren't more
if(nDirEntries != 8)
break;
// get next 8 directory entries
iSelectedEntry = MAXDIRENTRIES -1;
ScanDirectory(SCAN_NEXT_PAGE, "", SCAN_DIR | FIND_DIR);
// if 8 entries are returned check if the start cluster of the first entry
// is the same as the first one in the previous list. If it is, then this
// is the same list and we are done
if((nDirEntries == 8) && (DirEntry[0].StartCluster == last_StartCluster))
break;
}
}
ScanDirectory(SCAN_INIT, pFileExt, Options);
}