satdump/src-core/settings.cpp

60 lines
1.3 KiB
C++
Raw Normal View History

2021-05-05 15:52:12 +02:00
#define SATDUMP_DLL_EXPORT 1
#include "settings.h"
#include "logger.h"
#include <fstream>
2021-06-06 14:11:02 +02:00
#include <filesystem>
#include "satdump_vars.h"
2021-05-05 15:52:12 +02:00
SATDUMP_DLL nlohmann::json settings;
SATDUMP_DLL nlohmann::json global_cfg;
2021-05-05 15:52:12 +02:00
std::string settings_path;
void loadConfig()
{
std::string config_path = "config.json";
2021-08-19 16:44:12 +02:00
if (std::filesystem::exists("config.json"))
config_path = "config.json";
else
config_path = (std::string)RESOURCES_PATH + "config.json";
logger->info("Loading config from file " + config_path);
if (std::filesystem::exists(config_path))
{
std::ifstream istream(config_path);
istream >> global_cfg;
istream.close();
}
else
{
logger->error("No config file found! Using defaults.");
}
}
2021-05-05 15:52:12 +02:00
void loadSettings(std::string path)
{
settings_path = path;
logger->info("Loading settings from file " + path);
2021-06-06 14:11:02 +02:00
if (std::filesystem::exists(path))
{
std::ifstream istream(path);
istream >> settings;
istream.close();
}
else
{
logger->error("No settings file found! Using defaults.");
}
2021-05-05 15:52:12 +02:00
}
void saveSettings()
{
2021-06-06 14:11:02 +02:00
logger->info("Saving settings to file " + settings_path);
2021-05-05 15:52:12 +02:00
std::ofstream ostream(settings_path);
ostream << settings.dump(4);
ostream.close();
}