mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 04:29:13 +12:00
Add config class
This commit is contained in:
parent
90a88eee39
commit
bc3377ac78
6 changed files with 75 additions and 2 deletions
53
src/config.cpp
Normal file
53
src/config.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
#include "config.hpp"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "helpers.hpp"
|
||||
#include "toml.hpp"
|
||||
|
||||
// Largely based on https://github.com/nba-emu/NanoBoyAdvance/blob/master/src/platform/core/src/config.cpp
|
||||
|
||||
void EmulatorConfig::load(const std::filesystem::path& path) {
|
||||
// If the configuration file does not exist, create it and return
|
||||
if (!std::filesystem::exists(path)) {
|
||||
save(path);
|
||||
return;
|
||||
}
|
||||
|
||||
toml::value data;
|
||||
|
||||
try {
|
||||
data = toml::parse(path);
|
||||
} catch (std::exception& ex) {
|
||||
Helpers::warn("Got exception trying to load config file. Exception: %s\n", ex.what());
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.contains("GPU")) {
|
||||
auto gpuResult = toml::expect<toml::value>(data.at("GPU"));
|
||||
if (gpuResult.is_ok()) {
|
||||
auto gpu = gpuResult.unwrap();
|
||||
|
||||
shaderJitEnabled = toml::find_or<toml::boolean>(gpu, "EnableShaderJIT", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EmulatorConfig::save(const std::filesystem::path& path) {
|
||||
toml::basic_value<toml::preserve_comments> data;
|
||||
|
||||
if (std::filesystem::exists(path)) {
|
||||
try {
|
||||
data = toml::parse<toml::preserve_comments>(path);
|
||||
} catch (std::exception& ex) {
|
||||
Helpers::warn("Got exception trying to save config file. Exception: %s\n", ex.what());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
data["GPU"]["EnableShaderJIT"] = shaderJitEnabled;
|
||||
|
||||
std::ofstream file(path, std::ios::out);
|
||||
file << data;
|
||||
file.close();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue