diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp index a3504f80d2..342ef8ec6d 100644 --- a/Source/Core/Common/Config/Config.cpp +++ b/Source/Core/Common/Config/Config.cpp @@ -101,15 +101,14 @@ const std::string& GetSystemName(System system) return system_to_name.at(system); } -System GetSystemFromName(const std::string& name) +std::optional GetSystemFromName(const std::string& name) { const auto system = std::find_if(system_to_name.begin(), system_to_name.end(), [&name](const auto& entry) { return entry.second == name; }); if (system != system_to_name.end()) return system->first; - _assert_msg_(COMMON, false, "Programming error! Couldn't convert '%s' to system!", name.c_str()); - return System::Main; + return {}; } const std::string& GetLayerName(LayerType layer) diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 3536f5677c..14a2dcb20c 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "Common/Config/ConfigInfo.h" @@ -38,7 +39,7 @@ void Shutdown(); void ClearCurrentRunLayer(); const std::string& GetSystemName(System system); -System GetSystemFromName(const std::string& system); +std::optional GetSystemFromName(const std::string& system); const std::string& GetLayerName(LayerType layer); LayerType GetActiveLayerForConfig(const ConfigLocation&); diff --git a/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp index e6ec7c97bc..63239b903a 100644 --- a/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp @@ -157,8 +157,9 @@ static ConfigLocation MapINIToRealLocation(const std::string& section, const std std::getline(buffer, config_section, '.'); fail |= buffer.fail(); - if (!fail) - return {Config::GetSystemFromName(system_str), config_section, key}; + const std::optional system = Config::GetSystemFromName(system_str); + if (!fail && system) + return {*system, config_section, key}; WARN_LOG(CORE, "Unknown game INI option in section %s: %s", section.c_str(), key.c_str()); return {Config::System::Main, "", ""}; diff --git a/Source/Core/UICommon/CommandLineParse.cpp b/Source/Core/UICommon/CommandLineParse.cpp index 1ca4bb90e8..683738479f 100644 --- a/Source/Core/UICommon/CommandLineParse.cpp +++ b/Source/Core/UICommon/CommandLineParse.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include #include #include @@ -40,8 +41,12 @@ public: std::getline(buffer, section, '.'); std::getline(buffer, key, '='); std::getline(buffer, value, '='); - Config::System system = Config::GetSystemFromName(system_str); - m_values.emplace_back(std::make_tuple(Config::ConfigLocation{system, section, key}, value)); + const std::optional system = Config::GetSystemFromName(system_str); + if (system) + { + m_values.emplace_back( + std::make_tuple(Config::ConfigLocation{*system, section, key}, value)); + } } }