mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-08 07:51:19 +12:00
Add all the files
This commit is contained in:
parent
e3db07a16a
commit
d60742f52b
1445 changed files with 430238 additions and 0 deletions
65
src/config/PermanentConfig.cpp
Normal file
65
src/config/PermanentConfig.cpp
Normal file
|
@ -0,0 +1,65 @@
|
|||
#include "PermanentConfig.h"
|
||||
|
||||
#include "pugixml.hpp"
|
||||
|
||||
#include "PermanentStorage.h"
|
||||
|
||||
struct xml_string_writer : pugi::xml_writer
|
||||
{
|
||||
std::string result;
|
||||
|
||||
void write(const void* data, size_t size) override
|
||||
{
|
||||
result.append(static_cast<const char*>(data), size);
|
||||
}
|
||||
};
|
||||
|
||||
std::string PermanentConfig::ToXMLString() const noexcept
|
||||
{
|
||||
pugi::xml_document doc;
|
||||
doc.append_child(pugi::node_declaration).append_attribute("encoding") = "UTF-8";
|
||||
auto root = doc.append_child("config");
|
||||
root.append_child("MlcPath").text().set(this->custom_mlc_path.c_str());
|
||||
|
||||
xml_string_writer writer;
|
||||
doc.save(writer);
|
||||
return writer.result;
|
||||
}
|
||||
|
||||
PermanentConfig PermanentConfig::FromXMLString(std::string_view str) noexcept
|
||||
{
|
||||
PermanentConfig result{};
|
||||
|
||||
pugi::xml_document doc;
|
||||
if(doc.load_buffer(str.data(), str.size()))
|
||||
{
|
||||
result.custom_mlc_path = doc.select_node("/config/MlcPath").node().text().as_string();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PermanentConfig PermanentConfig::Load()
|
||||
{
|
||||
PermanentStorage storage;
|
||||
|
||||
const auto str = storage.ReadFile(kFileName);
|
||||
if (!str.empty())
|
||||
return FromXMLString(str);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
bool PermanentConfig::Store() noexcept
|
||||
{
|
||||
try
|
||||
{
|
||||
PermanentStorage storage;
|
||||
storage.WriteStringToFile(kFileName, ToXMLString());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue