forked from Hal47/dsfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.cpp
68 lines (59 loc) · 1.99 KB
/
Settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "Settings.h"
#include "WindowManager.h"
#include "util.h"
#include <filesystem>
#include <fstream>
#include <spdlog/spdlog.h>
#include <sstream>
#include <string>
#include <Windows.h>
namespace fs = std::filesystem;
Settings Settings::instance;
void Settings::load() {
fs::path iniFilename = GetModuleDirectoryPath() / L"DSfix.ini";
std::ifstream settings(iniFilename);
std::string line;
while (std::getline(settings, line)) {
if (line.empty() || line[0] == '#')
continue;
std::istringstream iss(line);
std::string propertyName;
iss >> propertyName;
#define SETTING(_type, _var, _propertyName, _defaultval) \
if (propertyName == _propertyName) { \
iss >> _var; \
continue; \
}
#include "Settings.inc"
#undef SETTING
}
}
void Settings::save() {
fs::path iniFilename = GetModuleDirectoryPath() / L"DSfix.ini";
std::ofstream settings(iniFilename);
#define SETTING(_type, _var, _propertyName, _defaultval) \
settings << _propertyName << " " << _var << "\n";
#include "Settings.inc"
#undef SETTING
}
void Settings::report() {
spdlog::info("= Settings read:");
#define SETTING(_type, _var, _propertyName, _defaultval) \
spdlog::info(" - {} : {}", _propertyName, _var);
#include "Settings.inc"
#undef SETTING
spdlog::info("_____________");
}
void Settings::init() {
if (!initialized) {
WindowManager::get().toggleCursorVisibility();
WindowManager::get().toggleCursorCapture();
WindowManager::get().toggleBorderlessFullscreen();
initialized = true;
}
}
void Settings::shutdown() {
if (initialized) {
initialized = false;
}
}