-
Notifications
You must be signed in to change notification settings - Fork 114
/
Config.cpp
56 lines (44 loc) · 1.23 KB
/
Config.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
#include "pch.h"
#include "Config.h"
#include "util.h"
// Source: https://stackoverflow.com/a/54394658/3805929
#define GET(j, key) this->key = j[#key].get<decltype(key)>()
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Platform, enabled, process, replicate, ignore, blacklist)
void from_json(const json& j, SteamPlatform& p)
{
from_json(j, (Platform&) p);
j["unlock_shared_library"].get_to(p.unlock_shared_library);
j["unlock_dlc"].get_to(p.unlock_dlc);
j["app_blacklist"].get_to(p.app_blacklist);
}
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Platforms, Steam, EpicGames, Origin, EADesktop, UplayR1)
Config::Config()
{
std::ifstream ifs(getConfigPath(), std::ios::in);
if(!ifs.good())
{
MessageBox(NULL, getConfigPath().c_str(), L"Config not found at: ", MB_ICONERROR);
exit(1);
}
try
{
auto j = json::parse(ifs, nullptr, true, true);
GET(j, log_level);
GET(j, platforms);
GET(j, ignore);
GET(j, terminate);
platformRefs = j["platforms"].get<Platforms>();
} catch(json::exception e)
{
MessageBoxA(NULL, e.what(), "Error parsing config file", MB_ICONERROR);
exit(1);
}
}
void Config::init()
{
if(config != nullptr)
return;
config = new Config();
}
// Every app must call the config constructor first.
Config* config = nullptr;