looper/options.cpp

33 lines
990 B
C++
Raw Normal View History

#include "thirdparty/toml.hpp"
#include "util.hpp"
#include <filesystem>
using namespace std::filesystem;
namespace Looper::Options {
toml::table *options;
toml::table opts_value;
std::string get_options_path() {
path prefs_path(get_prefs_path());
prefs_path /= path("looper");
create_directories(prefs_path);
path config_file = prefs_path / path("config.toml");
return config_file.string();
}
void load_options() {
std::string config_path = get_options_path();
if (exists(config_path)) {
auto res = toml::parse_file(config_path);
opts_value = res;
options = &opts_value;
if (options == nullptr) {
options = new toml::table();
}
} else {
options = new toml::table();
}
}
void save_options() {
std::ofstream output(get_options_path());
output << *options;
output.close();
}
}