Merge pull request #754 from cxd4/extensions-cleanup

Simplify ROM browser shell file extensions comparisons.
This commit is contained in:
zilmar 2015-11-14 15:35:41 +11:00
commit 5d0c361b39
1 changed files with 34 additions and 20 deletions

View File

@ -545,8 +545,13 @@ void CRomBrowser::NotificationCB(LPCWSTR Status, CRomBrowser * /*_this*/)
g_Notify->DisplayMessage(5, Status); g_Notify->DisplayMessage(5, Status);
} }
static const char* ROM_extensions[] = {
"zip", "7z", "v64", "z64", "n64", "rom", "jap", "pal", "usa", "eur", "bin",
};
void CRomBrowser::AddFileNameToList(strlist & FileList, const stdstr & Directory, CPath & File) void CRomBrowser::AddFileNameToList(strlist & FileList, const stdstr & Directory, CPath & File)
{ {
uint8_t i;
if (FileList.size() > 3000) if (FileList.size() > 3000)
{ {
return; return;
@ -555,13 +560,15 @@ void CRomBrowser::AddFileNameToList(strlist & FileList, const stdstr & Directory
stdstr Drive, Dir, Name, Extension; stdstr Drive, Dir, Name, Extension;
File.GetComponents(NULL, &Dir, &Name, &Extension); File.GetComponents(NULL, &Dir, &Name, &Extension);
Extension.ToLower(); Extension.ToLower();
if (Extension == "zip" || Extension == "7z" || Extension == "v64" || Extension == "z64" || for (i = 0; i < sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); i++)
Extension == "n64" || Extension == "rom" || Extension == "jap" || Extension == "pal" || {
Extension == "usa" || Extension == "eur" || Extension == "bin") if (Extension == ROM_extensions[i])
{ {
stdstr FileName = Directory + Name + Extension; stdstr FileName = Directory + Name + Extension;
FileName.ToLower(); FileName.ToLower();
FileList.push_back(FileName); FileList.push_back(FileName);
break;
}
} }
} }
@ -579,6 +586,10 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c
do do
{ {
uint8_t ext_ID;
int8_t new_list_entry = 0;
const uint8_t exts = sizeof(ROM_extensions) / sizeof(ROM_extensions[0]);
//TODO: Fix exception on Windows XP (Visual Studio 2010+) //TODO: Fix exception on Windows XP (Visual Studio 2010+)
//WriteTraceF(TraceDebug,__FUNCTION__ ": 2 %s m_StopRefresh = %d",(LPCSTR)SearchPath,m_StopRefresh); //WriteTraceF(TraceDebug,__FUNCTION__ ": 2 %s m_StopRefresh = %d",(LPCSTR)SearchPath,m_StopRefresh);
if (m_StopRefresh) { break; } if (m_StopRefresh) { break; }
@ -598,13 +609,20 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c
stdstr Extension = SearchPath.GetExtension(); stdstr Extension = SearchPath.GetExtension();
Extension.ToLower(); Extension.ToLower();
if (Extension == "zip" || Extension == "v64" || Extension == "z64" || Extension == "n64" || for (ext_ID = 0; ext_ID < exts; ext_ID++)
Extension == "rom" || Extension == "jap" || Extension == "pal" || Extension == "usa" || {
Extension == "eur" || Extension == "bin") if (Extension == ROM_extensions[ext_ID] && Extension != "7z")
{
new_list_entry = 1;
break;
}
}
if (new_list_entry)
{ {
AddRomToList(SearchPath, lpLastRom); AddRomToList(SearchPath, lpLastRom);
continue; continue;
} }
if (Extension == "7z") if (Extension == "7z")
{ {
try try
@ -641,11 +659,7 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c
_splitpath(FileName.c_str(), drive2, dir2, FileName2, ext2); _splitpath(FileName.c_str(), drive2, dir2, FileName2, ext2);
WriteTraceF(TraceDebug, __FUNCTION__ ": 6 %s", ext2); WriteTraceF(TraceDebug, __FUNCTION__ ": 6 %s", ext2);
if (_stricmp(ext2, ".v64") != 0 && _stricmp(ext2, ".z64") != 0 && if (_stricmp(ext2, ".bin") == 0)
_stricmp(ext2, ".n64") != 0 && _stricmp(ext2, ".rom") != 0 &&
_stricmp(ext2, ".jap") != 0 && _stricmp(ext2, ".pal") != 0 &&
_stricmp(ext2, ".usa") != 0 && _stricmp(ext2, ".eur") != 0 &&
_stricmp(ext2, ".bin") == 0)
{ {
continue; continue;
} }