From 5372fe6e43ee3527f59f7b00fa4df1fa9c082a41 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Mon, 10 Jul 2023 10:46:47 -0700 Subject: [PATCH 1/2] config: Use `error_code` prototype of `filesystem::exists` The non-error-code version of these functions are susceptible to throwing an exception in the case of system errors like permission issues or underlying device errors. --- src/config.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 9964c1c7..7dfc2cb5 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -11,7 +11,8 @@ void EmulatorConfig::load(const std::filesystem::path& path) { // If the configuration file does not exist, create it and return - if (!std::filesystem::exists(path)) { + std::error_code error; + if (!std::filesystem::exists(path, error)) { save(path); return; } @@ -38,13 +39,19 @@ void EmulatorConfig::load(const std::filesystem::path& path) { void EmulatorConfig::save(const std::filesystem::path& path) { toml::basic_value data; - if (std::filesystem::exists(path)) { + std::error_code error; + if (std::filesystem::exists(path, error)) { try { data = toml::parse(path); } catch (std::exception& ex) { - Helpers::warn("Got exception trying to save config file. Exception: %s\n", ex.what()); + Helpers::warn("Exception trying to parse config file. Exception: %s\n", ex.what()); return; } + } else { + if (error) { + Helpers::warn("FileSystem error accessing %s %s\n", path.string().c_str(), error.message().c_str()); + } + Helpers::warn("Saving new configuration file %s \n", path.string().c_str()); } data["GPU"]["EnableShaderJIT"] = shaderJitEnabled; From e4f3c3beda0e897f6319e66069db1075e0b93b02 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Mon, 10 Jul 2023 22:01:49 +0300 Subject: [PATCH 2/2] Bonk config.cpp --- src/config.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 7dfc2cb5..6c9a8450 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -49,9 +49,9 @@ void EmulatorConfig::save(const std::filesystem::path& path) { } } else { if (error) { - Helpers::warn("FileSystem error accessing %s %s\n", path.string().c_str(), error.message().c_str()); + Helpers::warn("Filesystem error accessing %s (error: %s)\n", path.string().c_str(), error.message().c_str()); } - Helpers::warn("Saving new configuration file %s \n", path.string().c_str()); + printf("Saving new configuration file %s\n", path.string().c_str()); } data["GPU"]["EnableShaderJIT"] = shaderJitEnabled; @@ -59,4 +59,4 @@ void EmulatorConfig::save(const std::filesystem::path& path) { std::ofstream file(path, std::ios::out); file << data; file.close(); -} \ No newline at end of file +}