Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
[submodule "third_party/capstone"]
path = third_party/capstone
url = https://github.com/xenia-project/capstone.git
[submodule "third_party/cpptoml"]
path = third_party/cpptoml
url = https://github.com/skystrife/cpptoml.git
[submodule "third_party/tomlplusplus"]
path = third_party/tomlplusplus
url = https://github.com/marzer/tomlplusplus.git
[submodule "third_party/cxxopts"]
path = third_party/cxxopts
url = https://github.com/jarro2783/cxxopts.git
Expand Down
2 changes: 1 addition & 1 deletion premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ workspace("xenia")
include("third_party/dxbc.lua")
include("third_party/discord-rpc.lua")
include("third_party/cxxopts.lua")
include("third_party/cpptoml.lua")
include("third_party/tomlplusplus.lua")
include("third_party/FFmpeg/premake5.lua")
include("third_party/fmt.lua")
include("third_party/glslang-spirv.lua")
Expand Down
9 changes: 5 additions & 4 deletions src/xenia/base/cvar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void ParseLaunchArguments(int& argc, char**& argv,
}
}

namespace toml {
namespace toml_internal {

std::string EscapeBasicString(const std::string_view view) {
std::string result;
Expand Down Expand Up @@ -202,19 +202,20 @@ std::string EscapeString(const std::string_view view) {
if (xe::utf8::find_any_of(view, escape_chars) == std::string_view::npos) {
return "'" + std::string(view) + "'";
} else {
return "\"" + toml::EscapeBasicString(view) + "\"";
return "\"" + toml_internal::EscapeBasicString(view) + "\"";
}
} else {
// multi line
if (xe::utf8::find_any_of(view, escape_chars) == std::string_view::npos &&
xe::utf8::find_first_of(view, u8"'''") == std::string_view::npos) {
return "'''\n" + std::string(view) + "'''";
} else {
return u8"\"\"\"\n" + toml::EscapeMultilineBasicString(view) + u8"\"\"\"";
return u8"\"\"\"\n" + toml_internal::EscapeMultilineBasicString(view) +
u8"\"\"\"";
}
}
}

} // namespace toml
} // namespace toml_internal

} // namespace cvar
32 changes: 16 additions & 16 deletions src/xenia/base/cvar.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include <string>
#include <vector>

#include "third_party/cpptoml/include/cpptoml.h"
#include "third_party/cxxopts/include/cxxopts.hpp"
#include "third_party/fmt/include/fmt/format.h"
#include "third_party/tomlplusplus/include/toml++/toml.hpp"
#include "xenia/base/assert.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/platform.h"
Expand All @@ -29,7 +29,7 @@

namespace cvar {

namespace toml {
namespace toml_internal {
std::string EscapeString(const std::string_view str);
}

Expand All @@ -48,8 +48,8 @@ class IConfigVar : virtual public ICommandVar {
virtual const std::string& category() const = 0;
virtual bool is_transient() const = 0;
virtual std::string config_value() const = 0;
virtual void LoadConfigValue(std::shared_ptr<cpptoml::base> result) = 0;
virtual void LoadGameConfigValue(std::shared_ptr<cpptoml::base> result) = 0;
virtual void LoadConfigValue(const toml::node* result) = 0;
virtual void LoadGameConfigValue(const toml::node* result) = 0;
virtual void ResetConfigValueToDefault() = 0;
};

Expand Down Expand Up @@ -87,8 +87,8 @@ class ConfigVar : public CommandVar<T>, virtual public IConfigVar {
const std::string& category() const override;
bool is_transient() const override;
void AddToLaunchOptions(cxxopts::Options* options) override;
void LoadConfigValue(std::shared_ptr<cpptoml::base> result) override;
void LoadGameConfigValue(std::shared_ptr<cpptoml::base> result) override;
void LoadConfigValue(const toml::node* result) override;
void LoadGameConfigValue(const toml::node* result) override;
void SetConfigValue(T val);
void SetGameConfigValue(T val);
// Changes the actual value used to the one specified, and also makes it the
Expand Down Expand Up @@ -146,24 +146,24 @@ inline void CommandVar<std::filesystem::path>::LoadFromLaunchOptions(
SetCommandLineValue(value);
}
template <class T>
void ConfigVar<T>::LoadConfigValue(std::shared_ptr<cpptoml::base> result) {
SetConfigValue(*cpptoml::get_impl<T>(result));
void ConfigVar<T>::LoadConfigValue(const toml::node* result) {
SetConfigValue(result->value<T>().value());
}
template <>
inline void ConfigVar<std::filesystem::path>::LoadConfigValue(
std::shared_ptr<cpptoml::base> result) {
const toml::node* result) {
SetConfigValue(
xe::utf8::fix_path_separators(*cpptoml::get_impl<std::string>(result)));
xe::utf8::fix_path_separators(result->as_string()->value_or("")));
}
template <class T>
void ConfigVar<T>::LoadGameConfigValue(std::shared_ptr<cpptoml::base> result) {
SetGameConfigValue(*cpptoml::get_impl<T>(result));
void ConfigVar<T>::LoadGameConfigValue(const toml::node* result) {
SetGameConfigValue(result->value<T>().value());
}
template <>
inline void ConfigVar<std::filesystem::path>::LoadGameConfigValue(
std::shared_ptr<cpptoml::base> result) {
const toml::node* result) {
SetGameConfigValue(
xe::utf8::fix_path_separators(*cpptoml::get_impl<std::string>(result)));
xe::utf8::fix_path_separators(result->as_string()->value_or("")));
}
template <class T>
CommandVar<T>::CommandVar(const char* name, T* default_value,
Expand Down Expand Up @@ -215,12 +215,12 @@ inline std::string CommandVar<bool>::ToString(bool val) {
}
template <>
inline std::string CommandVar<std::string>::ToString(std::string val) {
return toml::EscapeString(val);
return toml_internal::EscapeString(val);
}
template <>
inline std::string CommandVar<std::filesystem::path>::ToString(
std::filesystem::path val) {
return toml::EscapeString(
return toml_internal::EscapeString(
xe::utf8::fix_path_separators(xe::path_to_utf8(val), '/'));
}

Expand Down
48 changes: 19 additions & 29 deletions src/xenia/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,17 @@

#include "config.h"

#include "third_party/cpptoml/include/cpptoml.h"
#include "third_party/fmt/include/fmt/format.h"
#include "third_party/tomlplusplus/include/toml++/toml.hpp"
#include "xenia/base/assert.h"
#include "xenia/base/cvar.h"
#include "xenia/base/filesystem.h"
#include "xenia/base/logging.h"
#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.");
Expand All @@ -51,14 +36,13 @@ std::filesystem::path config_folder;
std::filesystem::path config_path;
std::string game_config_suffix = ".config.toml";

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();
}
}

Expand All @@ -67,7 +51,7 @@ void ReadConfig(const std::filesystem::path& file_path,
if (!cvar::ConfigVars) {
return;
}
const auto config = ParseConfig(file_path);
const toml::table config = ParseConfig(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).
Expand All @@ -77,9 +61,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();
Expand All @@ -96,9 +83,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));
Expand Down
1 change: 0 additions & 1 deletion third_party/cpptoml
Submodule cpptoml deleted from fededa
1 change: 1 addition & 0 deletions third_party/tomlplusplus
Submodule tomlplusplus added at 301724
4 changes: 2 additions & 2 deletions third_party/cpptoml.lua → third_party/tomlplusplus.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group("third_party")
project("cpptoml")
project("tomlplusplus")
uuid("1e86cc51-3f8b-476d-9249-3b200424846b")
if os.istarget("android") then
-- ndk-build only supports StaticLib and SharedLib.
Expand All @@ -9,5 +9,5 @@ project("cpptoml")
end
language("C++")
files({
"cpptoml/include/cpptoml.h",
"tomlplusplus/include/toml++/toml.hpp"
})