2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-05-01 16:09:36 +00:00

feat: show loading progress in modman

This commit is contained in:
Jan Laupetin
2025-10-14 17:59:34 +01:00
parent 5b3664ad8c
commit 9fa41ca0d3
9 changed files with 134 additions and 12 deletions
+35 -1
View File
@@ -4,6 +4,40 @@
#include "Web/UiCommunication.h"
#include "ZoneLoading.h"
#include <filesystem>
namespace fs = std::filesystem;
namespace
{
constexpr double MIN_PROGRESS_TO_REPORT = 0.005;
class EventProgressReporter : public ProgressCallback
{
public:
explicit EventProgressReporter(std::string zoneName)
: m_zone_name(std::move(zoneName)),
m_last_progress(0)
{
}
void OnProgress(const size_t current, const size_t total) override
{
const double percentage = static_cast<double>(current) / static_cast<double>(total);
if (percentage - m_last_progress >= MIN_PROGRESS_TO_REPORT)
{
m_last_progress = percentage;
ui::NotifyZoneLoadProgress(m_zone_name, percentage);
}
}
private:
std::string m_zone_name;
double m_last_progress;
};
} // namespace
void FastFileContext::Destroy()
{
// Unload all zones
@@ -12,7 +46,7 @@ void FastFileContext::Destroy()
result::Expected<Zone*, std::string> FastFileContext::LoadFastFile(const std::string& path)
{
auto zone = ZoneLoading::LoadZone(path, std::nullopt);
auto zone = ZoneLoading::LoadZone(path, std::make_unique<EventProgressReporter>(fs::path(path).filename().replace_extension().string()));
if (!zone)
return result::Unexpected(std::move(zone.error()));