diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 32da64b69..d219f4450 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -1,8 +1,8 @@ // SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) -#include "assert.h" #include "string_util.h" +#include "assert.h" #include #include @@ -306,6 +306,22 @@ void StringUtil::ReplaceAll(std::string* subject, const std::string_view search, } } +std::string StringUtil::ReplaceAll(const std::string_view subject, const char search, const char replacement) +{ + std::string ret(subject); + ReplaceAll(&ret, search, replacement); + return ret; +} + +void StringUtil::ReplaceAll(std::string* subject, const char search, const char replacement) +{ + for (size_t i = 0; i < subject->length(); i++) + { + const char ch = (*subject)[i]; + (*subject)[i] = (ch == search) ? replacement : ch; + } +} + bool StringUtil::ParseAssignmentString(const std::string_view str, std::string_view* key, std::string_view* value) { const std::string_view::size_type pos = str.find('='); diff --git a/src/common/string_util.h b/src/common/string_util.h index a440a96e4..72ccfffbd 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -223,8 +223,10 @@ std::string_view StripWhitespace(const std::string_view str); void StripWhitespace(std::string* str); /// Splits a string based on a single character delimiter. -std::vector SplitString(const std::string_view str, char delimiter, bool skip_empty = true); -std::vector SplitNewString(const std::string_view str, char delimiter, bool skip_empty = true); +[[nodiscard]] std::vector SplitString(const std::string_view str, char delimiter, + bool skip_empty = true); +[[nodiscard]] std::vector SplitNewString(const std::string_view str, char delimiter, + bool skip_empty = true); /// Joins a string together using the specified delimiter. template @@ -253,9 +255,11 @@ static inline std::string JoinString(const T& start, const T& end, const std::st } /// Replaces all instances of search in subject with replacement. -std::string ReplaceAll(const std::string_view subject, const std::string_view search, - const std::string_view replacement); +[[nodiscard]] std::string ReplaceAll(const std::string_view subject, const std::string_view search, + const std::string_view replacement); void ReplaceAll(std::string* subject, const std::string_view search, const std::string_view replacement); +[[nodiscard]] std::string ReplaceAll(const std::string_view subject, const char search, const char replacement); +void ReplaceAll(std::string* subject, const char search, const char replacement); /// Parses an assignment string (Key = Value) into its two components. bool ParseAssignmentString(const std::string_view str, std::string_view* key, std::string_view* value); diff --git a/src/util/postprocessing.cpp b/src/util/postprocessing.cpp index ff89b0092..070d52b4c 100644 --- a/src/util/postprocessing.cpp +++ b/src/util/postprocessing.cpp @@ -164,12 +164,10 @@ std::vector> PostProcessing::GetAvailableSha if (pos != std::string::npos && pos > 0) fd.FileName.erase(pos); +#ifdef _WIN32 // swap any backslashes for forward slashes so the config is cross-platform - for (size_t i = 0; i < fd.FileName.size(); i++) - { - if (fd.FileName[i] == '\\') - fd.FileName[i] = '/'; - } + StringUtil::ReplaceAll(&fd.FileName, '\\', '/'); +#endif if (std::none_of(names.begin(), names.end(), [&fd](const auto& other) { return fd.FileName == other.second; })) { @@ -179,11 +177,13 @@ std::vector> PostProcessing::GetAvailableSha } FileSystem::FindFiles(Path::Combine(EmuFolders::Shaders, "reshade" FS_OSPATH_SEPARATOR_STR "Shaders").c_str(), "*.fx", - FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_RELATIVE_PATHS, &results); + FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_RECURSIVE | FILESYSTEM_FIND_RELATIVE_PATHS, &results); FileSystem::FindFiles( Path::Combine(EmuFolders::Resources, "shaders" FS_OSPATH_SEPARATOR_STR "reshade" FS_OSPATH_SEPARATOR_STR "Shaders") .c_str(), - "*.fx", FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_RELATIVE_PATHS | FILESYSTEM_FIND_KEEP_ARRAY, &results); + "*.fx", + FILESYSTEM_FIND_FILES | FILESYSTEM_FIND_RECURSIVE | FILESYSTEM_FIND_RELATIVE_PATHS | FILESYSTEM_FIND_KEEP_ARRAY, + &results); std::sort(results.begin(), results.end(), [](const auto& lhs, const auto& rhs) { return lhs.FileName < rhs.FileName; }); @@ -193,12 +193,10 @@ std::vector> PostProcessing::GetAvailableSha if (pos != std::string::npos && pos > 0) fd.FileName.erase(pos); +#ifdef _WIN32 // swap any backslashes for forward slashes so the config is cross-platform - for (size_t i = 0; i < fd.FileName.size(); i++) - { - if (fd.FileName[i] == '\\') - fd.FileName[i] = '/'; - } + StringUtil::ReplaceAll(&fd.FileName, '\\', '/'); +#endif if (std::none_of(names.begin(), names.end(), [&fd](const auto& other) { return fd.FileName == other.second; })) {