diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-05-03 15:13:14 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-05-03 15:13:14 -0400 |
commit | f2a4553fa9d64cc39d138531d0a8d662af733ef8 (patch) | |
tree | b2c7a0fe753fe2ea132b0582e8f1b7521303f3e1 /tracker_config.cpp | |
parent | dc4a14397ae226d91041389c2a47993f9c22f83d (diff) | |
download | lingo-ap-tracker-f2a4553fa9d64cc39d138531d0a8d662af733ef8.tar.gz lingo-ap-tracker-f2a4553fa9d64cc39d138531d0a8d662af733ef8.tar.bz2 lingo-ap-tracker-f2a4553fa9d64cc39d138531d0a8d662af733ef8.zip |
Connection details are saved locally
Diffstat (limited to 'tracker_config.cpp')
-rw-r--r-- | tracker_config.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tracker_config.cpp b/tracker_config.cpp new file mode 100644 index 0000000..96bb60a --- /dev/null +++ b/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 | } | ||