about summary refs log tree commit diff stats
path: root/src/tracker_config.cpp
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-05-05 15:46:58 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-05-05 15:46:58 -0400
commit149e7c0836927e14a926a952bd1a7f0d1b49e779 (patch)
tree2c7ac89387eb890d3d345217b79929e9a23f4ecf /src/tracker_config.cpp
parent0dace7831673170bd31eefa6bbe6e705211d3061 (diff)
downloadlingo-ap-tracker-149e7c0836927e14a926a952bd1a7f0d1b49e779.tar.gz
lingo-ap-tracker-149e7c0836927e14a926a952bd1a7f0d1b49e779.tar.bz2
lingo-ap-tracker-149e7c0836927e14a926a952bd1a7f0d1b49e779.zip
Organised repo
Diffstat (limited to 'src/tracker_config.cpp')
-rw-r--r--src/tracker_config.cpp33
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
6constexpr const char* CONFIG_FILE_NAME = "config.yaml";
7
8void 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
20void 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
30TrackerConfig& GetTrackerConfig() {
31 static TrackerConfig* instance = new TrackerConfig();
32 return *instance;
33}