summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorSintendo <3380580+Sintendo@users.noreply.github.com>2025-12-24 10:14:02 +0100
committerSintendo <3380580+Sintendo@users.noreply.github.com>2026-01-24 16:50:10 +0100
commitf2e1c71803b953c9adb9528c168cbbde23b3b30a (patch)
tree276c17d2bbfaebc6dc2193e1f6e3a6f387eb0787 /Source/Core
parent3221e982d371afd39793628bf8973f3cc951db35 (diff)
Common/FileSearch: Refactor DoFileSearch
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/FileSearch.cpp8
-rw-r--r--Source/Core/Common/FileSearch.h26
-rw-r--r--Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp4
-rw-r--r--Source/Core/DiscIO/RiivolutionParser.cpp2
-rw-r--r--Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp5
-rw-r--r--Source/Core/DolphinQt/RiivolutionBootWidget.cpp2
-rw-r--r--Source/Core/DolphinQt/Settings/InterfacePane.cpp6
-rw-r--r--Source/Core/InputCommon/DynamicInputTextureManager.cpp2
-rw-r--r--Source/Core/InputCommon/InputProfile.cpp4
-rw-r--r--Source/Core/UICommon/GameFileCache.cpp8
-rw-r--r--Source/Core/UICommon/GameFileCache.h2
-rw-r--r--Source/Core/UICommon/ResourcePack/Manager.cpp2
-rw-r--r--Source/Core/UICommon/ResourcePack/ResourcePack.cpp2
-rw-r--r--Source/Core/VideoCommon/HiresTextures.cpp6
-rw-r--r--Source/Core/VideoCommon/PostProcessing.cpp6
-rw-r--r--Source/Core/VideoCommon/TextureUtils.cpp2
16 files changed, 52 insertions, 35 deletions
diff --git a/Source/Core/Common/FileSearch.cpp b/Source/Core/Common/FileSearch.cpp
index 9eb74e4fcf..1eecb1d36d 100644
--- a/Source/Core/Common/FileSearch.cpp
+++ b/Source/Core/Common/FileSearch.cpp
@@ -5,8 +5,6 @@
#include <algorithm>
#include <filesystem>
-#include <functional>
-#include <iterator>
#include <system_error>
#include "Common/CommonPaths.h"
@@ -21,16 +19,14 @@
#endif
#include <cstring>
-#include "Common/CommonFuncs.h"
-#include "Common/FileUtil.h"
#endif
namespace fs = std::filesystem;
namespace Common
{
-std::vector<std::string> DoFileSearch(const std::vector<std::string>& directories,
- const std::vector<std::string>& exts, bool recursive)
+std::vector<std::string> DoFileSearch(std::span<const std::string_view> directories,
+ std::span<const std::string_view> exts, bool recursive)
{
const bool accept_all = exts.empty();
diff --git a/Source/Core/Common/FileSearch.h b/Source/Core/Common/FileSearch.h
index ac8fb7bf1b..ef28e244d3 100644
--- a/Source/Core/Common/FileSearch.h
+++ b/Source/Core/Common/FileSearch.h
@@ -3,14 +3,36 @@
#pragma once
+#include <span>
#include <string>
+#include <string_view>
#include <vector>
namespace Common
{
// Callers can pass empty "exts" to indicate they want all files + directories in results
// Otherwise, only files matching the extensions are returned
-std::vector<std::string> DoFileSearch(const std::vector<std::string>& directories,
- const std::vector<std::string>& exts = {},
+std::vector<std::string> DoFileSearch(std::span<const std::string_view> directories,
+ std::span<const std::string_view> exts = {},
bool recursive = false);
+
+inline std::vector<std::string> DoFileSearch(std::span<const std::string_view> directories,
+ std::string_view ext, bool recursive = false)
+{
+ return DoFileSearch(directories, std::span(&ext, 1), recursive);
+}
+
+inline std::vector<std::string> DoFileSearch(std::string_view directory,
+ std::span<const std::string_view> exts = {},
+ bool recursive = false)
+{
+ return DoFileSearch(std::span(&directory, 1), exts, recursive);
+}
+
+inline std::vector<std::string> DoFileSearch(std::string_view directory, std::string_view ext,
+ bool recursive = false)
+{
+ return DoFileSearch(std::span(&directory, 1), std::span(&ext, 1), recursive);
+}
+
} // namespace Common
diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp
index 66629d43f1..8e78857655 100644
--- a/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp
+++ b/Source/Core/Core/HW/GCMemcard/GCMemcardDirectory.cpp
@@ -134,7 +134,7 @@ std::vector<std::string> GCMemcardDirectory::GetFileNamesForGameID(const std::st
game_code = Common::swap32(reinterpret_cast<const u8*>(game_id.c_str()));
std::vector<Memcard::DEntry> loaded_saves;
- for (const std::string& file_name : Common::DoFileSearch({directory}, {".gci"}))
+ for (const std::string& file_name : Common::DoFileSearch(directory, ".gci"))
{
File::IOFile gci_file(file_name, "rb");
if (!gci_file)
@@ -190,7 +190,7 @@ GCMemcardDirectory::GCMemcardDirectory(const std::string& directory, ExpansionIn
}
const bool current_game_only = Config::Get(Config::SESSION_GCI_FOLDER_CURRENT_GAME_ONLY);
- const std::vector<std::string> filenames = Common::DoFileSearch({m_save_directory}, {".gci"});
+ const std::vector<std::string> filenames = Common::DoFileSearch(m_save_directory, ".gci");
// split up into files for current games we should definitely load,
// and files for other games that we don't care too much about
diff --git a/Source/Core/DiscIO/RiivolutionParser.cpp b/Source/Core/DiscIO/RiivolutionParser.cpp
index 6fbb4d41c4..754419f33f 100644
--- a/Source/Core/DiscIO/RiivolutionParser.cpp
+++ b/Source/Core/DiscIO/RiivolutionParser.cpp
@@ -399,7 +399,7 @@ std::vector<Patch> GenerateRiivolutionPatchesFromConfig(const std::string& root_
const std::optional<Config> config = ParseConfigFile(
fmt::format("{}/riivolution/config/{}.xml", root_directory, game_id.substr(0, 4)));
- for (const std::string& path : Common::DoFileSearch({root_directory + "riivolution"}, {".xml"}))
+ for (const std::string& path : Common::DoFileSearch(root_directory + "riivolution", ".xml"))
{
std::optional<Disc> parsed = ParseFile(path);
if (!parsed || !parsed->IsValidForGame(game_id, revision, disc_number))
diff --git a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp
index 23ce80a489..ddb9d39ee6 100644
--- a/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp
+++ b/Source/Core/DolphinQt/Config/Mapping/MappingWindow.cpp
@@ -534,7 +534,7 @@ void MappingWindow::PopulateProfileSelection()
m_profiles_combo->clear();
const std::string profiles_path = m_config->GetUserProfileDirectoryPath();
- for (const auto& filename : Common::DoFileSearch({profiles_path}, {".ini"}))
+ for (const auto& filename : Common::DoFileSearch(profiles_path, ".ini"))
{
std::string basename;
SplitPath(filename, nullptr, &basename, nullptr);
@@ -544,8 +544,7 @@ void MappingWindow::PopulateProfileSelection()
m_profiles_combo->insertSeparator(m_profiles_combo->count());
- for (const auto& filename :
- Common::DoFileSearch({m_config->GetSysProfileDirectoryPath()}, {".ini"}))
+ for (const auto& filename : Common::DoFileSearch(m_config->GetSysProfileDirectoryPath(), ".ini"))
{
std::string basename;
SplitPath(filename, nullptr, &basename, nullptr);
diff --git a/Source/Core/DolphinQt/RiivolutionBootWidget.cpp b/Source/Core/DolphinQt/RiivolutionBootWidget.cpp
index aedb42c903..ce8dbdbe97 100644
--- a/Source/Core/DolphinQt/RiivolutionBootWidget.cpp
+++ b/Source/Core/DolphinQt/RiivolutionBootWidget.cpp
@@ -109,7 +109,7 @@ void RiivolutionBootWidget::LoadMatchingXMLs()
{
const std::string& riivolution_dir = File::GetUserPath(D_RIIVOLUTION_IDX);
const auto config = LoadConfigXML(riivolution_dir);
- for (const std::string& path : Common::DoFileSearch({riivolution_dir + "riivolution"}, {".xml"}))
+ for (const std::string& path : Common::DoFileSearch(riivolution_dir + "riivolution", ".xml"))
{
auto parsed = DiscIO::Riivolution::ParseFile(path);
if (!parsed || !parsed->IsValidForGame(m_game_id, m_revision, m_disc_number))
diff --git a/Source/Core/DolphinQt/Settings/InterfacePane.cpp b/Source/Core/DolphinQt/Settings/InterfacePane.cpp
index a12434236c..6703d41107 100644
--- a/Source/Core/DolphinQt/Settings/InterfacePane.cpp
+++ b/Source/Core/DolphinQt/Settings/InterfacePane.cpp
@@ -132,8 +132,8 @@ void InterfacePane::CreateUI()
combobox_layout->addRow(tr("&Language:"), m_combobox_language);
// List available themes
- auto theme_paths =
- Common::DoFileSearch({File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR});
+ auto theme_paths = Common::DoFileSearch(
+ {{File::GetUserPath(D_THEMES_IDX), File::GetSysDirectory() + THEMES_DIR}});
std::vector<std::string> theme_names;
theme_names.reserve(theme_paths.size());
std::ranges::transform(theme_paths, std::back_inserter(theme_names), PathToFileName);
@@ -147,7 +147,7 @@ void InterfacePane::CreateUI()
m_label_userstyle = new QLabel(tr("Style:"));
combobox_layout->addRow(m_label_userstyle, m_combobox_userstyle);
- auto userstyle_search_results = Common::DoFileSearch({File::GetUserPath(D_STYLES_IDX)});
+ auto userstyle_search_results = Common::DoFileSearch(File::GetUserPath(D_STYLES_IDX));
m_combobox_userstyle->addItem(tr("(System)"), static_cast<int>(Settings::StyleType::System));
diff --git a/Source/Core/InputCommon/DynamicInputTextureManager.cpp b/Source/Core/InputCommon/DynamicInputTextureManager.cpp
index af5214bd37..b02d98eeca 100644
--- a/Source/Core/InputCommon/DynamicInputTextureManager.cpp
+++ b/Source/Core/InputCommon/DynamicInputTextureManager.cpp
@@ -32,7 +32,7 @@ void DynamicInputTextureManager::Load()
for (const auto& dynamic_input_directory : dynamic_input_directories)
{
- const auto json_files = Common::DoFileSearch({dynamic_input_directory}, {".json"});
+ const auto json_files = Common::DoFileSearch(dynamic_input_directory, ".json");
for (auto& file : json_files)
{
m_configuration.emplace_back(file);
diff --git a/Source/Core/InputCommon/InputProfile.cpp b/Source/Core/InputCommon/InputProfile.cpp
index 0bb452ac1e..a9471c2765 100644
--- a/Source/Core/InputCommon/InputProfile.cpp
+++ b/Source/Core/InputCommon/InputProfile.cpp
@@ -37,7 +37,7 @@ std::vector<std::string> GetProfilesFromSetting(const std::string& setting, cons
const std::string path = root + std::string(StripWhitespace(setting_choice));
if (File::IsDirectory(path))
{
- const auto files_under_directory = Common::DoFileSearch({path}, {".ini"}, true);
+ const auto files_under_directory = Common::DoFileSearch(path, ".ini", true);
result.insert(result.end(), files_under_directory.begin(), files_under_directory.end());
}
else
@@ -57,7 +57,7 @@ std::vector<std::string> ProfileCycler::GetProfilesForDevice(InputConfig* device
{
const std::string device_profile_root_location(
device_configuration->GetUserProfileDirectoryPath());
- return Common::DoFileSearch({device_profile_root_location}, {".ini"}, true);
+ return Common::DoFileSearch(device_profile_root_location, ".ini", true);
}
std::string ProfileCycler::GetProfile(CycleDirection cycle_direction, int& profile_index,
diff --git a/Source/Core/UICommon/GameFileCache.cpp b/Source/Core/UICommon/GameFileCache.cpp
index f72f47c11e..4c93fb7640 100644
--- a/Source/Core/UICommon/GameFileCache.cpp
+++ b/Source/Core/UICommon/GameFileCache.cpp
@@ -28,12 +28,12 @@ namespace UICommon
{
static constexpr u32 CACHE_REVISION = 26; // Last changed in PR 10084
-std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& directories_to_scan,
+std::vector<std::string> FindAllGamePaths(std::span<const std::string_view> directories_to_scan,
bool recursive_scan)
{
- static const std::vector<std::string> search_extensions = {
- ".gcm", ".tgc", ".bin", ".iso", ".ciso", ".gcz", ".wbfs",
- ".wia", ".rvz", ".nfs", ".wad", ".dol", ".elf", ".json"};
+ constexpr auto search_extensions =
+ std::to_array<std::string_view>({".gcm", ".tgc", ".bin", ".iso", ".ciso", ".gcz", ".wbfs",
+ ".wia", ".rvz", ".nfs", ".wad", ".dol", ".elf", ".json"});
// TODO: We could process paths iteratively as they are found
return Common::DoFileSearch(directories_to_scan, search_extensions, recursive_scan);
diff --git a/Source/Core/UICommon/GameFileCache.h b/Source/Core/UICommon/GameFileCache.h
index 5544b3a143..4c4ab15557 100644
--- a/Source/Core/UICommon/GameFileCache.h
+++ b/Source/Core/UICommon/GameFileCache.h
@@ -19,7 +19,7 @@ namespace UICommon
{
class GameFile;
-std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& directories_to_scan,
+std::vector<std::string> FindAllGamePaths(std::span<const std::string_view> directories_to_scan,
bool recursive_scan);
class GameFileCache
diff --git a/Source/Core/UICommon/ResourcePack/Manager.cpp b/Source/Core/UICommon/ResourcePack/Manager.cpp
index b1fd555c85..f3abf44ebc 100644
--- a/Source/Core/UICommon/ResourcePack/Manager.cpp
+++ b/Source/Core/UICommon/ResourcePack/Manager.cpp
@@ -32,7 +32,7 @@ bool Init()
{
packs.clear();
const std::vector<std::string> pack_list =
- Common::DoFileSearch({File::GetUserPath(D_RESOURCEPACK_IDX)}, {".zip"});
+ Common::DoFileSearch(File::GetUserPath(D_RESOURCEPACK_IDX), ".zip");
Common::IniFile file = GetPackConfig();
diff --git a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp
index 73f271c6bc..f755dae6f5 100644
--- a/Source/Core/UICommon/ResourcePack/ResourcePack.cpp
+++ b/Source/Core/UICommon/ResourcePack/ResourcePack.cpp
@@ -305,7 +305,7 @@ bool ResourcePack::Uninstall(const std::string& path)
while (dir.length() > (path + TEXTURE_PATH).length())
{
- auto is_empty = Common::DoFileSearch({dir}).empty();
+ const auto is_empty = Common::DoFileSearch(dir).empty();
if (is_empty)
File::DeleteDir(dir);
diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp
index 12f59f5ff5..5fb90a9416 100644
--- a/Source/Core/VideoCommon/HiresTextures.cpp
+++ b/Source/Core/VideoCommon/HiresTextures.cpp
@@ -93,7 +93,7 @@ void HiresTexture::Update()
const std::string& game_id = SConfig::GetInstance().GetGameID();
const std::set<std::string> texture_directories =
GetTextureDirectoriesWithGameId(File::GetUserPath(D_HIRESTEXTURES_IDX), game_id);
- const std::vector<std::string> extensions{".png", ".dds"};
+ constexpr auto extensions = std::to_array<std::string_view>({".png", ".dds"});
for (const auto& texture_directory : texture_directories)
{
@@ -101,7 +101,7 @@ void HiresTexture::Update()
s_file_library->Watch(texture_directory);
const auto texture_paths =
- Common::DoFileSearch({texture_directory}, extensions, /*recursive*/ true);
+ Common::DoFileSearch(texture_directory, extensions, /*recursive*/ true);
bool failed_insert = false;
for (auto& path : texture_paths)
@@ -227,7 +227,7 @@ std::set<std::string> GetTextureDirectoriesWithGameId(const std::string& root_di
};
// Look for any other directories that might be specific to the given gameid
- const auto files = Common::DoFileSearch({root_directory}, {".txt"}, true);
+ const auto files = Common::DoFileSearch(root_directory, ".txt", true);
for (const auto& file : files)
{
if (match_gameid_or_all(file))
diff --git a/Source/Core/VideoCommon/PostProcessing.cpp b/Source/Core/VideoCommon/PostProcessing.cpp
index 94da639bca..e8111879b4 100644
--- a/Source/Core/VideoCommon/PostProcessing.cpp
+++ b/Source/Core/VideoCommon/PostProcessing.cpp
@@ -387,9 +387,9 @@ PostProcessing::~PostProcessing()
static std::vector<std::string> GetShaders(const std::string& sub_dir = "")
{
std::vector<std::string> paths =
- Common::DoFileSearch({File::GetUserPath(D_SHADERS_IDX) + sub_dir,
- File::GetSysDirectory() + SHADERS_DIR DIR_SEP + sub_dir},
- {".glsl"});
+ Common::DoFileSearch({{File::GetUserPath(D_SHADERS_IDX) + sub_dir,
+ File::GetSysDirectory() + SHADERS_DIR DIR_SEP + sub_dir}},
+ ".glsl");
std::vector<std::string> result;
for (std::string path : paths)
{
diff --git a/Source/Core/VideoCommon/TextureUtils.cpp b/Source/Core/VideoCommon/TextureUtils.cpp
index 907b1ac523..bd41550877 100644
--- a/Source/Core/VideoCommon/TextureUtils.cpp
+++ b/Source/Core/VideoCommon/TextureUtils.cpp
@@ -58,7 +58,7 @@ void TextureDumper::DumpTexture(const ::AbstractTexture& texture, std::string ba
if (!File::IsDirectory(dump_dir))
File::CreateDir(dump_dir);
- for (auto& filename : Common::DoFileSearch({dump_dir}, {".png"}, true))
+ for (auto& filename : Common::DoFileSearch(dump_dir, ".png", true))
{
std::string name;
SplitPath(filename, nullptr, &name, nullptr);