2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-02-19 17:05:26 +00:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
// Utilities to parse and modify a Wii SYSCONF file and its sections.
|
|
|
|
|
2014-02-10 13:54:46 -05:00
|
|
|
#pragma once
|
2010-02-19 17:05:26 +00:00
|
|
|
|
2014-02-20 04:11:52 +01:00
|
|
|
#include <cstring>
|
2018-03-11 12:05:12 +01:00
|
|
|
#include <memory>
|
2010-02-19 17:05:26 +00:00
|
|
|
#include <string>
|
2020-12-29 18:19:08 -05:00
|
|
|
#include <string_view>
|
2010-02-19 17:05:26 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
#include "Common/Assert.h"
|
2015-09-26 17:13:07 -04:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-01-06 21:59:02 +01:00
|
|
|
#include "Common/NandPaths.h"
|
2020-01-14 17:08:21 -06:00
|
|
|
#include "Common/Swap.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
|
2018-03-11 12:05:12 +01:00
|
|
|
namespace IOS::HLE::FS
|
|
|
|
{
|
|
|
|
class FileHandle;
|
|
|
|
class FileSystem;
|
2019-05-05 23:48:12 +00:00
|
|
|
} // namespace IOS::HLE::FS
|
2018-03-11 12:05:12 +01:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
class SysConf final
|
2010-02-19 17:05:26 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-03-11 12:05:12 +01:00
|
|
|
explicit SysConf(std::shared_ptr<IOS::HLE::FS::FileSystem> fs);
|
2010-02-19 17:05:26 +00:00
|
|
|
~SysConf();
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
void Clear();
|
|
|
|
void Load();
|
|
|
|
bool Save() const;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
struct Entry
|
2010-12-22 08:00:08 +00:00
|
|
|
{
|
2017-03-10 18:11:45 +01:00
|
|
|
enum Type : u8
|
2010-12-22 08:00:08 +00:00
|
|
|
{
|
2017-03-10 18:11:45 +01: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,
|
|
|
|
};
|
|
|
|
|
2020-12-29 19:09:54 -05:00
|
|
|
Entry(Type type_, std::string name_);
|
|
|
|
Entry(Type type_, std::string name_, std::vector<u8> bytes_);
|
2017-03-10 18:11:45 +01:00
|
|
|
|
|
|
|
// Intended for use with the non array types.
|
|
|
|
template <typename T>
|
|
|
|
T GetData(T default_value) const
|
2010-12-22 08:00:08 +00:00
|
|
|
{
|
2017-03-10 18:11:45 +01:00
|
|
|
if (bytes.size() != sizeof(T))
|
|
|
|
return default_value;
|
2020-01-14 17:08:21 -06:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
T value;
|
|
|
|
std::memcpy(&value, bytes.data(), bytes.size());
|
2020-01-14 17:08:21 -06:00
|
|
|
return Common::FromBigEndian(value);
|
2010-12-22 08:00:08 +00:00
|
|
|
}
|
2017-03-10 18:11:45 +01:00
|
|
|
template <typename T>
|
|
|
|
void SetData(T value)
|
2010-12-22 08:00:08 +00:00
|
|
|
{
|
2018-03-14 20:34:35 -04:00
|
|
|
ASSERT(sizeof(value) == bytes.size());
|
2020-01-14 17:08:21 -06:00
|
|
|
|
|
|
|
value = Common::FromBigEndian(value);
|
2017-03-10 18:11:45 +01:00
|
|
|
std::memcpy(bytes.data(), &value, bytes.size());
|
2010-12-22 08:00:08 +00:00
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
Type type;
|
|
|
|
std::string name;
|
|
|
|
std::vector<u8> bytes;
|
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2020-12-29 18:24:21 -05:00
|
|
|
Entry& AddEntry(Entry&& entry);
|
2020-12-29 18:19:08 -05:00
|
|
|
Entry* GetEntry(std::string_view key);
|
|
|
|
const Entry* GetEntry(std::string_view key) const;
|
|
|
|
Entry* GetOrAddEntry(std::string_view key, Entry::Type type);
|
|
|
|
void RemoveEntry(std::string_view key);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
// Intended for use with the non array types.
|
|
|
|
template <typename T>
|
2020-12-29 18:19:08 -05:00
|
|
|
T GetData(std::string_view key, T default_value) const
|
2017-03-10 18:11:45 +01:00
|
|
|
{
|
|
|
|
const Entry* entry = GetEntry(key);
|
|
|
|
return entry ? entry->GetData(default_value) : default_value;
|
2010-12-22 08:00:08 +00:00
|
|
|
}
|
2017-03-10 18:11:45 +01:00
|
|
|
template <typename T>
|
2020-12-29 18:19:08 -05:00
|
|
|
void SetData(std::string_view key, Entry::Type type, T value)
|
2010-02-19 17:05:26 +00:00
|
|
|
{
|
2017-03-10 18:11:45 +01:00
|
|
|
GetOrAddEntry(key, type)->SetData(value);
|
2010-02-19 17:05:26 +00:00
|
|
|
}
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2010-02-19 17:05:26 +00:00
|
|
|
private:
|
2017-03-10 18:11:45 +01:00
|
|
|
void InsertDefaultEntries();
|
2018-03-11 12:05:12 +01:00
|
|
|
bool LoadFromFile(const IOS::HLE::FS::FileHandle& file);
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2017-03-10 18:11:45 +01:00
|
|
|
std::vector<Entry> m_entries;
|
2018-03-11 12:05:12 +01:00
|
|
|
std::shared_ptr<IOS::HLE::FS::FileSystem> m_fs;
|
2010-02-19 17:05:26 +00:00
|
|
|
};
|