From a3a081f8253f4f1b39e1d4d95799406be93a0597 Mon Sep 17 00:00:00 2001 From: dborth Date: Mon, 12 Jul 2010 06:10:00 +0000 Subject: [PATCH] hide non-ROM files --- source/fileop.cpp | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/source/fileop.cpp b/source/fileop.cpp index 238a74a..477c6f6 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -484,27 +484,57 @@ 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, "nes") != 0 && stricmp(p, "fds") != 0 && + stricmp(p, "nsf") != 0 && stricmp(p, "unf") != 0 && + stricmp(p, "nez") != 0 && stricmp(p, "unif") != 0 && + stricmp(ext, "zip") != 0 && stricmp(ext, "7z") != 0) + continue; } if(!AddBrowserEntry())