[3PP] Replaced cpptoml with tomlplusplus
Also adjusted code that used cpptoml to be used with toml++ and some more changes
This commit is contained in:
@@ -17,23 +17,8 @@
|
||||
#include "xenia/base/string.h"
|
||||
#include "xenia/base/string_buffer.h"
|
||||
|
||||
std::shared_ptr<cpptoml::table> ParseFile(
|
||||
const std::filesystem::path& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
throw cpptoml::parse_exception(xe::path_to_utf8(filename) +
|
||||
" could not be opened for parsing");
|
||||
}
|
||||
// since cpptoml can't parse files with a UTF-8 BOM we need to skip them
|
||||
char bom[3];
|
||||
file.read(bom, sizeof(bom));
|
||||
if (file.fail() || bom[0] != '\xEF' || bom[1] != '\xBB' || bom[2] != '\xBF') {
|
||||
file.clear();
|
||||
file.seekg(0);
|
||||
}
|
||||
|
||||
cpptoml::parser p(file);
|
||||
return p.parse();
|
||||
toml::parse_result ParseFile(const std::filesystem::path& filename) {
|
||||
return toml::parse_file(xe::path_to_utf8(filename));
|
||||
}
|
||||
|
||||
CmdVar(config, "", "Specifies the target config to load.");
|
||||
@@ -57,14 +42,13 @@ bool sortCvar(cvar::IConfigVar* a, cvar::IConfigVar* b) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::shared_ptr<cpptoml::table> ParseConfig(
|
||||
const std::filesystem::path& config_path) {
|
||||
toml::parse_result ParseConfig(const std::filesystem::path& config_path) {
|
||||
try {
|
||||
return ParseFile(config_path);
|
||||
} catch (cpptoml::parse_exception& e) {
|
||||
} catch (toml::parse_error& e) {
|
||||
xe::FatalError(fmt::format("Failed to parse config file '{}':\n\n{}",
|
||||
xe::path_to_utf8(config_path), e.what()));
|
||||
return nullptr;
|
||||
return toml::parse_result();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,9 +91,11 @@ void ReadConfig(const std::filesystem::path& file_path,
|
||||
if (!cvar::ConfigVars) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto config = ParseConfig(file_path);
|
||||
|
||||
PrintConfigToLog(file_path);
|
||||
|
||||
// Loading an actual global config file that exists - if there's no
|
||||
// defaults_date in it, it's very old (before updating was added at all, thus
|
||||
// all defaults need to be updated).
|
||||
@@ -119,9 +105,12 @@ void ReadConfig(const std::filesystem::path& file_path,
|
||||
defaults_date_cvar->SetConfigValue(0);
|
||||
for (auto& it : *cvar::ConfigVars) {
|
||||
auto config_var = static_cast<cvar::IConfigVar*>(it.second);
|
||||
auto config_key = config_var->category() + "." + config_var->name();
|
||||
if (config->contains_qualified(config_key)) {
|
||||
config_var->LoadConfigValue(config->get_qualified(config_key));
|
||||
toml::path config_key =
|
||||
toml::path(config_var->category() + "." + config_var->name());
|
||||
|
||||
const auto config_key_node = config.at_path(config_key);
|
||||
if (config_key_node) {
|
||||
config_var->LoadConfigValue(config_key_node.node());
|
||||
}
|
||||
}
|
||||
uint32_t config_defaults_date = defaults_date_cvar->GetTypedConfigValue();
|
||||
@@ -139,9 +128,12 @@ void ReadGameConfig(const std::filesystem::path& file_path) {
|
||||
const auto config = ParseConfig(file_path);
|
||||
for (auto& it : *cvar::ConfigVars) {
|
||||
auto config_var = static_cast<cvar::IConfigVar*>(it.second);
|
||||
auto config_key = config_var->category() + "." + config_var->name();
|
||||
if (config->contains_qualified(config_key)) {
|
||||
config_var->LoadGameConfigValue(config->get_qualified(config_key));
|
||||
toml::path config_key =
|
||||
toml::path(config_var->category() + "." + config_var->name());
|
||||
|
||||
const auto config_key_node = config.at_path(config_key);
|
||||
if (config_key_node) {
|
||||
config_var->LoadConfigValue(config_key_node.node());
|
||||
}
|
||||
}
|
||||
XELOGI("Loaded game config: {}", xe::path_to_utf8(file_path));
|
||||
|
||||
Reference in New Issue
Block a user