From fa70a8fd01045157da536f2ecb543a83c02ee2db Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 14 Dec 2023 14:10:51 -0500 Subject: [PATCH 1/2] WC24PatchEngine: Make a few functions internally linked These are only used within this translation unit, so we can remove the IniFile dependency from the header. --- Source/Core/Core/WC24PatchEngine.cpp | 28 +++++++++++++++------------- Source/Core/Core/WC24PatchEngine.h | 6 +----- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Source/Core/Core/WC24PatchEngine.cpp b/Source/Core/Core/WC24PatchEngine.cpp index 1fd7462b77..a1c5532fa1 100644 --- a/Source/Core/Core/WC24PatchEngine.cpp +++ b/Source/Core/Core/WC24PatchEngine.cpp @@ -4,17 +4,19 @@ // WC24PatchEngine // Allows for replacing URLs used in WC24 requests +#include "Core/WC24PatchEngine.h" + #include #include #include +#include "Common/IniFile.h" #include "Common/StringUtil.h" #include "Core/CheatCodes.h" #include "Core/CommonTitles.h" #include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" -#include "Core/WC24PatchEngine.h" namespace WC24PatchEngine { @@ -38,7 +40,7 @@ static constexpr std::array s_wc24_channels{ static std::vector s_patches; -bool DeserializeLine(const std::string& line, NetworkPatch* patch) +static bool DeserializeLine(const std::string& line, NetworkPatch* patch) { const std::vector items = SplitString(line, ':'); @@ -54,13 +56,13 @@ bool DeserializeLine(const std::string& line, NetworkPatch* patch) return patch; } -void LoadPatchSection(const Common::IniFile& ini) +static void LoadPatchSection(const Common::IniFile& ini) { std::vector lines; NetworkPatch patch; ini.GetLines("WC24Patch", &lines); - for (std::string& line : lines) + for (const std::string& line : lines) { if (line.empty()) continue; @@ -81,6 +83,15 @@ void LoadPatchSection(const Common::IniFile& ini) ReadEnabledAndDisabled(ini, "WC24Patch", &s_patches); } +static bool IsWC24Channel() +{ + const auto& sconfig = SConfig::GetInstance(); + const auto found = + std::find(s_wc24_channels.begin(), s_wc24_channels.end(), sconfig.GetTitleID()); + + return found != s_wc24_channels.end(); +} + static void LoadPatches() { const auto& sconfig = SConfig::GetInstance(); @@ -98,15 +109,6 @@ static void LoadPatches() LoadPatchSection(ini); } -bool IsWC24Channel() -{ - const auto& sconfig = SConfig::GetInstance(); - const auto found = - std::find(s_wc24_channels.begin(), s_wc24_channels.end(), sconfig.GetTitleID()); - - return found != s_wc24_channels.end(); -} - void Reload() { s_patches.clear(); diff --git a/Source/Core/Core/WC24PatchEngine.h b/Source/Core/Core/WC24PatchEngine.h index abbfcc0d58..5f9c78da4c 100644 --- a/Source/Core/Core/WC24PatchEngine.h +++ b/Source/Core/Core/WC24PatchEngine.h @@ -6,8 +6,6 @@ #include #include -#include "Common/IniFile.h" - namespace WC24PatchEngine { enum class IsKD : bool; @@ -22,9 +20,7 @@ struct NetworkPatch final }; void Reload(); -bool DeserializeLine(const std::string& line, NetworkPatch* patch); -bool IsWC24Channel(); -void LoadPatchSection(const Common::IniFile& ini); + std::optional GetNetworkPatch(const std::string& source, IsKD is_kd); std::optional GetNetworkPatchByPayload(std::string_view source); } // namespace WC24PatchEngine From 88431cfbca00495f597418d87384efe8e440b628 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 14 Dec 2023 14:18:38 -0500 Subject: [PATCH 2/2] WC24PatchEngine: Make GetNetworkPatch() take a std::string_view Makes it consistent with GetNetworkPatchByPayload() --- Source/Core/Core/WC24PatchEngine.cpp | 2 +- Source/Core/Core/WC24PatchEngine.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/WC24PatchEngine.cpp b/Source/Core/Core/WC24PatchEngine.cpp index a1c5532fa1..7a9b5a25ff 100644 --- a/Source/Core/Core/WC24PatchEngine.cpp +++ b/Source/Core/Core/WC24PatchEngine.cpp @@ -115,7 +115,7 @@ void Reload() LoadPatches(); } -std::optional GetNetworkPatch(const std::string& source, IsKD is_kd) +std::optional GetNetworkPatch(std::string_view source, IsKD is_kd) { const auto patch = std::find_if(s_patches.begin(), s_patches.end(), [&source, &is_kd](const NetworkPatch& p) { diff --git a/Source/Core/Core/WC24PatchEngine.h b/Source/Core/Core/WC24PatchEngine.h index 5f9c78da4c..5e019a67a1 100644 --- a/Source/Core/Core/WC24PatchEngine.h +++ b/Source/Core/Core/WC24PatchEngine.h @@ -21,6 +21,6 @@ struct NetworkPatch final void Reload(); -std::optional GetNetworkPatch(const std::string& source, IsKD is_kd); +std::optional GetNetworkPatch(std::string_view source, IsKD is_kd); std::optional GetNetworkPatchByPayload(std::string_view source); } // namespace WC24PatchEngine