Skip to content

Commit

Permalink
FileSearch: Don't use RegExs, just do string comparisons.
Browse files Browse the repository at this point in the history
Nothing used the RegEx feature of FileSearch, and GCC < 4.9
doesn't support C++11 RegEx properly, so get rid of it.
  • Loading branch information
waddlesplash committed Sep 22, 2015
1 parent 79bf939 commit 2595fd9
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 44 deletions.
29 changes: 12 additions & 17 deletions Source/Core/Common/FileSearch.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -37,20 +32,20 @@ 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 = (exts.size() == 0) || (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);
for (auto& ext : exts)
{
if (name.length() >= ext.length() && name.compare(name.length() - ext.length(), ext.length(), ext) == 0)
return true;
}
return false;
});
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Common/FileSearch.h
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/GCMemcardDirectory.cpp
Expand Up @@ -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)
{
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/DolphinQt/GameList/GameTracker.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/Config/InterfaceConfigPane.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/FrameTools.cpp
Expand Up @@ -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)
{
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/DolphinWX/GameListCtrl.cpp
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinWX/InputConfigDiag.cpp
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoBackends/OGL/main.cpp
Expand Up @@ -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
});
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoCommon/HiresTextures.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 2595fd9

Please sign in to comment.