satdump/src-core/settings.cpp

35 lines
714 B
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>
2021-05-05 15:52:12 +02:00
SATDUMP_DLL nlohmann::json settings;
std::string settings_path;
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();
}