-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
94 lines (89 loc) · 3.26 KB
/
main.cpp
File metadata and controls
94 lines (89 loc) · 3.26 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
#define D_SCL_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#pragma warning(disable : 4996)
#include "FastWorldGenerator.h"
#include "UI/FwgUI.h"
#include "utils/Logging.h"
#include "utils/Utils.h"
#include <filesystem>
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(Fwg::Cfg::Values().mapSeed);
dump += "\n";
for (auto layerSeed : Fwg::Cfg::Values().seeds) {
dump += std::to_string(layerSeed);
dump += "\n";
}
dump += error;
dump += Fwg::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()) {
Fwg::Utils::Logging::logLine("Config could not be loaded");
}
buffer << f.rdbuf();
Fwg::Parsing::replaceInStringStream(buffer, "\\", "//");
pt::read_json(buffer, metaConf);
} catch (std::exception &e) {
Fwg::Utils::Logging::logLine("Incorrect config \"MetaConf.json\"");
Fwg::Utils::Logging::logLine("You can try fixing it yourself. Error is: ",
e.what());
Fwg::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 (!Fwg::Utils::Paths::validateAndSanitizeWorkingDirectory(
workingDirectory)) {
return -1;
}
std::string configSubFolder =
workingDirectory + metaConf.get<std::string>("config.configSubFolder");
auto &config = Fwg::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) {
Fwg::Utils::Logging::logLine(
"Incorrect config \"FastWorldGenerator.json\"");
Fwg::Utils::Logging::logLine("You can try fixing it yourself. Error is: ",
e.what());
Fwg::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;
}
Fwg::Utils::Logging::logLine("Initialising Fwg");
Fwg::FastWorldGenerator fwg;
Fwg::Utils::Logging::logLine("Initialising Fwg UI");
Fwg::FwgUI ui;
Fwg::Utils::Logging::logLine("Calling Fwg UI.shiny");
ui.shiny(fwg);
}