forked from PeterTh/dpfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cpp
116 lines (89 loc) · 2.74 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "Settings.h"
#include <fstream>
#include <string>
#include "main.h"
#include "WindowManager.h"
Settings Settings::instance;
void Settings::load() {
std::ifstream sfile;
sfile.open(GetDirectoryFile(SETTINGS_FILE_NAME), std::ios::in);
char buffer[128];
while(!sfile.eof()) {
sfile.getline(buffer, 128);
if(buffer[0] == '#') continue;
if(sfile.gcount() <= 1) continue;
std::string bstring(buffer);
#define SETTING(_type, _var, _inistring, _defaultval) \
if(bstring.find(_inistring) == 0) { \
read(buffer + strlen(_inistring) + 1, _var); \
}
#include "Settings.def"
#undef SETTING
}
sfile.close();
if(getPresentWidth() == 0) PresentWidth = getRenderWidth();
if(getPresentHeight() == 0) PresentHeight = getRenderHeight();
baseLogLevel = LogLevel;
}
void Settings::report() {
SDLOG(0, "= Settings read:\n");
#define SETTING(_type, _var, _inistring, _defaultval) \
log(_inistring, _var);
#include "Settings.def"
#undef SETTING
SDLOG(0, "=============\n");
}
void Settings::init() {
if(!inited) {
if(getDisableCursor()) WindowManager::get().toggleCursorVisibility();
if(getCaptureCursor()) WindowManager::get().toggleCursorCapture();
if(getForceWindowed()) WindowManager::get().resize(getPresentWidth(), getPresentHeight());
if(getBorderlessFullscreen()) WindowManager::get().toggleBorderlessFullscreen();
inited = true;
}
}
void Settings::shutdown() {
if(inited) {
inited = false;
}
}
void Settings::elevateLogLevel(unsigned level) {
LogLevel = level;
}
void Settings::restoreLogLevel() {
LogLevel = baseLogLevel;
}
// reading --------------------------------------------------------------------
void Settings::read(char* source, bool& value) {
std::string ss(source);
if(ss.find("true")==0 || ss.find("1")==0 || ss.find("TRUE")==0 || ss.find("enable")==0) value = true;
else value = false;
}
void Settings::read(char* source, int& value) {
sscanf_s(source, "%d", &value);
}
void Settings::read(char* source, unsigned& value) {
sscanf_s(source, "%u", &value);
}
void Settings::read(char* source, float& value) {
sscanf_s(source, "%f", &value);
}
void Settings::read(char* source, std::string& value) {
value.assign(source);
}
// logging --------------------------------------------------------------------
void Settings::log(const char* name, bool value) {
SDLOG(0, " - %s : %s\n", name, value ? "true" : "false");
}
void Settings::log(const char* name, int value) {
SDLOG(0, " - %s : %d\n", name, value);
}
void Settings::log(const char* name, unsigned value) {
SDLOG(0, " - %s : %u\n", name, value);
}
void Settings::log(const char* name, float value) {
SDLOG(0, " - %s : %f\n", name, value);
}
void Settings::log(const char* name, const std::string& value) {
SDLOG(0, " - %s : %s\n", name, value.c_str());
}