-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.cpp
More file actions
78 lines (64 loc) · 2.65 KB
/
settings.cpp
File metadata and controls
78 lines (64 loc) · 2.65 KB
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
// Copyright (c) 2012-2014 The PHP Desktop authors. All rights reserved.
// License: New BSD License.
// Website: http://code.google.com/p/phpdesktop/
#include "defines.h"
#include "misc/file_utils.h"
#include "misc/logger.h"
#include "settings.h"
nlohmann::json* GetApplicationSettings() {
static nlohmann::json* ret = new nlohmann::json();
static bool fetched = false;
if (fetched) {
return ret;
}
fetched = true;
FLOG_DEBUG << "Fetching settings from settings.json file";
std::string contents;
std::string settingsFile;
settingsFile = GetExecutableDirectory() + "\\config\\settings.json";
contents = GetFileContents(settingsFile);
if (contents.empty()) {
settingsFile = GetExecutableDirectory() + "\\settings.json";
contents = GetFileContents(settingsFile);
if (contents.empty()) {
FLOG_WARNING << "Error while opening the settings.json file";
return ret;
}
}
std::string err;
*ret = nlohmann::json::parse(contents);
if (!err.empty()) {
FLOG_WARNING << "Error while parsing settings.json file: " << err;
}
if ((*ret)["integration"]["engine"].is_null()) {
(*ret)["integration"]["engine"] = "msie";
} else if ((*ret)["integration"]["engine"].is_string()) {
if ("msie" != (*ret)["integration"]["engine"].get<std::string>() && "mb" != (*ret)["integration"]["engine"].get<std::string>()) {
FLOG_WARNING << "Gui engine must be msie or mb, give: " << (*ret)["integration"]["engine"];
(*ret)["integration"]["engine"] = "msie";
}
} else {
FLOG_WARNING << "Gui engine must be msie or mb, give: " << (*ret)["integration"]["engine"];
(*ret)["integration"]["engine"] = "msie";
}
std::string log_file = (*ret)["integration"]["log_file"];
if (log_file.length()) {
if (std::string::npos == log_file.find(":")) {
log_file = GetExecutableDirectory() + "\\" + log_file;
}
(*ret)["integration"]["log_file"] = GetRealPath(log_file);
}
if ((*ret)["integration"]["temp"].empty()) {
(*ret)["integration"]["temp"] = GetRealPath(GetExecutableDirectory());
} else {
std::string temp_path = (*ret)["integration"]["temp"];
if (std::string::npos == temp_path.find(":")) {
temp_path = GetExecutableDirectory() + "\\" + temp_path;
}
(*ret)["integration"]["temp"] = GetRealPath(temp_path);
}
if ((*ret)["window"]["title"].empty()) {
(*ret)["window"]["title"] = GetExecutableName();
}
return ret;
}