mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 21:30:19 -06:00
Merge Core/Config/Config.h into Common/Config/Config.h
Allows code in Common to take advantage of the layered config logic.
This commit is contained in:
@ -5,6 +5,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <tuple>
|
||||||
|
|
||||||
#include "Common/Assert.h"
|
#include "Common/Assert.h"
|
||||||
#include "Common/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
@ -144,4 +145,34 @@ const std::string& GetLayerName(LayerType layer)
|
|||||||
};
|
};
|
||||||
return layer_to_name.at(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,24 @@
|
|||||||
|
|
||||||
namespace Config
|
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 <typename T>
|
||||||
|
struct ConfigInfo
|
||||||
|
{
|
||||||
|
ConfigLocation location;
|
||||||
|
T default_value;
|
||||||
|
};
|
||||||
|
|
||||||
using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
|
using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
|
||||||
using ConfigChangedCallback = std::function<void()>;
|
using ConfigChangedCallback = std::function<void()>;
|
||||||
|
|
||||||
@ -45,4 +63,60 @@ void ClearCurrentRunLayer();
|
|||||||
const std::string& GetSystemName(System system);
|
const std::string& GetSystemName(System system);
|
||||||
System GetSystemFromName(const std::string& system);
|
System GetSystemFromName(const std::string& system);
|
||||||
const std::string& GetLayerName(LayerType layer);
|
const std::string& GetLayerName(LayerType layer);
|
||||||
|
LayerType GetActiveLayerForConfig(const ConfigLocation&);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T Get(LayerType layer, const ConfigInfo<T>& info)
|
||||||
|
{
|
||||||
|
return GetLayer(layer)
|
||||||
|
->GetOrCreateSection(info.location.system, info.location.section)
|
||||||
|
->template Get<T>(info.location.key, info.default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T Get(const ConfigInfo<T>& info)
|
||||||
|
{
|
||||||
|
return Get(LayerType::Meta, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T GetBase(const ConfigInfo<T>& info)
|
||||||
|
{
|
||||||
|
return Get(LayerType::Base, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
|
||||||
|
{
|
||||||
|
return GetActiveLayerForConfig(info.location);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
|
||||||
|
{
|
||||||
|
GetLayer(layer)
|
||||||
|
->GetOrCreateSection(info.location.system, info.location.section)
|
||||||
|
->Set(info.location.key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void SetBase(const ConfigInfo<T>& info, const T& value)
|
||||||
|
{
|
||||||
|
Set<T>(LayerType::Base, info, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void SetCurrent(const ConfigInfo<T>& info, const T& value)
|
||||||
|
{
|
||||||
|
Set<T>(LayerType::CurrentRun, info, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void SetBaseOrCurrent(const ConfigInfo<T>& info, const T& value)
|
||||||
|
{
|
||||||
|
if (GetActiveLayerForConfig(info) == LayerType::Base)
|
||||||
|
Set<T>(LayerType::Base, info, value);
|
||||||
|
else
|
||||||
|
Set<T>(LayerType::CurrentRun, info, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@
|
|||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
|
#include "Common/Config/Config.h"
|
||||||
#include "Core/Boot/Boot.h"
|
#include "Core/Boot/Boot.h"
|
||||||
#include "Core/Config/Config.h"
|
|
||||||
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
#include "Core/ConfigLoaders/GameConfigLoader.h"
|
||||||
#include "Core/ConfigLoaders/NetPlayConfigLoader.h"
|
#include "Core/ConfigLoaders/NetPlayConfigLoader.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
@ -25,7 +25,6 @@ set(SRCS
|
|||||||
Boot/Boot_WiiWAD.cpp
|
Boot/Boot_WiiWAD.cpp
|
||||||
Boot/DolReader.cpp
|
Boot/DolReader.cpp
|
||||||
Boot/ElfReader.cpp
|
Boot/ElfReader.cpp
|
||||||
Config/Config.cpp
|
|
||||||
Config/GraphicsSettings.cpp
|
Config/GraphicsSettings.cpp
|
||||||
ConfigLoaders/BaseConfigLoader.cpp
|
ConfigLoaders/BaseConfigLoader.cpp
|
||||||
ConfigLoaders/GameConfigLoader.cpp
|
ConfigLoaders/GameConfigLoader.cpp
|
||||||
|
@ -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 <tuple>
|
|
||||||
|
|
||||||
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
|
|
@ -1,90 +0,0 @@
|
|||||||
// Copyright 2017 Dolphin Emulator Project
|
|
||||||
// Licensed under GPLv2+
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#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 <typename T>
|
|
||||||
struct ConfigInfo
|
|
||||||
{
|
|
||||||
ConfigLocation location;
|
|
||||||
T default_value;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T Get(LayerType layer, const ConfigInfo<T>& info)
|
|
||||||
{
|
|
||||||
return GetLayer(layer)
|
|
||||||
->GetOrCreateSection(info.location.system, info.location.section)
|
|
||||||
->template Get<T>(info.location.key, info.default_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T Get(const ConfigInfo<T>& info)
|
|
||||||
{
|
|
||||||
return Get(LayerType::Meta, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
T GetBase(const ConfigInfo<T>& info)
|
|
||||||
{
|
|
||||||
return Get(LayerType::Base, info);
|
|
||||||
}
|
|
||||||
|
|
||||||
LayerType GetActiveLayerForConfig(const ConfigLocation&);
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
|
|
||||||
{
|
|
||||||
return GetActiveLayerForConfig(info.location);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
|
|
||||||
{
|
|
||||||
GetLayer(layer)
|
|
||||||
->GetOrCreateSection(info.location.system, info.location.section)
|
|
||||||
->Set(info.location.key, value);
|
|
||||||
InvokeConfigChangedCallbacks();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void SetBase(const ConfigInfo<T>& info, const T& value)
|
|
||||||
{
|
|
||||||
Set<T>(LayerType::Base, info, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void SetCurrent(const ConfigInfo<T>& info, const T& value)
|
|
||||||
{
|
|
||||||
Set<T>(LayerType::CurrentRun, info, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void SetBaseOrCurrent(const ConfigInfo<T>& info, const T& value)
|
|
||||||
{
|
|
||||||
if (GetActiveLayerForConfig(info) == LayerType::Base)
|
|
||||||
Set<T>(LayerType::Base, info, value);
|
|
||||||
else
|
|
||||||
Set<T>(LayerType::CurrentRun, info, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Config
|
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Core/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "VideoCommon/VideoConfig.h"
|
#include "VideoCommon/VideoConfig.h"
|
||||||
|
|
||||||
namespace Config
|
namespace Config
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "Core/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
|
|
||||||
namespace Config
|
namespace Config
|
||||||
{
|
{
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "Common/IniFile.h"
|
#include "Common/IniFile.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
#include "Core/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "Core/ConfigLoaders/IsSettingSaveable.h"
|
#include "Core/ConfigLoaders/IsSettingSaveable.h"
|
||||||
|
|
||||||
namespace ConfigLoaders
|
namespace ConfigLoaders
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#include "Common/MsgHandler.h"
|
#include "Common/MsgHandler.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
|
||||||
#include "Core/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "Core/Config/GraphicsSettings.h"
|
#include "Core/Config/GraphicsSettings.h"
|
||||||
#include "Core/ConfigLoaders/IsSettingSaveable.h"
|
#include "Core/ConfigLoaders/IsSettingSaveable.h"
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Core/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
#include "Core/Config/GraphicsSettings.h"
|
#include "Core/Config/GraphicsSettings.h"
|
||||||
|
|
||||||
namespace ConfigLoaders
|
namespace ConfigLoaders
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
<ClCompile Include="Boot\Boot_WiiWAD.cpp" />
|
<ClCompile Include="Boot\Boot_WiiWAD.cpp" />
|
||||||
<ClCompile Include="Boot\DolReader.cpp" />
|
<ClCompile Include="Boot\DolReader.cpp" />
|
||||||
<ClCompile Include="Boot\ElfReader.cpp" />
|
<ClCompile Include="Boot\ElfReader.cpp" />
|
||||||
<ClCompile Include="Config\Config.cpp" />
|
|
||||||
<ClCompile Include="Config\GraphicsSettings.cpp" />
|
<ClCompile Include="Config\GraphicsSettings.cpp" />
|
||||||
<ClCompile Include="ConfigLoaders\BaseConfigLoader.cpp" />
|
<ClCompile Include="ConfigLoaders\BaseConfigLoader.cpp" />
|
||||||
<ClCompile Include="ConfigLoaders\GameConfigLoader.cpp" />
|
<ClCompile Include="ConfigLoaders\GameConfigLoader.cpp" />
|
||||||
@ -301,7 +300,6 @@
|
|||||||
<ClInclude Include="Boot\DolReader.h" />
|
<ClInclude Include="Boot\DolReader.h" />
|
||||||
<ClInclude Include="Boot\ElfReader.h" />
|
<ClInclude Include="Boot\ElfReader.h" />
|
||||||
<ClInclude Include="Boot\ElfTypes.h" />
|
<ClInclude Include="Boot\ElfTypes.h" />
|
||||||
<ClInclude Include="Config\Config.h" />
|
|
||||||
<ClInclude Include="Config\GraphicsSettings.h" />
|
<ClInclude Include="Config\GraphicsSettings.h" />
|
||||||
<ClInclude Include="ConfigLoaders\BaseConfigLoader.h" />
|
<ClInclude Include="ConfigLoaders\BaseConfigLoader.h" />
|
||||||
<ClInclude Include="ConfigLoaders\GameConfigLoader.h" />
|
<ClInclude Include="ConfigLoaders\GameConfigLoader.h" />
|
||||||
|
@ -871,9 +871,6 @@
|
|||||||
<ClCompile Include="ConfigLoaders\IsSettingSaveable.cpp">
|
<ClCompile Include="ConfigLoaders\IsSettingSaveable.cpp">
|
||||||
<Filter>ConfigLoader</Filter>
|
<Filter>ConfigLoader</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Config\Config.cpp">
|
|
||||||
<Filter>Config</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Config\GraphicsSettings.cpp">
|
<ClCompile Include="Config\GraphicsSettings.cpp">
|
||||||
<Filter>Config</Filter>
|
<Filter>Config</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -1523,9 +1520,6 @@
|
|||||||
<ClInclude Include="ConfigLoaders\IsSettingSaveable.h">
|
<ClInclude Include="ConfigLoaders\IsSettingSaveable.h">
|
||||||
<Filter>ConfigLoader</Filter>
|
<Filter>ConfigLoader</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Config\Config.h">
|
|
||||||
<Filter>Config</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Config\GraphicsSettings.h">
|
<ClInclude Include="Config\GraphicsSettings.h">
|
||||||
<Filter>Config</Filter>
|
<Filter>Config</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "DolphinQt2/Config/Graphics/GraphicsBool.h"
|
#include "DolphinQt2/Config/Graphics/GraphicsBool.h"
|
||||||
|
|
||||||
#include "Core/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "DolphinQt2/Config/Graphics/GraphicsChoice.h"
|
#include "DolphinQt2/Config/Graphics/GraphicsChoice.h"
|
||||||
|
|
||||||
#include "Core/Config/Config.h"
|
#include "Common/Config/Config.h"
|
||||||
|
|
||||||
GraphicsChoice::GraphicsChoice(const QStringList& options, const Config::ConfigInfo<int>& setting)
|
GraphicsChoice::GraphicsChoice(const QStringList& options, const Config::ConfigInfo<int>& setting)
|
||||||
: m_setting(setting)
|
: m_setting(setting)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include "DolphinQt2/Config/Graphics/GraphicsSlider.h"
|
#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<int>& setting,
|
GraphicsSlider::GraphicsSlider(int minimum, int maximum, const Config::ConfigInfo<int>& setting,
|
||||||
int tick)
|
int tick)
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
#include <bitset>
|
#include <bitset>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "Common/Config/Config.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Core/Config/Config.h"
|
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/Core.h"
|
#include "Core/Core.h"
|
||||||
#include "Core/CoreTiming.h"
|
#include "Core/CoreTiming.h"
|
||||||
@ -55,6 +55,7 @@ public:
|
|||||||
Core::UndeclareAsCPUThread();
|
Core::UndeclareAsCPUThread();
|
||||||
File::DeleteDirRecursively(m_profile_path);
|
File::DeleteDirRecursively(m_profile_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_profile_path;
|
std::string m_profile_path;
|
||||||
};
|
};
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
|
#include "Common/Config/Config.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Core/Config/Config.h"
|
|
||||||
#include "Core/HW/MMIO.h"
|
#include "Core/HW/MMIO.h"
|
||||||
#include "UICommon/UICommon.h"
|
#include "UICommon/UICommon.h"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user