diff --git a/Source/Core/Common/Config/Config.cpp b/Source/Core/Common/Config/Config.cpp index 27f0389ea8..285db95f28 100644 --- a/Source/Core/Common/Config/Config.cpp +++ b/Source/Core/Common/Config/Config.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "Common/Assert.h" #include "Common/Config/Config.h" @@ -144,4 +145,34 @@ const std::string& GetLayerName(LayerType layer) }; return layer_to_name.at(layer); } + +bool ConfigLocation::operator==(const ConfigLocation& other) const +{ + return std::tie(system, section, key) == std::tie(other.system, other.section, other.key); +} + +bool ConfigLocation::operator!=(const ConfigLocation& other) const +{ + return !(*this == other); +} + +bool ConfigLocation::operator<(const ConfigLocation& other) const +{ + return std::tie(system, section, key) < std::tie(other.system, other.section, other.key); +} + +LayerType GetActiveLayerForConfig(const ConfigLocation& config) +{ + for (auto layer : SEARCH_ORDER) + { + if (!LayerExists(layer)) + continue; + + if (GetLayer(layer)->Exists(config.system, config.section, config.key)) + return layer; + } + + // If config is not present in any layer, base layer is considered active. + return LayerType::Base; +} } diff --git a/Source/Core/Common/Config/Config.h b/Source/Core/Common/Config/Config.h index 3ce1833345..d839569ace 100644 --- a/Source/Core/Common/Config/Config.h +++ b/Source/Core/Common/Config/Config.h @@ -15,6 +15,24 @@ namespace Config { +struct ConfigLocation +{ + System system; + std::string section; + std::string key; + + bool operator==(const ConfigLocation& other) const; + bool operator!=(const ConfigLocation& other) const; + bool operator<(const ConfigLocation& other) const; +}; + +template +struct ConfigInfo +{ + ConfigLocation location; + T default_value; +}; + using Layers = std::map>; using ConfigChangedCallback = std::function; @@ -45,4 +63,60 @@ void ClearCurrentRunLayer(); const std::string& GetSystemName(System system); System GetSystemFromName(const std::string& system); const std::string& GetLayerName(LayerType layer); +LayerType GetActiveLayerForConfig(const ConfigLocation&); + +template +T Get(LayerType layer, const ConfigInfo& info) +{ + return GetLayer(layer) + ->GetOrCreateSection(info.location.system, info.location.section) + ->template Get(info.location.key, info.default_value); +} + +template +T Get(const ConfigInfo& info) +{ + return Get(LayerType::Meta, info); +} + +template +T GetBase(const ConfigInfo& info) +{ + return Get(LayerType::Base, info); +} + +template +LayerType GetActiveLayerForConfig(const ConfigInfo& info) +{ + return GetActiveLayerForConfig(info.location); +} + +template +void Set(LayerType layer, const ConfigInfo& info, const T& value) +{ + GetLayer(layer) + ->GetOrCreateSection(info.location.system, info.location.section) + ->Set(info.location.key, value); +} + +template +void SetBase(const ConfigInfo& info, const T& value) +{ + Set(LayerType::Base, info, value); +} + +template +void SetCurrent(const ConfigInfo& info, const T& value) +{ + Set(LayerType::CurrentRun, info, value); +} + +template +void SetBaseOrCurrent(const ConfigInfo& info, const T& value) +{ + if (GetActiveLayerForConfig(info) == LayerType::Base) + Set(LayerType::Base, info, value); + else + Set(LayerType::CurrentRun, info, value); +} } diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 679e68f59b..45d10de6a2 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -9,8 +9,8 @@ #include #include "Common/CommonPaths.h" +#include "Common/Config/Config.h" #include "Common/FileUtil.h" -#include "Common/IniFile.h" #include "Common/Logging/ConsoleListener.h" #include "Common/Logging/Log.h" #include "Common/Logging/LogManager.h" @@ -19,6 +19,14 @@ constexpr size_t MAX_MSGLEN = 1024; +const Config::ConfigInfo LOGGER_WRITE_TO_FILE{ + {Config::System::Logger, "Options", "WriteToFile"}, false}; +const Config::ConfigInfo LOGGER_WRITE_TO_CONSOLE{ + {Config::System::Logger, "Options", "WriteToConsole"}, true}; +const Config::ConfigInfo LOGGER_WRITE_TO_WINDOW{ + {Config::System::Logger, "Options", "WriteToWindow"}, true}; +const Config::ConfigInfo LOGGER_VERBOSITY{{Config::System::Logger, "Options", "Verbosity"}, 0}; + class FileLogListener : public LogListener { public: @@ -40,7 +48,6 @@ public: bool IsValid() const { return m_logfile.good(); } bool IsEnabled() const { return m_enable; } void SetEnable(bool enable) { m_enable = enable; } - // const char* GetName() const { return "file"; } private: std::mutex m_log_lock; std::ofstream m_logfile; @@ -121,20 +128,9 @@ LogManager::LogManager() new FileLogListener(File::GetUserPath(F_MAINLOG_IDX))); RegisterListener(LogListener::CONSOLE_LISTENER, new ConsoleListener()); - IniFile ini; - ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX)); - IniFile::Section* logs = ini.GetOrCreateSection("Logs"); - IniFile::Section* options = ini.GetOrCreateSection("Options"); - bool write_file; - bool write_console; - bool write_window; - options->Get("WriteToFile", &write_file, false); - options->Get("WriteToConsole", &write_console, true); - options->Get("WriteToWindow", &write_window, true); - // Set up log listeners - int verbosity; - options->Get("Verbosity", &verbosity, 0); + int verbosity = Config::Get(LOGGER_VERBOSITY); + ; // Ensure the verbosity level is valid if (verbosity < 1) @@ -143,12 +139,13 @@ LogManager::LogManager() verbosity = MAX_LOGLEVEL; SetLogLevel(static_cast(verbosity)); - EnableListener(LogListener::FILE_LISTENER, write_file); - EnableListener(LogListener::CONSOLE_LISTENER, write_console); - EnableListener(LogListener::LOG_WINDOW_LISTENER, write_window); + EnableListener(LogListener::FILE_LISTENER, Config::Get(LOGGER_WRITE_TO_FILE)); + EnableListener(LogListener::CONSOLE_LISTENER, Config::Get(LOGGER_WRITE_TO_CONSOLE)); + EnableListener(LogListener::LOG_WINDOW_LISTENER, Config::Get(LOGGER_WRITE_TO_WINDOW)); for (LogContainer& container : m_log) - logs->Get(container.m_short_name, &container.m_enable, false); + container.m_enable = Config::Get( + Config::ConfigInfo{{Config::System::Logger, "Logs", container.m_short_name}, false}); m_path_cutoff_point = DeterminePathCutOffPoint(); } @@ -162,20 +159,18 @@ LogManager::~LogManager() void LogManager::SaveSettings() { - IniFile ini; - ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX)); + Config::SetBaseOrCurrent(LOGGER_WRITE_TO_FILE, IsListenerEnabled(LogListener::FILE_LISTENER)); + Config::SetBaseOrCurrent(LOGGER_WRITE_TO_CONSOLE, + IsListenerEnabled(LogListener::CONSOLE_LISTENER)); + Config::SetBaseOrCurrent(LOGGER_WRITE_TO_WINDOW, + IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER)); + Config::SetBaseOrCurrent(LOGGER_VERBOSITY, static_cast(GetLogLevel())); - IniFile::Section* options = ini.GetOrCreateSection("Options"); - options->Set("Verbosity", GetLogLevel()); - options->Set("WriteToFile", m_listener_ids[LogListener::FILE_LISTENER]); - options->Set("WriteToConsole", m_listener_ids[LogListener::CONSOLE_LISTENER]); - options->Set("WriteToWindow", m_listener_ids[LogListener::LOG_WINDOW_LISTENER]); - - // Save all enabled/disabled states of the log types to the config ini. for (const auto& container : m_log) - ini.GetOrCreateSection("Logs")->Set(container.m_short_name, container.m_enable); + Config::SetBaseOrCurrent({{Config::System::Logger, "Logs", container.m_short_name}, false}, + container.m_enable); - ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX)); + Config::Save(); } void LogManager::Log(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type, const char* file, diff --git a/Source/Core/Core/BootManager.cpp b/Source/Core/Core/BootManager.cpp index 7738e0897c..cffa64bbb8 100644 --- a/Source/Core/Core/BootManager.cpp +++ b/Source/Core/Core/BootManager.cpp @@ -31,8 +31,8 @@ #include "Common/MsgHandler.h" #include "Common/StringUtil.h" +#include "Common/Config/Config.h" #include "Core/Boot/Boot.h" -#include "Core/Config/Config.h" #include "Core/ConfigLoaders/GameConfigLoader.h" #include "Core/ConfigLoaders/NetPlayConfigLoader.h" #include "Core/ConfigManager.h" diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 498cb8e9f2..761eee33e3 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -25,7 +25,6 @@ set(SRCS Boot/Boot_WiiWAD.cpp Boot/DolReader.cpp Boot/ElfReader.cpp - Config/Config.cpp Config/GraphicsSettings.cpp ConfigLoaders/BaseConfigLoader.cpp ConfigLoaders/GameConfigLoader.cpp diff --git a/Source/Core/Core/Config/Config.cpp b/Source/Core/Core/Config/Config.cpp deleted file mode 100644 index f4d5991c23..0000000000 --- a/Source/Core/Core/Config/Config.cpp +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#include "Core/Config/Config.h" - -#include - -namespace Config -{ -bool ConfigLocation::operator==(const ConfigLocation& other) const -{ - return std::tie(system, section, key) == std::tie(other.system, other.section, other.key); -} - -bool ConfigLocation::operator!=(const ConfigLocation& other) const -{ - return !(*this == other); -} - -bool ConfigLocation::operator<(const ConfigLocation& other) const -{ - return std::tie(system, section, key) < std::tie(other.system, other.section, other.key); -} - -LayerType GetActiveLayerForConfig(const ConfigLocation& config) -{ - for (auto layer : SEARCH_ORDER) - { - if (!LayerExists(layer)) - continue; - - if (GetLayer(layer)->Exists(config.system, config.section, config.key)) - return layer; - } - - // If config is not present in any layer, base layer is considered active. - return LayerType::Base; -} - -} // namespace Config diff --git a/Source/Core/Core/Config/Config.h b/Source/Core/Core/Config/Config.h deleted file mode 100644 index 846f016c25..0000000000 --- a/Source/Core/Core/Config/Config.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2017 Dolphin Emulator Project -// Licensed under GPLv2+ -// Refer to the license.txt file included. - -#pragma once - -#include - -#include "Common/Config/Config.h" -#include "Common/Config/Enums.h" - -namespace Config -{ -struct ConfigLocation -{ - System system; - std::string section; - std::string key; - - bool operator==(const ConfigLocation& other) const; - bool operator!=(const ConfigLocation& other) const; - bool operator<(const ConfigLocation& other) const; -}; - -template -struct ConfigInfo -{ - ConfigLocation location; - T default_value; -}; - -template -T Get(LayerType layer, const ConfigInfo& info) -{ - return GetLayer(layer) - ->GetOrCreateSection(info.location.system, info.location.section) - ->template Get(info.location.key, info.default_value); -} - -template -T Get(const ConfigInfo& info) -{ - return Get(LayerType::Meta, info); -} - -template -T GetBase(const ConfigInfo& info) -{ - return Get(LayerType::Base, info); -} - -LayerType GetActiveLayerForConfig(const ConfigLocation&); - -template -LayerType GetActiveLayerForConfig(const ConfigInfo& info) -{ - return GetActiveLayerForConfig(info.location); -} - -template -void Set(LayerType layer, const ConfigInfo& info, const T& value) -{ - GetLayer(layer) - ->GetOrCreateSection(info.location.system, info.location.section) - ->Set(info.location.key, value); - InvokeConfigChangedCallbacks(); -} - -template -void SetBase(const ConfigInfo& info, const T& value) -{ - Set(LayerType::Base, info, value); -} - -template -void SetCurrent(const ConfigInfo& info, const T& value) -{ - Set(LayerType::CurrentRun, info, value); -} - -template -void SetBaseOrCurrent(const ConfigInfo& info, const T& value) -{ - if (GetActiveLayerForConfig(info) == LayerType::Base) - Set(LayerType::Base, info, value); - else - Set(LayerType::CurrentRun, info, value); -} - -} // namespace Config diff --git a/Source/Core/Core/Config/GraphicsSettings.cpp b/Source/Core/Core/Config/GraphicsSettings.cpp index da553068d0..f467c8e911 100644 --- a/Source/Core/Core/Config/GraphicsSettings.cpp +++ b/Source/Core/Core/Config/GraphicsSettings.cpp @@ -6,7 +6,7 @@ #include -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" #include "VideoCommon/VideoConfig.h" namespace Config diff --git a/Source/Core/Core/Config/GraphicsSettings.h b/Source/Core/Core/Config/GraphicsSettings.h index 8325aea3b1..af2cf8ed1d 100644 --- a/Source/Core/Core/Config/GraphicsSettings.h +++ b/Source/Core/Core/Config/GraphicsSettings.h @@ -6,7 +6,7 @@ #include -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" namespace Config { diff --git a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp index e19e868f7c..72e86a4a1f 100644 --- a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp @@ -16,7 +16,7 @@ #include "Common/IniFile.h" #include "Common/Logging/Log.h" -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" #include "Core/ConfigLoaders/IsSettingSaveable.h" namespace ConfigLoaders diff --git a/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp index eea16b7b27..db7d15579c 100644 --- a/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp +++ b/Source/Core/Core/ConfigLoaders/GameConfigLoader.cpp @@ -23,7 +23,7 @@ #include "Common/MsgHandler.h" #include "Common/StringUtil.h" -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" #include "Core/Config/GraphicsSettings.h" #include "Core/ConfigLoaders/IsSettingSaveable.h" diff --git a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp index 22247c486f..38ea90710f 100644 --- a/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp +++ b/Source/Core/Core/ConfigLoaders/IsSettingSaveable.cpp @@ -7,13 +7,16 @@ #include #include -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" #include "Core/Config/GraphicsSettings.h" namespace ConfigLoaders { bool IsSettingSaveable(const Config::ConfigLocation& config_location) { + if (config_location.system == Config::System::Logger) + return true; + const static std::vector s_setting_saveable{ // Graphics.Hardware diff --git a/Source/Core/Core/Core.vcxproj b/Source/Core/Core/Core.vcxproj index cee0beb8df..a5d8c85456 100644 --- a/Source/Core/Core/Core.vcxproj +++ b/Source/Core/Core/Core.vcxproj @@ -45,7 +45,6 @@ - @@ -301,7 +300,6 @@ - diff --git a/Source/Core/Core/Core.vcxproj.filters b/Source/Core/Core/Core.vcxproj.filters index 76c5fcff0d..49b139432a 100644 --- a/Source/Core/Core/Core.vcxproj.filters +++ b/Source/Core/Core/Core.vcxproj.filters @@ -871,9 +871,6 @@ ConfigLoader - - Config - Config @@ -1523,9 +1520,6 @@ ConfigLoader - - Config - Config diff --git a/Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.cpp b/Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.cpp index dae8431c0b..e05e9d94c0 100644 --- a/Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.cpp +++ b/Source/Core/DolphinQt2/Config/Graphics/GraphicsBool.cpp @@ -4,7 +4,7 @@ #include "DolphinQt2/Config/Graphics/GraphicsBool.h" -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" #include diff --git a/Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.cpp b/Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.cpp index 9fbc537894..65546ed718 100644 --- a/Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.cpp +++ b/Source/Core/DolphinQt2/Config/Graphics/GraphicsChoice.cpp @@ -4,7 +4,7 @@ #include "DolphinQt2/Config/Graphics/GraphicsChoice.h" -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" GraphicsChoice::GraphicsChoice(const QStringList& options, const Config::ConfigInfo& setting) : m_setting(setting) diff --git a/Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.cpp b/Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.cpp index b15f3018d2..e78be6eb82 100644 --- a/Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.cpp +++ b/Source/Core/DolphinQt2/Config/Graphics/GraphicsSlider.cpp @@ -4,7 +4,7 @@ #include "DolphinQt2/Config/Graphics/GraphicsSlider.h" -#include "Core/Config/Config.h" +#include "Common/Config/Config.h" GraphicsSlider::GraphicsSlider(int minimum, int maximum, const Config::ConfigInfo& setting, int tick) diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp index 9c45a5c0d9..691644edf5 100644 --- a/Source/Core/UICommon/UICommon.cpp +++ b/Source/Core/UICommon/UICommon.cpp @@ -32,10 +32,10 @@ namespace UICommon { void Init() { - LogManager::Init(); Config::Init(); Config::AddLoadLayer(ConfigLoaders::GenerateBaseConfigLoader()); SConfig::Init(); + LogManager::Init(); VideoBackendBase::PopulateList(); WiimoteReal::LoadSettings(); GCAdapter::Init(); @@ -49,9 +49,9 @@ void Shutdown() GCAdapter::Shutdown(); WiimoteReal::Shutdown(); VideoBackendBase::ClearList(); + LogManager::Shutdown(); SConfig::Shutdown(); Config::Shutdown(); - LogManager::Shutdown(); } void CreateDirectories() diff --git a/Source/UnitTests/Core/CoreTimingTest.cpp b/Source/UnitTests/Core/CoreTimingTest.cpp index ca2e08bb56..2723c90d2a 100644 --- a/Source/UnitTests/Core/CoreTimingTest.cpp +++ b/Source/UnitTests/Core/CoreTimingTest.cpp @@ -8,8 +8,8 @@ #include #include +#include "Common/Config/Config.h" #include "Common/FileUtil.h" -#include "Core/Config/Config.h" #include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/CoreTiming.h" @@ -55,6 +55,7 @@ public: Core::UndeclareAsCPUThread(); File::DeleteDirRecursively(m_profile_path); } + private: std::string m_profile_path; }; diff --git a/Source/UnitTests/Core/MMIOTest.cpp b/Source/UnitTests/Core/MMIOTest.cpp index b54d82d27d..04bf850a96 100644 --- a/Source/UnitTests/Core/MMIOTest.cpp +++ b/Source/UnitTests/Core/MMIOTest.cpp @@ -7,8 +7,8 @@ #include #include "Common/CommonTypes.h" +#include "Common/Config/Config.h" #include "Common/FileUtil.h" -#include "Core/Config/Config.h" #include "Core/HW/MMIO.h" #include "UICommon/UICommon.h"