diff --git a/source/fileop.cpp b/source/fileop.cpp index 8195427..1638f3c 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -483,32 +483,63 @@ void CreateAppPath(char * origpath) free(path); } +static char *GetExt(char *file) +{ + if(!file) + return NULL; + + char *ext = strrchr(file,'.'); + if(ext != NULL) + { + ext++; + int extlen = strlen(ext); + if(extlen > 5) + return NULL; + } + return ext; +} + bool ParseDirEntries() { if(!dirIter) return false; char filename[MAXPATHLEN]; + char *ext; struct stat filestat; - int i, res; + int i = 0; + int res; - for(i=0; i < 20; i++) + while(i < 20) { res = dirnext(dirIter,filename,&filestat); if(res != 0) break; - if(strcmp(filename,".") == 0) - { - i--; + if(filename[0] == '.' && filename[1] != '.') continue; + + ext = GetExt(filename); + + // don't show the file if it's not a valid ROM + if((filestat.st_mode & _IFDIR) == 0) + { + if(ext == NULL) + continue; + + if( stricmp(p, "agb") != 0 && stricmp(p, "gba") != 0 && + stricmp(p, "bin") != 0 && stricmp(p, "elf") != 0 && + stricmp(p, "mb") != 0 && stricmp(p, "dmg") != 0 && + stricmp(p, "gb") != 0 && stricmp(p, "gbc") != 0 && + stricmp(p, "cgb") != 0 && stricmp(p, "sgb") != 0 && + stricmp(ext, "zip") != 0 && stricmp(ext, "7z") != 0) + continue; } if(!AddBrowserEntry()) { - i=0; parseHalt = true; break; } @@ -530,6 +561,7 @@ bool ParseDirEntries() { StripExt(browserList[browser.numEntries+i].displayname, browserList[browser.numEntries+i].filename); // hide file extension } + i++; } // Sort the file list