2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:09:55 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-02-19 10:05:26 -07:00
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
// Utilities to parse and modify a Wii SYSCONF file and its sections.
|
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2010-02-19 10:05:26 -07:00
|
|
|
|
2014-02-19 20:11:52 -07:00
|
|
|
#include <cstring>
|
2010-02-19 10:05:26 -07:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
#include "Common/Assert.h"
|
2015-09-26 15:13:07 -06:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-01-06 13:59:02 -07:00
|
|
|
#include "Common/NandPaths.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
class SysConf final
|
2010-02-19 10:05:26 -07:00
|
|
|
{
|
|
|
|
public:
|
2017-07-30 13:35:11 -06:00
|
|
|
explicit SysConf(Common::FromWhichRoot root_type);
|
2016-06-24 02:43:46 -06:00
|
|
|
~SysConf();
|
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
void Clear();
|
|
|
|
void Load();
|
|
|
|
bool Save() const;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
struct Entry
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-03-10 10:11:45 -07:00
|
|
|
enum Type : u8
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-03-10 10:11:45 -07:00
|
|
|
BigArray = 1,
|
|
|
|
SmallArray = 2,
|
|
|
|
Byte = 3,
|
|
|
|
Short = 4,
|
|
|
|
Long = 5,
|
|
|
|
LongLong = 6,
|
|
|
|
// Should really be named Bool, but this conflicts with some random macro. :/
|
|
|
|
ByteBool = 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
Entry(Type type_, const std::string& name_);
|
|
|
|
Entry(Type type_, const std::string& name_, const std::vector<u8>& bytes_);
|
|
|
|
Entry(Type type_, const std::string& name_, std::vector<u8>&& bytes_);
|
|
|
|
|
|
|
|
// Intended for use with the non array types.
|
|
|
|
template <typename T>
|
|
|
|
T GetData(T default_value) const
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-03-10 10:11:45 -07:00
|
|
|
if (bytes.size() != sizeof(T))
|
|
|
|
return default_value;
|
|
|
|
T value;
|
|
|
|
std::memcpy(&value, bytes.data(), bytes.size());
|
|
|
|
return value;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2017-03-10 10:11:45 -07:00
|
|
|
template <typename T>
|
|
|
|
void SetData(T value)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2018-03-14 18:34:35 -06:00
|
|
|
ASSERT(sizeof(value) == bytes.size());
|
2017-03-10 10:11:45 -07:00
|
|
|
std::memcpy(bytes.data(), &value, bytes.size());
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
Type type;
|
|
|
|
std::string name;
|
|
|
|
std::vector<u8> bytes;
|
|
|
|
};
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
void AddEntry(Entry&& entry);
|
|
|
|
Entry* GetEntry(const std::string& key);
|
|
|
|
const Entry* GetEntry(const std::string& key) const;
|
|
|
|
Entry* GetOrAddEntry(const std::string& key, Entry::Type type);
|
|
|
|
void RemoveEntry(const std::string& key);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
// Intended for use with the non array types.
|
|
|
|
template <typename T>
|
|
|
|
T GetData(const std::string& key, T default_value) const
|
|
|
|
{
|
|
|
|
const Entry* entry = GetEntry(key);
|
|
|
|
return entry ? entry->GetData(default_value) : default_value;
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
2017-03-10 10:11:45 -07:00
|
|
|
template <typename T>
|
|
|
|
void SetData(const std::string& key, Entry::Type type, T value)
|
2016-06-24 02:43:46 -06:00
|
|
|
{
|
2017-03-10 10:11:45 -07:00
|
|
|
GetOrAddEntry(key, type)->SetData(value);
|
2016-06-24 02:43:46 -06:00
|
|
|
}
|
|
|
|
|
2010-02-19 10:05:26 -07:00
|
|
|
private:
|
2017-03-10 10:11:45 -07:00
|
|
|
void InsertDefaultEntries();
|
|
|
|
bool LoadFromFile(const std::string& file_name);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-03-10 10:11:45 -07:00
|
|
|
std::string m_file_name;
|
|
|
|
std::vector<Entry> m_entries;
|
2010-02-19 10:05:26 -07:00
|
|
|
};
|