2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-02-19 17:05:26 +00:00
|
|
|
|
2017-03-10 17:11:45 +00:00
|
|
|
// Utilities to parse and modify a Wii SYSCONF file and its sections.
|
|
|
|
|
2014-02-10 18:54:46 +00:00
|
|
|
#pragma once
|
2010-02-19 17:05:26 +00:00
|
|
|
|
2014-02-20 03:11:52 +00:00
|
|
|
#include <cstring>
|
2010-02-19 17:05:26 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2017-03-10 17:11:45 +00:00
|
|
|
#include "Common/Assert.h"
|
2015-09-26 21:13:07 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-01-06 20:59:02 +00:00
|
|
|
#include "Common/NandPaths.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
2017-03-10 17:11:45 +00:00
|
|
|
class SysConf final
|
2010-02-19 17:05:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-07-30 19:35:11 +00:00
|
|
|
explicit SysConf(Common::FromWhichRoot root_type);
|
2016-06-24 08:43:46 +00:00
|
|
|
~SysConf();
|
|
|
|
|
2017-03-10 17:11:45 +00:00
|
|
|
void Clear();
|
|
|
|
void Load();
|
|
|
|
bool Save() const;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-10 17:11:45 +00:00
|
|
|
struct Entry
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-03-10 17:11:45 +00:00
|
|
|
enum Type : u8
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-03-10 17:11:45 +00: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 08:43:46 +00:00
|
|
|
{
|
2017-03-10 17:11:45 +00:00
|
|
|
if (bytes.size() != sizeof(T))
|
|
|
|
return default_value;
|
|
|
|
T value;
|
|
|
|
std::memcpy(&value, bytes.data(), bytes.size());
|
|
|
|
return value;
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
2017-03-10 17:11:45 +00:00
|
|
|
template <typename T>
|
|
|
|
void SetData(T value)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-03-10 17:11:45 +00:00
|
|
|
_assert_(sizeof(value) == bytes.size());
|
|
|
|
std::memcpy(bytes.data(), &value, bytes.size());
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-10 17:11:45 +00:00
|
|
|
Type type;
|
|
|
|
std::string name;
|
|
|
|
std::vector<u8> bytes;
|
|
|
|
};
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-10 17:11:45 +00: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 08:43:46 +00:00
|
|
|
|
2017-03-10 17:11:45 +00: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 08:43:46 +00:00
|
|
|
}
|
2017-03-10 17:11:45 +00:00
|
|
|
template <typename T>
|
|
|
|
void SetData(const std::string& key, Entry::Type type, T value)
|
2016-06-24 08:43:46 +00:00
|
|
|
{
|
2017-03-10 17:11:45 +00:00
|
|
|
GetOrAddEntry(key, type)->SetData(value);
|
2016-06-24 08:43:46 +00:00
|
|
|
}
|
|
|
|
|
2010-02-19 17:05:26 +00:00
|
|
|
private:
|
2017-03-10 17:11:45 +00:00
|
|
|
void InsertDefaultEntries();
|
|
|
|
bool LoadFromFile(const std::string& file_name);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2017-03-10 17:11:45 +00:00
|
|
|
std::string m_file_name;
|
|
|
|
std::vector<Entry> m_entries;
|
2010-02-19 17:05:26 +00:00
|
|
|
};
|