looper/options.cpp

36 lines
1 KiB
C++
Raw Normal View History

#include "thirdparty/toml.hpp"
#include "util.hpp"
#include <filesystem>
2024-04-25 11:23:38 -07:00
#ifdef __ANDROID__
#include <SDL.h>
#endif
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();
}
}