From 23e6503a9ff9c7b13e7d68e26dfa14a4fb6fb05b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Nov 2015 17:51:07 -0500 Subject: [PATCH 1/3] [ROM browser] Loop through a string LUT of extensions. --- .../User Interface/Rom Browser Class.cpp | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index 11683afb9..40abf3be7 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -545,8 +545,13 @@ void CRomBrowser::NotificationCB(LPCWSTR Status, CRomBrowser * /*_this*/) 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) { + uint8_t i; + if (FileList.size() > 3000) { return; @@ -555,14 +560,15 @@ void CRomBrowser::AddFileNameToList(strlist & FileList, const stdstr & Directory stdstr Drive, Dir, Name, Extension; File.GetComponents(NULL, &Dir, &Name, &Extension); Extension.ToLower(); - if (Extension == "zip" || Extension == "7z" || Extension == "v64" || Extension == "z64" || - Extension == "n64" || Extension == "rom" || Extension == "jap" || Extension == "pal" || - Extension == "usa" || Extension == "eur" || Extension == "bin") - { - stdstr FileName = Directory + Name + Extension; - FileName.ToLower(); - FileList.push_back(FileName); - } + for (i = 0; i < sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); i++) + { + if (Extension == ROM_extensions[i]) + { + stdstr FileName = Directory + Name + Extension; + FileName.ToLower(); + FileList.push_back(FileName); + } + } } void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, const stdstr & Directory, const char * lpLastRom) @@ -579,6 +585,10 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c do { + uint8_t ext_ID; + const uint8_t exts = sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); +rom_entry_begin: + //TODO: Fix exception on Windows XP (Visual Studio 2010+) //WriteTraceF(TraceDebug,__FUNCTION__ ": 2 %s m_StopRefresh = %d",(LPCSTR)SearchPath,m_StopRefresh); if (m_StopRefresh) { break; } @@ -598,13 +608,14 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c stdstr Extension = SearchPath.GetExtension(); Extension.ToLower(); - if (Extension == "zip" || Extension == "v64" || Extension == "z64" || Extension == "n64" || - Extension == "rom" || Extension == "jap" || Extension == "pal" || Extension == "usa" || - Extension == "eur" || Extension == "bin") - { - AddRomToList(SearchPath, lpLastRom); - continue; - } + for (ext_ID = 0; ext_ID < exts; ext_ID++) + { + if (Extension == ROM_extensions[ext_ID] && Extension != "7z") + { + AddRomToList(SearchPath, lpLastRom); + goto rom_entry_begin; + } + } if (Extension == "7z") { try From a476d4c36e1b06146277aa27e5f064a7796ad360 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Nov 2015 17:55:00 -0500 Subject: [PATCH 2/3] [ROM browser] removed redundant stricmp() inverse checks --- Source/Project64/User Interface/Rom Browser Class.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index 40abf3be7..42660e946 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -652,11 +652,7 @@ rom_entry_begin: _splitpath(FileName.c_str(), drive2, dir2, FileName2, ext2); WriteTraceF(TraceDebug, __FUNCTION__ ": 6 %s", ext2); - if (_stricmp(ext2, ".v64") != 0 && _stricmp(ext2, ".z64") != 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) + if (_stricmp(ext2, ".bin") == 0) { continue; } From a061bdb5dcf5d6b3de8963997f914cb62da480fe Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Nov 2015 22:00:26 -0500 Subject: [PATCH 3/3] fixed extra incursions of ROM extension searches --- .../Project64/User Interface/Rom Browser Class.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Source/Project64/User Interface/Rom Browser Class.cpp b/Source/Project64/User Interface/Rom Browser Class.cpp index 42660e946..5be2f84f8 100644 --- a/Source/Project64/User Interface/Rom Browser Class.cpp +++ b/Source/Project64/User Interface/Rom Browser Class.cpp @@ -567,6 +567,7 @@ void CRomBrowser::AddFileNameToList(strlist & FileList, const stdstr & Directory stdstr FileName = Directory + Name + Extension; FileName.ToLower(); FileList.push_back(FileName); + break; } } } @@ -586,8 +587,8 @@ void CRomBrowser::FillRomList(strlist & FileList, const CPath & BaseDirectory, c do { uint8_t ext_ID; + int8_t new_list_entry = 0; const uint8_t exts = sizeof(ROM_extensions) / sizeof(ROM_extensions[0]); -rom_entry_begin: //TODO: Fix exception on Windows XP (Visual Studio 2010+) //WriteTraceF(TraceDebug,__FUNCTION__ ": 2 %s m_StopRefresh = %d",(LPCSTR)SearchPath,m_StopRefresh); @@ -612,10 +613,16 @@ rom_entry_begin: { if (Extension == ROM_extensions[ext_ID] && Extension != "7z") { - AddRomToList(SearchPath, lpLastRom); - goto rom_entry_begin; + new_list_entry = 1; + break; } } + if (new_list_entry) + { + AddRomToList(SearchPath, lpLastRom); + continue; + } + if (Extension == "7z") { try