FileSearch: Don't use RegExs, just do string comparisons.
Nothing used the RegEx feature of FileSearch, and GCC < 4.9 doesn't support C++11 RegEx properly, so get rid of it.
This commit is contained in:
parent
79bf93996f
commit
5643fe5d1f
|
@ -2,13 +2,8 @@
|
|||
// Licensed under GPLv2+
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#if !__clang__ && __GNUC__ == 4 && __GNUC_MINOR__ < 9
|
||||
#error <regex> is broken in GCC < 4.9; please upgrade
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <regex>
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/FileSearch.h"
|
||||
|
@ -37,20 +32,17 @@ static std::vector<std::string> FileSearchWithTest(const std::vector<std::string
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> DoFileSearch(const std::vector<std::string>& globs, const std::vector<std::string>& directories, bool recursive)
|
||||
std::vector<std::string> DoFileSearch(const std::vector<std::string>& exts, const std::vector<std::string>& directories, bool recursive)
|
||||
{
|
||||
std::string regex_str = "^(";
|
||||
for (const auto& str : globs)
|
||||
{
|
||||
if (regex_str.size() != 2)
|
||||
regex_str += "|";
|
||||
// convert glob to regex
|
||||
regex_str += std::regex_replace(std::regex_replace(str, std::regex("\\."), "\\."), std::regex("\\*"), ".*");
|
||||
}
|
||||
regex_str += ")$";
|
||||
std::regex regex(regex_str, std::regex_constants::icase);
|
||||
bool accept_all = std::find(exts.begin(), exts.end(), "") != exts.end();
|
||||
return FileSearchWithTest(directories, recursive, [&](const File::FSTEntry& entry) {
|
||||
return std::regex_match(entry.virtualName, regex);
|
||||
if (accept_all)
|
||||
return true;
|
||||
std::string name = entry.virtualName;
|
||||
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||
return std::any_of(exts.begin(), exts.end(), [&](const std::string& ext) {
|
||||
return name.length() >= ext.length() && name.compare(name.length() - ext.length(), ext.length(), ext) == 0;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::vector<std::string> DoFileSearch(const std::vector<std::string>& globs, const std::vector<std::string>& directories, bool recursive = false);
|
||||
std::vector<std::string> DoFileSearch(const std::vector<std::string>& exts, const std::vector<std::string>& directories, bool recursive = false);
|
||||
std::vector<std::string> FindSubdirectories(const std::vector<std::string>& directories, bool recursive);
|
||||
|
|
|
@ -153,7 +153,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, int slot, u
|
|||
hdrfile.ReadBytes(&m_hdr, BLOCK_SIZE);
|
||||
}
|
||||
|
||||
std::vector<std::string> rFilenames = DoFileSearch({"*.gci"}, {m_SaveDirectory});
|
||||
std::vector<std::string> rFilenames = DoFileSearch({".gci"}, {m_SaveDirectory});
|
||||
|
||||
if (rFilenames.size() > 112)
|
||||
{
|
||||
|
|
|
@ -91,21 +91,21 @@ void DGameTracker::ScanForGames()
|
|||
std::vector<std::string> exts;
|
||||
if (SConfig::GetInstance().m_ListGC)
|
||||
{
|
||||
exts.push_back("*.gcm");
|
||||
exts.push_back("*.gcz");
|
||||
exts.push_back(".gcm");
|
||||
exts.push_back(".gcz");
|
||||
}
|
||||
if (SConfig::GetInstance().m_ListWii || SConfig::GetInstance().m_ListGC)
|
||||
{
|
||||
exts.push_back("*.iso");
|
||||
exts.push_back("*.ciso");
|
||||
exts.push_back("*.wbfs");
|
||||
exts.push_back(".iso");
|
||||
exts.push_back(".ciso");
|
||||
exts.push_back(".wbfs");
|
||||
}
|
||||
if (SConfig::GetInstance().m_ListWad)
|
||||
exts.push_back("*.wad");
|
||||
exts.push_back(".wad");
|
||||
if (SConfig::GetInstance().m_ListElfDol)
|
||||
{
|
||||
exts.push_back("*.dol");
|
||||
exts.push_back("*.elf");
|
||||
exts.push_back(".dol");
|
||||
exts.push_back(".elf");
|
||||
}
|
||||
|
||||
auto rFilenames = DoFileSearch(exts, SConfig::GetInstance().m_ISOFolder, SConfig::GetInstance().m_RecursiveISOFolder);
|
||||
|
|
|
@ -162,7 +162,7 @@ void InterfaceConfigPane::LoadGUIValues()
|
|||
|
||||
void InterfaceConfigPane::LoadThemes()
|
||||
{
|
||||
auto sv = DoFileSearch({"*"}, {
|
||||
auto sv = DoFileSearch({""}, {
|
||||
File::GetUserPath(D_THEMES_IDX),
|
||||
File::GetSysDirectory() + THEMES_DIR
|
||||
}, /*recursive*/ false);
|
||||
|
|
|
@ -1956,7 +1956,7 @@ void CFrame::GameListChanged(wxCommandEvent& event)
|
|||
SConfig::GetInstance().m_ListDrives = event.IsChecked();
|
||||
break;
|
||||
case IDM_PURGE_CACHE:
|
||||
std::vector<std::string> rFilenames = DoFileSearch({"*.cache"}, {File::GetUserPath(D_CACHE_IDX)});
|
||||
std::vector<std::string> rFilenames = DoFileSearch({".cache"}, {File::GetUserPath(D_CACHE_IDX)});
|
||||
|
||||
for (const std::string& rFilename : rFilenames)
|
||||
{
|
||||
|
|
|
@ -465,20 +465,20 @@ void CGameListCtrl::ScanForISOs()
|
|||
std::vector<std::string> Extensions;
|
||||
|
||||
if (SConfig::GetInstance().m_ListGC)
|
||||
Extensions.push_back("*.gcm");
|
||||
Extensions.push_back(".gcm");
|
||||
if (SConfig::GetInstance().m_ListWii || SConfig::GetInstance().m_ListGC)
|
||||
{
|
||||
Extensions.push_back("*.iso");
|
||||
Extensions.push_back("*.ciso");
|
||||
Extensions.push_back("*.gcz");
|
||||
Extensions.push_back("*.wbfs");
|
||||
Extensions.push_back(".iso");
|
||||
Extensions.push_back(".ciso");
|
||||
Extensions.push_back(".gcz");
|
||||
Extensions.push_back(".wbfs");
|
||||
}
|
||||
if (SConfig::GetInstance().m_ListWad)
|
||||
Extensions.push_back("*.wad");
|
||||
Extensions.push_back(".wad");
|
||||
if (SConfig::GetInstance().m_ListElfDol)
|
||||
{
|
||||
Extensions.push_back("*.dol");
|
||||
Extensions.push_back("*.elf");
|
||||
Extensions.push_back(".dol");
|
||||
Extensions.push_back(".elf");
|
||||
}
|
||||
|
||||
auto rFilenames = DoFileSearch(Extensions, SConfig::GetInstance().m_ISOFolder, SConfig::GetInstance().m_RecursiveISOFolder);
|
||||
|
|
|
@ -172,7 +172,7 @@ void InputConfigDialog::UpdateProfileComboBox()
|
|||
pname += PROFILES_PATH;
|
||||
pname += m_config.profile_name;
|
||||
|
||||
std::vector<std::string> sv = DoFileSearch({"*.ini"}, {pname});
|
||||
std::vector<std::string> sv = DoFileSearch({".ini"}, {pname});
|
||||
|
||||
wxArrayString strs;
|
||||
for (const std::string& filename : sv)
|
||||
|
|
|
@ -99,7 +99,7 @@ std::string VideoBackend::GetDisplayName() const
|
|||
|
||||
static std::vector<std::string> GetShaders(const std::string &sub_dir = "")
|
||||
{
|
||||
std::vector<std::string> paths = DoFileSearch({"*.glsl"}, {
|
||||
std::vector<std::string> paths = DoFileSearch({".glsl"}, {
|
||||
File::GetUserPath(D_SHADERS_IDX) + sub_dir,
|
||||
File::GetSysDirectory() + SHADERS_DIR DIR_SEP + sub_dir
|
||||
});
|
||||
|
|
|
@ -84,11 +84,11 @@ void HiresTexture::Update()
|
|||
std::string szDir = StringFromFormat("%s%s", File::GetUserPath(D_HIRESTEXTURES_IDX).c_str(), gameCode.c_str());
|
||||
|
||||
std::vector<std::string> Extensions {
|
||||
"*.png",
|
||||
"*.bmp",
|
||||
"*.tga",
|
||||
"*.dds",
|
||||
"*.jpg" // Why not? Could be useful for large photo-like textures
|
||||
".png",
|
||||
".bmp",
|
||||
".tga",
|
||||
".dds",
|
||||
".jpg" // Why not? Could be useful for large photo-like textures
|
||||
};
|
||||
|
||||
auto rFilenames = DoFileSearch(Extensions, {szDir}, /*recursive*/ true);
|
||||
|
|
Loading…
Reference in New Issue