Improved koalageddon config init

This commit is contained in:
acidicoala
2023-01-11 10:58:11 +03:00
parent edd785cfcf
commit 3e40e4607f
12 changed files with 106 additions and 67 deletions

View File

@@ -7,7 +7,6 @@
namespace smoke_api::config {
Config instance; // NOLINT(cert-err58-cpp)
// TODO: Reloading via export
void init() {
const auto path = paths::get_config_path();
@@ -15,10 +14,9 @@ namespace smoke_api::config {
try {
const auto config_str = koalabox::io::read_file(path);
LOG_DEBUG("Parsing config:\n{}", config_str)
instance = Json::parse(config_str).get<Config>();
LOG_DEBUG("Parsed config:\n{}", Json(instance))
} catch (const Exception& e) {
const auto message = fmt::format("Error parsing config file: {}", e.what());
koalabox::util::error_box("SmokeAPI Error", message);

View File

@@ -32,7 +32,7 @@ namespace smoke_api::config {
// We have to use general json type here since the library doesn't support std::optional
Json koalageddon_config;
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(
NLOHMANN_DEFINE_TYPE_INTRUSIVE(
Config, // NOLINT(misc-const-correctness)
$version,
logging,

View File

@@ -54,23 +54,24 @@ void init_hook_mode() {
// the support for it has been dropped from this project.
}
bool is_valve_steam(const String& exe_name) {
if (exe_name < not_equals > "steam.exe") {
bool is_valve_steam(const String& exe_name) noexcept {
try {
if (exe_name < not_equals > "steam.exe") {
return false;
}
// Verify that it's steam from valve, and not some other executable coincidentally named steam
const HMODULE steam_handle = koalabox::win_util::get_module_handle_or_throw(nullptr);
const auto manifest = koalabox::win_util::get_module_manifest(steam_handle);
// Steam.exe manifest is expected to contain this string
return manifest < contains > "valvesoftware.steam.steam";
} catch (const Exception& e) {
LOG_ERROR("{} -> {}", __func__, e.what())
return false;
}
const HMODULE steam_handle = koalabox::win_util::get_module_handle_or_throw(nullptr);
const auto manifest = koalabox::win_util::get_module_manifest(steam_handle);
// Verify that it's steam from valve, and not some other executable coincidentally named steam
if (!manifest) {
// Steam.exe is expected to have a manifest
return false;
}
// Steam.exe manifest is expected to contain this string
return *manifest < contains > "valvesoftware.steam.steam";
}
namespace smoke_api {
@@ -87,7 +88,8 @@ namespace smoke_api {
koalabox::logger::init_file_logger(paths::get_log_path());
}
// FIXME: Dynamic timestamp resolution: https://stackoverflow.com/q/17212518
// This kind of timestamp is reliable on for CI builds, as it will reflect the compilation
// time stamp only when this file gets recompiled.
LOG_INFO("🐨 {} v{} | Compiled at '{}'", PROJECT_NAME, PROJECT_VERSION, __TIMESTAMP__)
koalabox::cache::init_cache(paths::get_cache_path());