diff options
Diffstat (limited to 'src/tracker_config.cpp')
-rw-r--r-- | src/tracker_config.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/tracker_config.cpp b/src/tracker_config.cpp new file mode 100644 index 0000000..96bb60a --- /dev/null +++ b/src/tracker_config.cpp | |||
@@ -0,0 +1,33 @@ | |||
1 | #include "tracker_config.h" | ||
2 | |||
3 | #include <fstream> | ||
4 | #include <yaml-cpp/yaml.h> | ||
5 | |||
6 | constexpr const char* CONFIG_FILE_NAME = "config.yaml"; | ||
7 | |||
8 | void TrackerConfig::Load() { | ||
9 | try { | ||
10 | YAML::Node file = YAML::LoadFile(CONFIG_FILE_NAME); | ||
11 | |||
12 | ap_server = file["ap_server"].as<std::string>(); | ||
13 | ap_player = file["ap_player"].as<std::string>(); | ||
14 | ap_password = file["ap_password"].as<std::string>(); | ||
15 | } catch (const std::exception&) { | ||
16 | // It's fine if the file can't be loaded. | ||
17 | } | ||
18 | } | ||
19 | |||
20 | void TrackerConfig::Save() { | ||
21 | YAML::Node output; | ||
22 | output["ap_server"] = ap_server; | ||
23 | output["ap_player"] = ap_player; | ||
24 | output["ap_password"] = ap_password; | ||
25 | |||
26 | std::ofstream filewriter(CONFIG_FILE_NAME); | ||
27 | filewriter << output; | ||
28 | } | ||
29 | |||
30 | TrackerConfig& GetTrackerConfig() { | ||
31 | static TrackerConfig* instance = new TrackerConfig(); | ||
32 | return *instance; | ||
33 | } | ||