From d590aa88a4f57e1dda9d9da56c60c6db73206e25 Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 1 Jan 2022 17:53:12 +0100 Subject: [PATCH] Config: Port remaining General settings to new config system. --- Source/Core/Core/Config/MainSettings.cpp | 54 +++++++++++++++++++ Source/Core/Core/Config/MainSettings.h | 8 +++ Source/Core/Core/ConfigManager.cpp | 66 ----------------------- Source/Core/Core/ConfigManager.h | 13 ----- Source/Core/Core/Core.cpp | 34 +++++++----- Source/Core/Core/IOS/Network/MACUtils.cpp | 8 +-- Source/Core/Core/NetworkCaptureLogger.cpp | 2 +- Source/Core/DolphinQt/MenuBar.cpp | 8 +-- Source/Core/DolphinQt/Settings.cpp | 8 +-- Source/Core/VideoCommon/RenderBase.cpp | 14 +++-- 10 files changed, 102 insertions(+), 113 deletions(-) diff --git a/Source/Core/Core/Config/MainSettings.cpp b/Source/Core/Core/Config/MainSettings.cpp index 6f89123bf0..141d21ba71 100644 --- a/Source/Core/Core/Config/MainSettings.cpp +++ b/Source/Core/Core/Config/MainSettings.cpp @@ -10,6 +10,7 @@ #include "AudioCommon/AudioCommon.h" #include "Common/CommonPaths.h" #include "Common/Config/Config.h" +#include "Common/MathUtil.h" #include "Common/StringUtil.h" #include "Common/Version.h" #include "Core/Config/DefaultLocale.h" @@ -163,6 +164,59 @@ const Info MAIN_RESOURCEPACK_PATH{{System::Main, "General", "Resour const Info MAIN_FS_PATH{{System::Main, "General", "NANDRootPath"}, ""}; const Info MAIN_SD_PATH{{System::Main, "General", "WiiSDCardPath"}, ""}; const Info MAIN_WFS_PATH{{System::Main, "General", "WFSPath"}, ""}; +const Info MAIN_SHOW_LAG{{System::Main, "General", "ShowLag"}, false}; +const Info MAIN_SHOW_FRAME_COUNT{{System::Main, "General", "ShowFrameCount"}, false}; +const Info MAIN_WIRELESS_MAC{{System::Main, "General", "WirelessMac"}, ""}; +const Info MAIN_GDB_SOCKET{{System::Main, "General", "GDBSocket"}, ""}; +const Info MAIN_GDB_PORT{{System::Main, "General", "GDBPort"}, -1}; +const Info MAIN_ISO_PATH_COUNT{{System::Main, "General", "ISOPaths"}, 0}; + +static Info MakeISOPathConfigInfo(size_t idx) +{ + return Config::Info{{Config::System::Main, "General", fmt::format("ISOPath{}", idx)}, + ""}; +} + +std::vector GetIsoPaths() +{ + size_t count = MathUtil::SaturatingCast(Config::Get(Config::MAIN_ISO_PATH_COUNT)); + std::vector paths; + paths.reserve(count); + for (size_t i = 0; i < count; ++i) + { + std::string iso_path = Config::Get(MakeISOPathConfigInfo(i)); + if (!iso_path.empty()) + paths.emplace_back(std::move(iso_path)); + } + return paths; +} + +void SetIsoPaths(const std::vector& paths) +{ + size_t old_size = MathUtil::SaturatingCast(Config::Get(Config::MAIN_ISO_PATH_COUNT)); + size_t new_size = paths.size(); + + size_t current_path_idx = 0; + for (const std::string& p : paths) + { + if (p.empty()) + { + --new_size; + continue; + } + + Config::SetBase(MakeISOPathConfigInfo(current_path_idx), p); + ++current_path_idx; + } + + for (size_t i = current_path_idx; i < old_size; ++i) + { + // TODO: This actually needs a Config::Erase(). + Config::SetBase(MakeISOPathConfigInfo(i), ""); + } + + Config::SetBase(Config::MAIN_ISO_PATH_COUNT, MathUtil::SaturatingCast(new_size)); +} // Main.GBA diff --git a/Source/Core/Core/Config/MainSettings.h b/Source/Core/Core/Config/MainSettings.h index 7b34c311f1..5874748feb 100644 --- a/Source/Core/Core/Config/MainSettings.h +++ b/Source/Core/Core/Config/MainSettings.h @@ -141,6 +141,14 @@ extern const Info MAIN_RESOURCEPACK_PATH; extern const Info MAIN_FS_PATH; extern const Info MAIN_SD_PATH; extern const Info MAIN_WFS_PATH; +extern const Info MAIN_SHOW_LAG; +extern const Info MAIN_SHOW_FRAME_COUNT; +extern const Info MAIN_WIRELESS_MAC; +extern const Info MAIN_GDB_SOCKET; +extern const Info MAIN_GDB_PORT; +extern const Info MAIN_ISO_PATH_COUNT; +std::vector GetIsoPaths(); +void SetIsoPaths(const std::vector& paths); // Main.GBA diff --git a/Source/Core/Core/ConfigManager.cpp b/Source/Core/Core/ConfigManager.cpp index a3f28a10ed..b274922646 100644 --- a/Source/Core/Core/ConfigManager.cpp +++ b/Source/Core/Core/ConfigManager.cpp @@ -88,7 +88,6 @@ void SConfig::SaveSettings() IniFile ini; ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); // load first to not kill unknown stuff - SaveGeneralSettings(ini); SaveCoreSettings(ini); ini.Save(File::GetUserPath(F_DOLPHINCONFIG_IDX)); @@ -96,38 +95,6 @@ void SConfig::SaveSettings() Config::Save(); } -void SConfig::SaveGeneralSettings(IniFile& ini) -{ - IniFile::Section* general = ini.GetOrCreateSection("General"); - - // General - general->Set("ShowLag", m_ShowLag); - general->Set("ShowFrameCount", m_ShowFrameCount); - - // ISO folders - // Clear removed folders - int oldPaths; - int numPaths = (int)m_ISOFolder.size(); - general->Get("ISOPaths", &oldPaths, 0); - for (int i = numPaths; i < oldPaths; i++) - { - ini.DeleteKey("General", fmt::format("ISOPath{}", i)); - } - - general->Set("ISOPaths", numPaths); - for (int i = 0; i < numPaths; i++) - { - general->Set(fmt::format("ISOPath{}", i), m_ISOFolder[i]); - } - - general->Set("WirelessMac", m_WirelessMac); - -#ifndef _WIN32 - general->Set("GDBSocket", gdb_socket); -#endif - general->Set("GDBPort", iGDBPort); -} - void SConfig::SaveCoreSettings(IniFile& ini) { IniFile::Section* core = ini.GetOrCreateSection("Core"); @@ -185,37 +152,9 @@ void SConfig::LoadSettings() IniFile ini; ini.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX)); - LoadGeneralSettings(ini); LoadCoreSettings(ini); } -void SConfig::LoadGeneralSettings(IniFile& ini) -{ - IniFile::Section* general = ini.GetOrCreateSection("General"); - - general->Get("ShowLag", &m_ShowLag, false); - general->Get("ShowFrameCount", &m_ShowFrameCount, false); -#ifndef _WIN32 - general->Get("GDBSocket", &gdb_socket, ""); -#endif - general->Get("GDBPort", &(iGDBPort), -1); - - m_ISOFolder.clear(); - int numISOPaths; - - if (general->Get("ISOPaths", &numISOPaths, 0)) - { - for (int i = 0; i < numISOPaths; i++) - { - std::string tmpPath; - general->Get(fmt::format("ISOPath{}", i), &tmpPath, ""); - m_ISOFolder.push_back(std::move(tmpPath)); - } - } - - general->Get("WirelessMac", &m_WirelessMac); -} - void SConfig::LoadCoreSettings(IniFile& ini) { IniFile::Section* core = ini.GetOrCreateSection("Core"); @@ -392,11 +331,6 @@ void SConfig::LoadDefaults() bAutomaticStart = false; bBootToPause = false; - iGDBPort = -1; -#ifndef _WIN32 - gdb_socket = ""; -#endif - cpu_core = PowerPC::DefaultCPUCore(); iTimingVariance = 40; bCPUThread = false; diff --git a/Source/Core/Core/ConfigManager.h b/Source/Core/Core/ConfigManager.h index 09dd8773c1..69758f6404 100644 --- a/Source/Core/Core/ConfigManager.h +++ b/Source/Core/Core/ConfigManager.h @@ -65,14 +65,7 @@ struct SConfig bool m_WiimoteEnableSpeaker; bool connect_wiimotes_for_ciface; - // ISO folder - std::vector m_ISOFolder; - // Settings - int iGDBPort; -#ifndef _WIN32 - std::string gdb_socket; -#endif bool bAutomaticStart = false; bool bBootToPause = false; @@ -180,10 +173,6 @@ struct SConfig float m_EmulationSpeed; - std::string m_WirelessMac; - bool m_ShowLag; - bool m_ShowFrameCount; - // Input settings bool m_AdapterRumble[4]; bool m_AdapterKonga[4]; @@ -208,10 +197,8 @@ private: SConfig(); ~SConfig(); - void SaveGeneralSettings(IniFile& ini); void SaveCoreSettings(IniFile& ini); - void LoadGeneralSettings(IniFile& ini); void LoadCoreSettings(IniFile& ini); void SetRunningGameMetadata(const std::string& game_id, const std::string& gametdb_id, diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 2180d3f2cd..c56ba0b4ba 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -363,22 +363,28 @@ static void CpuThread(const std::optional& savestate_path, bool del } s_is_started = true; + { #ifndef _WIN32 - if (!_CoreParameter.gdb_socket.empty()) - { - GDBStub::InitLocal(_CoreParameter.gdb_socket.data()); - CPUSetInitialExecutionState(true); - } - else + std::string gdb_socket = Config::Get(Config::MAIN_GDB_SOCKET); + if (!gdb_socket.empty()) + { + GDBStub::InitLocal(gdb_socket.data()); + CPUSetInitialExecutionState(true); + } + else #endif - if (_CoreParameter.iGDBPort > 0) - { - GDBStub::Init(_CoreParameter.iGDBPort); - CPUSetInitialExecutionState(true); - } - else - { - CPUSetInitialExecutionState(); + { + int gdb_port = Config::Get(Config::MAIN_GDB_PORT); + if (gdb_port > 0) + { + GDBStub::Init(gdb_port); + CPUSetInitialExecutionState(true); + } + else + { + CPUSetInitialExecutionState(); + } + } } // Enter CPU run loop. When we leave it - we are done. diff --git a/Source/Core/Core/IOS/Network/MACUtils.cpp b/Source/Core/Core/IOS/Network/MACUtils.cpp index 6ff13a78e5..d9db1a8c84 100644 --- a/Source/Core/Core/IOS/Network/MACUtils.cpp +++ b/Source/Core/Core/IOS/Network/MACUtils.cpp @@ -10,22 +10,22 @@ #include "Common/Logging/Log.h" #include "Common/Network.h" -#include "Core/ConfigManager.h" +#include "Core/Config/MainSettings.h" #include "Core/Core.h" namespace IOS::Net { static void SaveMACAddress(const Common::MACAddress& mac) { - SConfig::GetInstance().m_WirelessMac = Common::MacAddressToString(mac); - SConfig::GetInstance().SaveSettings(); + Config::SetBaseOrCurrent(Config::MAIN_WIRELESS_MAC, Common::MacAddressToString(mac)); + Config::Save(); } Common::MACAddress GetMACAddress() { // Parse MAC address from config, and generate a new one if it doesn't // exist or can't be parsed. - std::string wireless_mac = SConfig::GetInstance().m_WirelessMac; + std::string wireless_mac = Config::Get(Config::MAIN_WIRELESS_MAC); if (Core::WantsDeterminism()) wireless_mac = "12:34:56:78:9a:bc"; diff --git a/Source/Core/Core/NetworkCaptureLogger.cpp b/Source/Core/Core/NetworkCaptureLogger.cpp index 77166ac072..2e4242fd88 100644 --- a/Source/Core/Core/NetworkCaptureLogger.cpp +++ b/Source/Core/Core/NetworkCaptureLogger.cpp @@ -191,7 +191,7 @@ void PCAPSSLCaptureLogger::LogIPv4(LogType log_type, const u8* data, u16 length, }; Common::EthernetHeader ethernet_header(0x800); - auto mac = Common::StringToMacAddress(SConfig::GetInstance().m_WirelessMac); + auto mac = Common::StringToMacAddress(Config::Get(Config::MAIN_WIRELESS_MAC)); if (mac) { auto& mac_address = diff --git a/Source/Core/DolphinQt/MenuBar.cpp b/Source/Core/DolphinQt/MenuBar.cpp index 696ec7b020..ea0c235601 100644 --- a/Source/Core/DolphinQt/MenuBar.cpp +++ b/Source/Core/DolphinQt/MenuBar.cpp @@ -758,15 +758,15 @@ void MenuBar::AddMovieMenu() auto* lag_counter = movie_menu->addAction(tr("Show Lag Counter")); lag_counter->setCheckable(true); - lag_counter->setChecked(SConfig::GetInstance().m_ShowLag); + lag_counter->setChecked(Config::Get(Config::MAIN_SHOW_LAG)); connect(lag_counter, &QAction::toggled, - [](bool value) { SConfig::GetInstance().m_ShowLag = value; }); + [](bool value) { Config::SetBaseOrCurrent(Config::MAIN_SHOW_LAG, value); }); auto* frame_counter = movie_menu->addAction(tr("Show Frame Counter")); frame_counter->setCheckable(true); - frame_counter->setChecked(SConfig::GetInstance().m_ShowFrameCount); + frame_counter->setChecked(Config::Get(Config::MAIN_SHOW_FRAME_COUNT)); connect(frame_counter, &QAction::toggled, - [](bool value) { SConfig::GetInstance().m_ShowFrameCount = value; }); + [](bool value) { Config::SetBaseOrCurrent(Config::MAIN_SHOW_FRAME_COUNT, value); }); auto* input_display = movie_menu->addAction(tr("Show Input Display")); input_display->setCheckable(true); diff --git a/Source/Core/DolphinQt/Settings.cpp b/Source/Core/DolphinQt/Settings.cpp index b283e0baeb..44bcd581b1 100644 --- a/Source/Core/DolphinQt/Settings.cpp +++ b/Source/Core/DolphinQt/Settings.cpp @@ -216,7 +216,7 @@ void Settings::GetToolTipStyle(QColor& window_color, QColor& text_color, QStringList Settings::GetPaths() const { QStringList list; - for (const auto& path : SConfig::GetInstance().m_ISOFolder) + for (const auto& path : Config::GetIsoPaths()) list << QString::fromStdString(path); return list; } @@ -224,25 +224,27 @@ QStringList Settings::GetPaths() const void Settings::AddPath(const QString& qpath) { std::string path = qpath.toStdString(); + std::vector paths = Config::GetIsoPaths(); - std::vector& paths = SConfig::GetInstance().m_ISOFolder; if (std::find(paths.begin(), paths.end(), path) != paths.end()) return; paths.emplace_back(path); + Config::SetIsoPaths(paths); emit PathAdded(qpath); } void Settings::RemovePath(const QString& qpath) { std::string path = qpath.toStdString(); - std::vector& paths = SConfig::GetInstance().m_ISOFolder; + std::vector paths = Config::GetIsoPaths(); auto new_end = std::remove(paths.begin(), paths.end(), path); if (new_end == paths.end()) return; paths.erase(new_end, paths.end()); + Config::SetIsoPaths(paths); emit PathRemoved(qpath); } diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 2a1d861ac5..155cd8e2c5 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -555,8 +555,6 @@ void Renderer::CheckForConfigChanges() // Create On-Screen-Messages void Renderer::DrawDebugText() { - const auto& config = SConfig::GetInstance(); - if (g_ActiveConfig.bShowFPS) { // Position in the top-right corner of the screen. @@ -576,10 +574,10 @@ void Renderer::DrawDebugText() ImGui::End(); } - const bool show_movie_window = config.m_ShowFrameCount || config.m_ShowLag || - Config::Get(Config::MAIN_MOVIE_SHOW_INPUT_DISPLAY) || - Config::Get(Config::MAIN_MOVIE_SHOW_RTC) || - Config::Get(Config::MAIN_MOVIE_SHOW_RERECORD); + const bool show_movie_window = + Config::Get(Config::MAIN_SHOW_FRAME_COUNT) || Config::Get(Config::MAIN_SHOW_LAG) || + Config::Get(Config::MAIN_MOVIE_SHOW_INPUT_DISPLAY) || + Config::Get(Config::MAIN_MOVIE_SHOW_RTC) || Config::Get(Config::MAIN_MOVIE_SHOW_RERECORD); if (show_movie_window) { // Position under the FPS display. @@ -598,12 +596,12 @@ void Renderer::DrawDebugText() ImGui::Text("Input: %" PRIu64 " / %" PRIu64, Movie::GetCurrentInputCount(), Movie::GetTotalInputCount()); } - else if (config.m_ShowFrameCount) + else if (Config::Get(Config::MAIN_SHOW_FRAME_COUNT)) { ImGui::Text("Frame: %" PRIu64, Movie::GetCurrentFrame()); ImGui::Text("Input: %" PRIu64, Movie::GetCurrentInputCount()); } - if (SConfig::GetInstance().m_ShowLag) + if (Config::Get(Config::MAIN_SHOW_LAG)) ImGui::Text("Lag: %" PRIu64 "\n", Movie::GetCurrentLagCount()); if (Config::Get(Config::MAIN_MOVIE_SHOW_INPUT_DISPLAY)) ImGui::TextUnformatted(Movie::GetInputDisplay().c_str());