added tomlplusplus and start of config parsing

This commit is contained in:
Anonymous275
2022-01-18 01:16:42 +02:00
parent f110ef2bc8
commit 93eb82080c
8 changed files with 49 additions and 6937 deletions

View File

@@ -3,8 +3,40 @@
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
///
#include <tomlplusplus/toml.hpp>
#include <filesystem>
#include "Launcher.h"
#include "Logger.h"
namespace fs = std::filesystem;
void Launcher::loadConfig() {
if(fs::exists("Launcher.cfg")){
std::ifstream cfg("Launcher.cfg");
if(cfg.is_open()) {
auto Size = fs::file_size("Launcher.cfg");
std::string Buffer(Size, 0);
cfg.read(&Buffer[0], std::streamsize(Size));
cfg.close();
toml::table config = toml::parse(cfg);
LOG(INFO) << "Parsing";
if(config["Port"].is_value()) {
/*auto Port = config["Port"].as_integer()->get();
LOG(INFO) << Port;*/
LOG(INFO) << "Got port";
}
}else LOG(FATAL) << "Failed to open Launcher.cfg!";
} else {
std::ofstream cfg("Launcher.cfg");
if(cfg.is_open()){
cfg <<
R"(Port = 4444
Build = "Default"
)";
cfg.close();
}else{
LOG(FATAL) << "Failed to write config on disk!";
}
}
}