mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 17:19:44 -06:00
Config: Flatten structures
Originally, Layer contained a std::map of Sections, which containted a std::map containing the (key, value) pairs. Here we flattern this structure so that only one std::map is required, reducing the number of indirections required and vastly simplifying the code.
This commit is contained in:
@ -61,6 +61,7 @@ ConfigInfo<bool> GetInfoForSimulateKonga(u32 channel)
|
||||
}
|
||||
|
||||
const ConfigInfo<bool> MAIN_WII_SD_CARD{{System::Main, "Core", "WiiSDCard"}, false};
|
||||
const ConfigInfo<bool> MAIN_WII_SD_CARD_WRITABLE{{System::Main, "Core", "WiiSDCardWritable"}, true};
|
||||
const ConfigInfo<bool> MAIN_WII_KEYBOARD{{System::Main, "Core", "WiiKeyboard"}, false};
|
||||
const ConfigInfo<bool> MAIN_WIIMOTE_CONTINUOUS_SCANNING{
|
||||
{System::Main, "Core", "WiimoteContinuousScanning"}, false};
|
||||
|
@ -40,6 +40,7 @@ ConfigInfo<u32> GetInfoForSIDevice(u32 channel);
|
||||
ConfigInfo<bool> GetInfoForAdapterRumble(u32 channel);
|
||||
ConfigInfo<bool> GetInfoForSimulateKonga(u32 channel);
|
||||
extern const ConfigInfo<bool> MAIN_WII_SD_CARD;
|
||||
extern const ConfigInfo<bool> MAIN_WII_SD_CARD_WRITABLE;
|
||||
extern const ConfigInfo<bool> MAIN_WII_KEYBOARD;
|
||||
extern const ConfigInfo<bool> MAIN_WIIMOTE_CONTINUOUS_SCANNING;
|
||||
extern const ConfigInfo<bool> MAIN_WIIMOTE_ENABLE_SPEAKER;
|
||||
|
@ -77,9 +77,9 @@ class BaseConfigLayerLoader final : public Config::ConfigLayerLoader
|
||||
{
|
||||
public:
|
||||
BaseConfigLayerLoader() : ConfigLayerLoader(Config::LayerType::Base) {}
|
||||
void Load(Config::Layer* config_layer) override
|
||||
void Load(Config::Layer* layer) override
|
||||
{
|
||||
LoadFromSYSCONF(config_layer);
|
||||
LoadFromSYSCONF(layer);
|
||||
for (const auto& system : system_to_ini)
|
||||
{
|
||||
IniFile ini;
|
||||
@ -89,55 +89,62 @@ public:
|
||||
for (const auto& section : system_sections)
|
||||
{
|
||||
const std::string section_name = section.GetName();
|
||||
Config::Section* config_section =
|
||||
config_layer->GetOrCreateSection(system.first, section_name);
|
||||
const IniFile::Section::SectionMap& section_map = section.GetValues();
|
||||
|
||||
for (const auto& value : section_map)
|
||||
config_section->Set(value.first, value.second);
|
||||
{
|
||||
const Config::ConfigLocation location{system.first, section_name, value.first};
|
||||
layer->Set(location, value.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Save(Config::Layer* config_layer) override
|
||||
void Save(Config::Layer* layer) override
|
||||
{
|
||||
const Config::LayerMap& sections = config_layer->GetLayerMap();
|
||||
for (const auto& system : sections)
|
||||
{
|
||||
if (system.first == Config::System::SYSCONF)
|
||||
{
|
||||
SaveToSYSCONF(config_layer->GetLayer());
|
||||
continue;
|
||||
}
|
||||
SaveToSYSCONF(layer->GetLayer());
|
||||
|
||||
auto mapping = system_to_ini.find(system.first);
|
||||
if (mapping == system_to_ini.end())
|
||||
std::map<Config::System, IniFile> inis;
|
||||
|
||||
for (const auto& system : system_to_ini)
|
||||
{
|
||||
inis[system.first].Load(File::GetUserPath(system.second));
|
||||
}
|
||||
|
||||
for (const auto& config : layer->GetLayerMap())
|
||||
{
|
||||
const Config::ConfigLocation& location = config.first;
|
||||
const std::optional<std::string>& value = config.second;
|
||||
|
||||
// Done by SaveToSYSCONF
|
||||
if (location.system == Config::System::SYSCONF)
|
||||
continue;
|
||||
|
||||
auto ini = inis.find(location.system);
|
||||
if (ini == inis.end())
|
||||
{
|
||||
ERROR_LOG(COMMON, "Config can't map system '%s' to an INI file!",
|
||||
Config::GetSystemName(system.first).c_str());
|
||||
Config::GetSystemName(location.system).c_str());
|
||||
continue;
|
||||
}
|
||||
|
||||
IniFile ini;
|
||||
ini.Load(File::GetUserPath(mapping->second));
|
||||
if (!IsSettingSaveable(location))
|
||||
continue;
|
||||
|
||||
for (const auto& section : system.second)
|
||||
if (value)
|
||||
{
|
||||
const std::string section_name = section->GetName();
|
||||
const Config::SectionValueMap& section_values = section->GetValues();
|
||||
|
||||
IniFile::Section* ini_section = ini.GetOrCreateSection(section_name);
|
||||
|
||||
for (const auto& value : section_values)
|
||||
{
|
||||
if (!IsSettingSaveable({system.first, section->GetName(), value.first}))
|
||||
continue;
|
||||
|
||||
ini_section->Set(value.first, value.second);
|
||||
}
|
||||
IniFile::Section* ini_section = ini->second.GetOrCreateSection(location.section);
|
||||
ini_section->Set(location.key, *value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ini->second.DeleteKey(location.section, location.key);
|
||||
}
|
||||
}
|
||||
|
||||
ini.Save(File::GetUserPath(mapping->second));
|
||||
for (const auto& system : system_to_ini)
|
||||
{
|
||||
inis[system.first].Save(File::GetUserPath(system.second));
|
||||
}
|
||||
}
|
||||
|
||||
@ -153,13 +160,10 @@ private:
|
||||
std::visit(
|
||||
[&](auto& info) {
|
||||
const std::string key = info.location.section + "." + info.location.key;
|
||||
auto* section =
|
||||
layer->GetOrCreateSection(Config::System::SYSCONF, info.location.section);
|
||||
|
||||
if (setting.type == SysConf::Entry::Type::Long)
|
||||
section->Set(info.location.key, sysconf.GetData<u32>(key, info.default_value));
|
||||
layer->Set(info.location, sysconf.GetData<u32>(key, info.default_value));
|
||||
else if (setting.type == SysConf::Entry::Type::Byte)
|
||||
section->Set(info.location.key, sysconf.GetData<u8>(key, info.default_value));
|
||||
layer->Set(info.location, sysconf.GetData<u8>(key, info.default_value));
|
||||
},
|
||||
setting.config_info);
|
||||
}
|
||||
|
@ -199,10 +199,10 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void Load(Config::Layer* config_layer) override
|
||||
void Load(Config::Layer* layer) override
|
||||
{
|
||||
IniFile ini;
|
||||
if (config_layer->GetLayer() == Config::LayerType::GlobalGame)
|
||||
if (layer->GetLayer() == Config::LayerType::GlobalGame)
|
||||
{
|
||||
for (const std::string& filename : GetGameIniFilenames(m_id, m_revision))
|
||||
ini.Load(File::GetSysDirectory() + GAMESETTINGS_DIR DIR_SEP + filename, true);
|
||||
@ -217,16 +217,16 @@ public:
|
||||
|
||||
for (const auto& section : system_sections)
|
||||
{
|
||||
LoadFromSystemSection(config_layer, section);
|
||||
LoadFromSystemSection(layer, section);
|
||||
}
|
||||
|
||||
LoadControllerConfig(config_layer);
|
||||
LoadControllerConfig(layer);
|
||||
}
|
||||
|
||||
void Save(Config::Layer* config_layer) override;
|
||||
void Save(Config::Layer* layer) override;
|
||||
|
||||
private:
|
||||
void LoadControllerConfig(Config::Layer* config_layer) const
|
||||
void LoadControllerConfig(Config::Layer* layer) const
|
||||
{
|
||||
// Game INIs can have controller profiles embedded in to them
|
||||
static const std::array<char, 4> nums = {{'1', '2', '3', '4'}};
|
||||
@ -244,82 +244,53 @@ private:
|
||||
std::string type = std::get<0>(use_data);
|
||||
std::string path = "Profiles/" + std::get<1>(use_data) + "/";
|
||||
|
||||
Config::Section* control_section =
|
||||
config_layer->GetOrCreateSection(std::get<2>(use_data), "Controls");
|
||||
const auto control_section = [&](std::string key) {
|
||||
return Config::ConfigLocation{std::get<2>(use_data), "Controls", key};
|
||||
};
|
||||
|
||||
for (const char num : nums)
|
||||
{
|
||||
bool use_profile = false;
|
||||
std::string profile;
|
||||
if (control_section->Exists(type + "Profile" + num))
|
||||
if (auto profile = layer->Get<std::string>(control_section(type + "Profile" + num)))
|
||||
{
|
||||
if (control_section->Get(type + "Profile" + num, &profile))
|
||||
std::string ini_path = File::GetUserPath(D_CONFIG_IDX) + path + *profile + ".ini";
|
||||
if (!File::Exists(ini_path))
|
||||
{
|
||||
if (File::Exists(File::GetUserPath(D_CONFIG_IDX) + path + profile + ".ini"))
|
||||
{
|
||||
use_profile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: PanicAlert shouldn't be used for this.
|
||||
PanicAlertT("Selected controller profile does not exist");
|
||||
}
|
||||
// TODO: PanicAlert shouldn't be used for this.
|
||||
PanicAlertT("Selected controller profile does not exist");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (use_profile)
|
||||
{
|
||||
IniFile profile_ini;
|
||||
profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile + ".ini");
|
||||
profile_ini.Load(ini_path);
|
||||
|
||||
const IniFile::Section* ini_section = profile_ini.GetOrCreateSection("Profile");
|
||||
const IniFile::Section::SectionMap& section_map = ini_section->GetValues();
|
||||
for (const auto& value : section_map)
|
||||
{
|
||||
Config::Section* section = config_layer->GetOrCreateSection(
|
||||
std::get<2>(use_data), std::get<1>(use_data) + num);
|
||||
section->Set(value.first, value.second);
|
||||
Config::ConfigLocation location{std::get<2>(use_data), std::get<1>(use_data) + num,
|
||||
value.first};
|
||||
layer->Set(location, value.second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoadFromSystemSection(Config::Layer* config_layer, const IniFile::Section& section) const
|
||||
void LoadFromSystemSection(Config::Layer* layer, const IniFile::Section& section) const
|
||||
{
|
||||
const std::string section_name = section.GetName();
|
||||
if (section.HasLines())
|
||||
{
|
||||
// Trash INI File chunks
|
||||
std::vector<std::string> chunk;
|
||||
section.GetLines(&chunk, true);
|
||||
|
||||
if (chunk.size())
|
||||
{
|
||||
const auto mapped_config = MapINIToRealLocation(section_name, "");
|
||||
|
||||
if (mapped_config.section.empty() && mapped_config.key.empty())
|
||||
return;
|
||||
|
||||
auto* config_section =
|
||||
config_layer->GetOrCreateSection(mapped_config.system, mapped_config.section);
|
||||
config_section->SetLines(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
// Regular key,value pairs
|
||||
const IniFile::Section::SectionMap& section_map = section.GetValues();
|
||||
|
||||
for (const auto& value : section_map)
|
||||
{
|
||||
const auto mapped_config = MapINIToRealLocation(section_name, value.first);
|
||||
const auto location = MapINIToRealLocation(section_name, value.first);
|
||||
|
||||
if (mapped_config.section.empty() && mapped_config.key.empty())
|
||||
if (location.section.empty() && location.key.empty())
|
||||
continue;
|
||||
|
||||
auto* config_section =
|
||||
config_layer->GetOrCreateSection(mapped_config.system, mapped_config.section);
|
||||
config_section->Set(mapped_config.key, value.second);
|
||||
layer->Set(location, value.second);
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,32 +298,35 @@ private:
|
||||
const u16 m_revision;
|
||||
};
|
||||
|
||||
void INIGameConfigLayerLoader::Save(Config::Layer* config_layer)
|
||||
void INIGameConfigLayerLoader::Save(Config::Layer* layer)
|
||||
{
|
||||
if (config_layer->GetLayer() != Config::LayerType::LocalGame)
|
||||
if (layer->GetLayer() != Config::LayerType::LocalGame)
|
||||
return;
|
||||
|
||||
IniFile ini;
|
||||
for (const std::string& file_name : GetGameIniFilenames(m_id, m_revision))
|
||||
ini.Load(File::GetUserPath(D_GAMESETTINGS_IDX) + file_name, true);
|
||||
|
||||
for (const auto& system : config_layer->GetLayerMap())
|
||||
for (const auto& config : layer->GetLayerMap())
|
||||
{
|
||||
for (const auto& section : system.second)
|
||||
const Config::ConfigLocation& location = config.first;
|
||||
const std::optional<std::string>& value = config.second;
|
||||
|
||||
if (!IsSettingSaveable(location))
|
||||
continue;
|
||||
|
||||
const auto ini_location = GetINILocationFromConfig(location);
|
||||
if (ini_location.first.empty() && ini_location.second.empty())
|
||||
continue;
|
||||
|
||||
if (value)
|
||||
{
|
||||
for (const auto& value : section->GetValues())
|
||||
{
|
||||
if (!IsSettingSaveable({system.first, section->GetName(), value.first}))
|
||||
continue;
|
||||
|
||||
const auto ini_location =
|
||||
GetINILocationFromConfig({system.first, section->GetName(), value.first});
|
||||
if (ini_location.first.empty() && ini_location.second.empty())
|
||||
continue;
|
||||
|
||||
IniFile::Section* ini_section = ini.GetOrCreateSection(ini_location.first);
|
||||
ini_section->Set(ini_location.second, value.second);
|
||||
}
|
||||
IniFile::Section* ini_section = ini.GetOrCreateSection(ini_location.first);
|
||||
ini_section->Set(ini_location.second, *value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ini.DeleteKey(ini_location.first, ini_location.second);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "Common/Config/Config.h"
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Config/SYSCONFSettings.h"
|
||||
#include "Core/NetPlayProto.h"
|
||||
|
||||
@ -20,29 +21,26 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void Load(Config::Layer* config_layer) override
|
||||
void Load(Config::Layer* layer) override
|
||||
{
|
||||
Config::Section* core = config_layer->GetOrCreateSection(Config::System::Main, "Core");
|
||||
Config::Section* dsp = config_layer->GetOrCreateSection(Config::System::Main, "DSP");
|
||||
layer->Set(Config::MAIN_CPU_THREAD, m_settings.m_CPUthread);
|
||||
layer->Set(Config::MAIN_CPU_CORE, m_settings.m_CPUcore);
|
||||
layer->Set(Config::MAIN_GC_LANGUAGE, m_settings.m_SelectedLanguage);
|
||||
layer->Set(Config::MAIN_OVERRIDE_GC_LANGUAGE, m_settings.m_OverrideGCLanguage);
|
||||
layer->Set(Config::MAIN_DSP_HLE, m_settings.m_DSPHLE);
|
||||
layer->Set(Config::MAIN_OVERCLOCK_ENABLE, m_settings.m_OCEnable);
|
||||
layer->Set(Config::MAIN_OVERCLOCK, m_settings.m_OCFactor);
|
||||
layer->Set(Config::MAIN_SLOT_A, static_cast<int>(m_settings.m_EXIDevice[0]));
|
||||
layer->Set(Config::MAIN_SLOT_B, static_cast<int>(m_settings.m_EXIDevice[1]));
|
||||
layer->Set(Config::MAIN_WII_SD_CARD_WRITABLE, m_settings.m_WriteToMemcard);
|
||||
|
||||
core->Set("CPUThread", m_settings.m_CPUthread);
|
||||
core->Set("CPUCore", m_settings.m_CPUcore);
|
||||
core->Set("SelectedLanguage", m_settings.m_SelectedLanguage);
|
||||
core->Set("OverrideGCLang", m_settings.m_OverrideGCLanguage);
|
||||
core->Set("DSPHLE", m_settings.m_DSPHLE);
|
||||
core->Set("OverclockEnable", m_settings.m_OCEnable);
|
||||
core->Set("Overclock", m_settings.m_OCFactor);
|
||||
core->Set("SlotA", m_settings.m_EXIDevice[0]);
|
||||
core->Set("SlotB", m_settings.m_EXIDevice[1]);
|
||||
core->Set("EnableSaving", m_settings.m_WriteToMemcard);
|
||||
layer->Set(Config::MAIN_DSP_JIT, m_settings.m_DSPEnableJIT);
|
||||
|
||||
dsp->Set("EnableJIT", m_settings.m_DSPEnableJIT);
|
||||
|
||||
config_layer->Set(Config::SYSCONF_PROGRESSIVE_SCAN, m_settings.m_ProgressiveScan);
|
||||
config_layer->Set(Config::SYSCONF_PAL60, m_settings.m_PAL60);
|
||||
layer->Set(Config::SYSCONF_PROGRESSIVE_SCAN, m_settings.m_ProgressiveScan);
|
||||
layer->Set(Config::SYSCONF_PAL60, m_settings.m_PAL60);
|
||||
}
|
||||
|
||||
void Save(Config::Layer* config_layer) override
|
||||
void Save(Config::Layer* layer) override
|
||||
{
|
||||
// Do Nothing
|
||||
}
|
||||
|
Reference in New Issue
Block a user