mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-11-17 18:52:06 +00:00
chore: add error handling for fastfile bind
This commit is contained in:
@@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
#include "ZoneLoading.h"
|
#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));
|
auto zone = ZoneLoading::LoadZone(path);
|
||||||
return true;
|
if (!zone)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
return m_loaded_zones.emplace_back(std::move(zone)).get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
#include "Zone/Zone.h"
|
#include "Zone/Zone.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class FastFileContext
|
class FastFileContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool LoadFastFile(const std::string& path);
|
std::optional<Zone*> LoadFastFile(const std::string& path);
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Zone>> m_loaded_zones;
|
std::vector<std::unique_ptr<Zone>> m_loaded_zones;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,8 +5,26 @@
|
|||||||
|
|
||||||
namespace
|
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
|
namespace ui
|
||||||
{
|
{
|
||||||
@@ -16,13 +34,7 @@ namespace ui
|
|||||||
"loadFastFile",
|
"loadFastFile",
|
||||||
[&wv](const std::string& id, std::string path)
|
[&wv](const std::string& id, std::string path)
|
||||||
{
|
{
|
||||||
std::string idMove(id);
|
LoadFastFile(wv, id, std::move(path));
|
||||||
ModManContext::Get().m_db_thread.Dispatch(
|
|
||||||
[&wv, idMove, path]
|
|
||||||
{
|
|
||||||
ModManContext::Get().m_fast_file.LoadFastFile(path);
|
|
||||||
PromiseResolve(wv, idMove, true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} // namespace ui
|
} // namespace ui
|
||||||
|
|||||||
@@ -9,9 +9,15 @@ async function onOpenFastfileClick() {
|
|||||||
lastPath.value =
|
lastPath.value =
|
||||||
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
|
(await webviewBinds.openFileDialog({ filters: [{ name: "Fastfiles", filter: "*.ff" }] })) ?? "";
|
||||||
|
|
||||||
loadingFastFile.value = true;
|
loadingFastFile.value = true;
|
||||||
await webviewBinds.loadFastFile(lastPath.value);
|
|
||||||
|
webviewBinds.loadFastFile(lastPath.value)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Failed to load fastfile", e);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
loadingFastFile.value = false;
|
loadingFastFile.value = false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user