diff --git a/src/ModMan/Context/FastFileContext.cpp b/src/ModMan/Context/FastFileContext.cpp index 1ea213e1..51d0814e 100644 --- a/src/ModMan/Context/FastFileContext.cpp +++ b/src/ModMan/Context/FastFileContext.cpp @@ -2,8 +2,11 @@ #include "ZoneLoading.h" -bool FastFileContext::LoadFastFile(const std::string& path) +std::optional FastFileContext::LoadFastFile(const std::string& path) { - m_loaded_zones.emplace_back(ZoneLoading::LoadZone(path)); - return true; + auto zone = ZoneLoading::LoadZone(path); + if (!zone) + return std::nullopt; + + return m_loaded_zones.emplace_back(std::move(zone)).get(); } diff --git a/src/ModMan/Context/FastFileContext.h b/src/ModMan/Context/FastFileContext.h index 9aed2d8c..54fa0114 100644 --- a/src/ModMan/Context/FastFileContext.h +++ b/src/ModMan/Context/FastFileContext.h @@ -2,12 +2,13 @@ #include "Zone/Zone.h" #include +#include #include class FastFileContext { public: - bool LoadFastFile(const std::string& path); + std::optional LoadFastFile(const std::string& path); std::vector> m_loaded_zones; }; diff --git a/src/ModMan/Web/Binds/FastFileBinds.cpp b/src/ModMan/Web/Binds/FastFileBinds.cpp index 3bfc74cb..a86ea0bf 100644 --- a/src/ModMan/Web/Binds/FastFileBinds.cpp +++ b/src/ModMan/Web/Binds/FastFileBinds.cpp @@ -5,8 +5,26 @@ namespace { + void LoadFastFile(webview::webview& wv, std::string id, std::string path) // NOLINT(performance-unnecessary-value-param) Copy is made for thread safety + { + ModManContext::Get().m_db_thread.Dispatch( + [&wv, id, path] + { + const auto maybeZone = ModManContext::Get().m_fast_file.LoadFastFile(path); -} + if (maybeZone) + { + ui::PromiseResolve(wv, id, true); + con::debug("Loaded zone \"{}\"", maybeZone.value()->m_name); + } + else + { + con::warn("Failed to load zone \"{}\"", path); + ui::PromiseReject(wv, id, false); + } + }); + } +} // namespace namespace ui { @@ -16,13 +34,7 @@ namespace ui "loadFastFile", [&wv](const std::string& id, std::string path) { - std::string idMove(id); - ModManContext::Get().m_db_thread.Dispatch( - [&wv, idMove, path] - { - ModManContext::Get().m_fast_file.LoadFastFile(path); - PromiseResolve(wv, idMove, true); - }); + LoadFastFile(wv, id, std::move(path)); }); } } // namespace ui diff --git a/src/ModManUi/src/App.vue b/src/ModManUi/src/App.vue index b360774f..3e15c414 100644 --- a/src/ModManUi/src/App.vue +++ b/src/ModManUi/src/App.vue @@ -9,9 +9,15 @@ async function onOpenFastfileClick() { lastPath.value = (await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? ""; - loadingFastFile.value = true; - await webviewBinds.loadFastFile(lastPath.value); + loadingFastFile.value = true; + + webviewBinds.loadFastFile(lastPath.value) + .catch((e) => { + console.error("Failed to load fastfile", e); + }) + .finally(() => { loadingFastFile.value = false; + }); }