-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (117 loc) · 4.38 KB
/
main.cpp
File metadata and controls
123 lines (117 loc) · 4.38 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
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
117
118
119
120
121
122
123
#include "FastWorldGenerator.h"
#include "UI/GUI.h"
#include <filesystem>
using namespace Fwg;
void dumpInfo(const std::string &error, const std::string &configSubFolder) {
std::string dump = "";
std::string path = configSubFolder;
if (path.length() > 0) {
for (const auto &entry : std::filesystem::directory_iterator(path)) {
if (entry.is_directory()) {
continue; // Skip directories
}
dump += Fwg::Parsing::readFile(entry.path().string());
}
}
dump += std::to_string(Cfg::Values().mapSeed);
dump += "\n";
for (auto layerSeed : Cfg::Values().seeds) {
dump += std::to_string(layerSeed);
dump += "\n";
}
dump += error;
dump += Utils::Logging::Logger::logInstance.getFullLog();
Fwg::Parsing::writeFile("log.txt", dump);
}
int main() {
Fwg::Utils::Logging::logLine("Starting the config loading");
// Short alias for this namespace
namespace pt = boost::property_tree;
// Create a root
pt::ptree metaConf;
try {
Fwg::Utils::Logging::logLine("Starting the loading of MetaConf.json");
std::ifstream f("MetaConf.json");
std::stringstream buffer;
if (!f.good()) {
Utils::Logging::logLine("Config could not be loaded");
}
buffer << f.rdbuf();
Parsing::replaceInStringStream(buffer, "\\", "//");
pt::read_json(buffer, metaConf);
} catch (std::exception &e) {
Utils::Logging::logLine("Incorrect config \"MetaConf.json\"");
Utils::Logging::logLine("You can try fixing it yourself. Error is: ",
e.what());
Utils::Logging::logLine(
"Otherwise try running it through a json validator, e.g. "
"\"https://jsonlint.com/\" or search for \"json validator\"");
dumpInfo(e.what(), "");
return -1;
}
std::string username = metaConf.get<std::string>("config.username");
std::string workingDirectory =
metaConf.get<std::string>("config.workingDirectory");
if (!Utils::Paths::validateAndSanitizeWorkingDirectory(workingDirectory)) {
return -1;
}
std::string configSubFolder =
workingDirectory + metaConf.get<std::string>("config.configSubFolder");
// Create a ptree
pt::ptree rpdConf;
try {
Fwg::Utils::Logging::logLine("Starting the loading of ", workingDirectory,
"configs//RandomParadox.json");
// Read the basic settings
std::ifstream f(workingDirectory + "configs//RandomParadox.json");
std::stringstream buffer;
if (!f.good())
Utils::Logging::logLine("Config could not be loaded");
buffer << f.rdbuf();
Parsing::replaceInStringStream(buffer, "\\", "//");
pt::read_json(buffer, rpdConf);
} catch (std::exception &e) {
Utils::Logging::logLine("Incorrect config \"RandomParadox.json\"");
Utils::Logging::logLine("You can try fixing it yourself. Error is: ",
e.what());
Utils::Logging::logLine(
"Otherwise try running it through a json validator, e.g. "
"\"https://jsonlint.com/\" or search for \"json validator\"");
dumpInfo(e.what(), configSubFolder);
return -1;
}
std::string mapName;
auto &config = Cfg::Values();
config.workingDirectory = workingDirectory;
// check if we can read the config
try {
Fwg::Utils::Logging::logLine("Starting the loading of ",
configSubFolder + "FastWorldGenerator.json");
config.readConfig(configSubFolder);
} catch (std::exception &e) {
Utils::Logging::logLine("Incorrect config \"FastWorldGenerator.json\"");
Utils::Logging::logLine("You can try fixing it yourself. Error is: ",
e.what());
Utils::Logging::logLine(
"Otherwise try running it through a json validator, e.g. "
"\"https://jsonlint.com/\" or \"search for json validator\"");
dumpInfo(e.what(), configSubFolder);
return -1;
}
try {
Fwg::Utils::Logging::logLine("Creating the exports folder");
// make sure we always have the default exports directory
std::filesystem::create_directory(workingDirectory + "exports//");
GUI gui2;
Fwg::Utils::Logging::logLine("Starting the GUI");
gui2.shiny(rpdConf, configSubFolder, username);
Fwg::Utils::Logging::logLine("Exited the GUI");
dumpInfo("", configSubFolder);
} catch (std::exception &e) {
Utils::Logging::logLine(e.what());
dumpInfo(e.what(), configSubFolder);
return -1;
}
Utils::Logging::logLine("Done with the generation");
return 0;
}