2020-08-16 03:39:05 +02:00
|
|
|
#pragma once
|
|
|
|
#include <json.hpp>
|
|
|
|
#include <thread>
|
2020-09-24 19:36:57 +02:00
|
|
|
#include <string>
|
2020-10-07 22:44:54 +02:00
|
|
|
#include <mutex>
|
2020-08-16 03:39:05 +02:00
|
|
|
|
|
|
|
using nlohmann::json;
|
|
|
|
|
2020-09-24 19:38:05 +02:00
|
|
|
#define DEV_BUILD
|
2020-09-24 19:36:57 +02:00
|
|
|
|
2020-10-24 14:51:55 +02:00
|
|
|
|
|
|
|
#define SDRPP_RESOURCE_DIR "/usr/local/"
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-09-24 19:36:57 +02:00
|
|
|
#ifndef ROOT_DIR
|
|
|
|
#ifdef DEV_BUILD
|
|
|
|
#define ROOT_DIR "../root_dev"
|
|
|
|
#elif _WIN32
|
|
|
|
#define ROOT_DIR "."
|
|
|
|
#else
|
|
|
|
#define ROOT_DIR "/etc/sdrpp"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class ConfigManager {
|
|
|
|
public:
|
|
|
|
ConfigManager();
|
|
|
|
void setPath(std::string file);
|
2020-09-24 19:50:22 +02:00
|
|
|
void load(json def, bool lock = true);
|
2020-09-24 19:36:57 +02:00
|
|
|
void save(bool lock = true);
|
|
|
|
void enableAutoSave();
|
|
|
|
void disableAutoSave();
|
|
|
|
void aquire();
|
|
|
|
void release(bool changed = false);
|
|
|
|
|
2020-10-24 14:51:55 +02:00
|
|
|
// static void setResourceDir(std::string path);
|
|
|
|
// static std::string getResourceDir();
|
|
|
|
|
|
|
|
// static void setConfigDir(std::string path);
|
|
|
|
// static std::string getConfigDir();
|
|
|
|
|
2020-09-24 19:36:57 +02:00
|
|
|
json conf;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void autoSaveWorker(ConfigManager* _this);
|
|
|
|
|
2020-10-24 14:51:55 +02:00
|
|
|
//static std::string resDir;
|
|
|
|
//static std::string configDir;
|
|
|
|
|
2020-09-24 19:36:57 +02:00
|
|
|
std::string path = "";
|
|
|
|
bool changed = false;
|
|
|
|
bool autoSaveEnabled = false;
|
|
|
|
std::thread autoSaveThread;
|
|
|
|
std::mutex mtx;
|
2020-08-16 03:39:05 +02:00
|
|
|
|
|
|
|
};
|