Files
kaizen/src/utils/Options.hpp
T
2026-04-13 23:58:36 +02:00

48 lines
1.1 KiB
C++

#pragma once
#include <filesystem>
#include <common.hpp>
#include <mini/ini.h>
#include <log.hpp>
namespace fs = std::filesystem;
struct Options {
Options() : file{"resources/options.ini"} {
auto fileExists = fs::exists("resources/options.ini");
if (fileExists) {
file.read(structure);
return;
}
structure["general"]["savePath"] = "saves";
fs::create_directory("saves");
structure["audio"]["volumeL"] = "0.5";
structure["audio"]["volumeR"] = "0.5";
structure["audio"]["lock"] = "true";
structure["cpu"]["type"] = "interpreter";
if (!file.generate(structure))
panic("Couldn't generate settings' INI!");
}
static Options &GetInstance() {
static Options instance;
return instance;
}
template <typename T>
void SetValue(const std::string &key, const std::string &field, const T &value);
template <typename T>
T GetValue(const std::string &key, const std::string &field);
void Apply() {
if (!file.write(structure))
panic("Could not modify options on disk!");
}
private:
mINI::INIFile file;
mINI::INIStructure structure;
};