From dd5ddbcc0f494c6d540a4411a9ce6b59680e207b Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 26 Mar 2024 19:49:03 +0100 Subject: [PATCH] fix: Settings being overwritten sometimes on crash --- lib/libimhex/source/api/content_registry.cpp | 13 +++++++++++-- main/gui/source/init/tasks.cpp | 5 ----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index 8b323fd3e..5c7628e87 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -58,6 +58,7 @@ namespace hex { } #if defined(OS_WEB) + void load() { char *data = (char *) MAIN_THREAD_EM_ASM_INT({ let data = localStorage.getItem("config"); @@ -73,7 +74,11 @@ namespace hex { for (const auto &[category, rest] : *impl::s_onChangeCallbacks) { for (const auto &[name, callbacks] : rest) { for (const auto &[id, callback] : callbacks) { - callback(getSetting(category, name, {})); + try { + callback(getSetting(category, name, {})); + } catch (const std::exception &e) { + log::error("Failed to load setting [{}/{}]: {}", category, name, e.what()); + } } } } @@ -112,7 +117,11 @@ namespace hex { for (const auto &[category, rest] : *impl::s_onChangeCallbacks) { for (const auto &[name, callbacks] : rest) { for (const auto &[id, callback] : callbacks) { - callback(getSetting(category, name, {})); + try { + callback(getSetting(category, name, {})); + } catch (const std::exception &e) { + log::error("Failed to load setting [{}/{}]: {}", category, name, e.what()); + } } } } diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index 09beb6929..41e11f011 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -226,13 +226,8 @@ namespace hex::init { // Try to load settings from file ContentRegistry::Settings::impl::load(); } catch (std::exception &e) { - // If that fails, create a new settings file - log::error("Failed to load configuration! {}", e.what()); - ContentRegistry::Settings::impl::clear(); - ContentRegistry::Settings::impl::store(); - return false; }