From 1eb11b55a0dfd3d28b2db29d0c341d2fa0bbda15 Mon Sep 17 00:00:00 2001 From: Ryan Houdek Date: Wed, 27 Jan 2016 18:08:58 -0600 Subject: [PATCH] Base configuration loader --- .../Core/ConfigLoaders/BaseConfigLoader.cpp | 95 +++++++++++++++++++ .../Core/ConfigLoaders/BaseConfigLoader.h | 17 ++++ 2 files changed, 112 insertions(+) create mode 100644 Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp create mode 100644 Source/Core/Core/ConfigLoaders/BaseConfigLoader.h diff --git a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp new file mode 100644 index 0000000000..c073cfcf2e --- /dev/null +++ b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.cpp @@ -0,0 +1,95 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include +#include +#include +#include + +#include "Common/CommonPaths.h" +#include "Common/CommonTypes.h" +#include "Common/Config/Config.h" +#include "Common/FileUtil.h" +#include "Common/IniFile.h" +#include "Common/Logging/Log.h" + +#include "Core/ConfigLoaders/BaseConfigLoader.h" + +namespace ConfigLoaders +{ +const std::map system_to_ini = { + {Config::System::Main, F_DOLPHINCONFIG_IDX}, + {Config::System::GCPad, F_GCPADCONFIG_IDX}, + {Config::System::WiiPad, F_WIIPADCONFIG_IDX}, + {Config::System::GCKeyboard, F_GCKEYBOARDCONFIG_IDX}, + {Config::System::GFX, F_GFXCONFIG_IDX}, + {Config::System::Logger, F_LOGGERCONFIG_IDX}, + {Config::System::Debugger, F_DEBUGGERCONFIG_IDX}, + {Config::System::UI, F_UICONFIG_IDX}, +}; + +// INI layer configuration loader +class INIBaseConfigLayerLoader final : public Config::ConfigLayerLoader +{ +public: + INIBaseConfigLayerLoader() : ConfigLayerLoader(Config::LayerType::Base) {} + void Load(Config::Layer* config_layer) override + { + for (const auto& system : system_to_ini) + { + IniFile ini; + ini.Load(File::GetUserPath(system.second)); + const std::list& system_sections = ini.GetSections(); + + 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); + } + } + } + + void Save(Config::Layer* config_layer) override + { + const Config::LayerMap& sections = config_layer->GetLayerMap(); + for (const auto& system : sections) + { + auto mapping = system_to_ini.find(system.first); + if (mapping == system_to_ini.end()) + { + ERROR_LOG(COMMON, "Config can't map system '%s' to an INI file!", + Config::GetSystemName(system.first).c_str()); + continue; + } + + IniFile ini; + ini.Load(File::GetUserPath(mapping->second)); + + for (const auto& section : system.second) + { + 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) + ini_section->Set(value.first, value.second); + } + + ini.Save(File::GetUserPath(mapping->second)); + } + } +}; + +// Loader generation +std::unique_ptr GenerateBaseConfigLoader() +{ + return std::make_unique(); +} +} diff --git a/Source/Core/Core/ConfigLoaders/BaseConfigLoader.h b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.h new file mode 100644 index 0000000000..4356c5ad47 --- /dev/null +++ b/Source/Core/Core/ConfigLoaders/BaseConfigLoader.h @@ -0,0 +1,17 @@ +// Copyright 2016 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +namespace Config +{ +class ConfigLayerLoader; +} + +namespace ConfigLoaders +{ +std::unique_ptr GenerateBaseConfigLoader(); +}