dolphin/Source/Core/Common/Config/Layer.h
Léo Lam 940cc843ed Config: Fix Movie config loading/saving
* Add missing Language setting loading/saving. This was added after the
  original OnionConfig PR, which is why support for it was missing.

* Change MovieConfigLoader to reuse ConfigInfos. Less duplication.

* Extract MovieConfigLoader::Save into SaveToDTM. The DTM should use
  the current config and not just the movie layer. This makes more
  sense than just saving the movie layer, which may not always exist,
  and also fixes a crash that would happen when creating a new
  recording because the movie layer wouldn't exist in that case.

  (Plus, having to get the loader from the layer and call ChangeDTM
  on it manually is not very pretty.)
2017-08-11 15:36:32 +08:00

95 lines
2.4 KiB
C++

// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "Common/Config/Enums.h"
#include "Common/Config/Section.h"
namespace Config
{
template <typename T>
struct ConfigInfo;
using LayerMap = std::map<System, std::vector<std::unique_ptr<Section>>>;
class ConfigLayerLoader
{
public:
explicit ConfigLayerLoader(LayerType layer);
virtual ~ConfigLayerLoader();
virtual void Load(Layer* config_layer) = 0;
virtual void Save(Layer* config_layer) = 0;
LayerType GetLayer() const;
private:
const LayerType m_layer;
};
class Layer
{
public:
explicit Layer(LayerType layer);
explicit Layer(std::unique_ptr<ConfigLayerLoader> loader);
virtual ~Layer();
// Convenience functions
bool Exists(System system, const std::string& section_name, const std::string& key);
bool DeleteKey(System system, const std::string& section_name, const std::string& key);
template <typename T>
bool GetIfExists(System system, const std::string& section_name, const std::string& key, T* value)
{
if (Exists(system, section_name, key))
return GetOrCreateSection(system, section_name)->Get(key, value);
return false;
}
virtual Section* GetSection(System system, const std::string& section_name);
virtual Section* GetOrCreateSection(System system, const std::string& section_name);
template <typename T>
T Get(const ConfigInfo<T>& config_info)
{
return GetOrCreateSection(config_info.location.system, config_info.location.section)
->template Get<T>(config_info.location.key, config_info.default_value);
}
template <typename T>
void Set(const ConfigInfo<T>& config_info, const T& value)
{
GetOrCreateSection(config_info.location.system, config_info.location.section)
->Set(config_info.location.key, value);
}
// Explicit load and save of layers
void Load();
void Save();
LayerType GetLayer() const;
const LayerMap& GetLayerMap() const;
protected:
bool IsDirty() const;
void ClearDirty();
LayerMap m_sections;
const LayerType m_layer;
std::unique_ptr<ConfigLayerLoader> m_loader;
};
class RecursiveLayer final : public Layer
{
public:
RecursiveLayer();
Section* GetSection(System system, const std::string& section_name) override;
Section* GetOrCreateSection(System system, const std::string& section_name) override;
};
}