2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2025-10-22 06:16:01 +00:00

chore: add error handling for fastfile bind

This commit is contained in:
Jan Laupetin
2025-10-11 14:42:52 +01:00
parent 2037cf3258
commit 098be53559
4 changed files with 36 additions and 14 deletions

View File

@@ -2,8 +2,11 @@
#include "ZoneLoading.h"
bool FastFileContext::LoadFastFile(const std::string& path)
std::optional<Zone*> 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();
}

View File

@@ -2,12 +2,13 @@
#include "Zone/Zone.h"
#include <memory>
#include <optional>
#include <vector>
class FastFileContext
{
public:
bool LoadFastFile(const std::string& path);
std::optional<Zone*> LoadFastFile(const std::string& path);
std::vector<std::unique_ptr<Zone>> m_loaded_zones;
};

View File

@@ -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

View File

@@ -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;
});
}
</script>