2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-01-24 08:53:04 +00:00

chore: add possibility to provide loading progress callback when loading zones

This commit is contained in:
Jan Laupetin
2025-10-14 16:48:20 +01:00
parent fa7fd26db6
commit 5b3664ad8c
22 changed files with 451 additions and 246 deletions

View File

@@ -1,9 +1,30 @@
#pragma once
#include "Game/IGame.h"
#include "Utils/ProgressCallback.h"
#include "Zone/ZoneTypes.h"
#include "ZoneLoader.h"
#include <memory>
#include <optional>
struct ZoneLoaderInspectionResult
{
// The game this zone is created for.
GameId m_game_id;
// Whether the zone is meant for a little-endian or big-endian loader.
GameEndianness m_endianness;
// Whether the zone is meant for a 32bit or 64bit loader.
GameWordSize m_word_size;
// The platform this zone is for.
GamePlatform m_platform;
// Whether this zone is confirmed official. False if not official or unknown.
bool m_is_official;
// Whether this zone contains a signature confirming the identity of the creator.
bool m_is_signed;
// Whether this zone is encrypted.
bool m_is_encrypted;
};
class IZoneLoaderFactory
{
@@ -15,7 +36,10 @@ public:
IZoneLoaderFactory& operator=(const IZoneLoaderFactory& other) = default;
IZoneLoaderFactory& operator=(IZoneLoaderFactory&& other) noexcept = default;
virtual std::unique_ptr<ZoneLoader> CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) const = 0;
[[nodiscard]] virtual std::optional<ZoneLoaderInspectionResult> InspectZoneHeader(const ZoneHeader& header) const = 0;
[[nodiscard]] virtual std::unique_ptr<ZoneLoader> CreateLoaderForHeader(const ZoneHeader& header,
const std::string& fileName,
std::optional<std::unique_ptr<ProgressCallback>> progressCallback) const = 0;
static const IZoneLoaderFactory* GetZoneLoaderFactoryForGame(GameId game);
};

View File

@@ -11,19 +11,21 @@ namespace
const unsigned pointerBitCount,
const unsigned offsetBlockBitCount,
const block_t insertBlock,
MemoryManager& memory)
MemoryManager& memory,
std::optional<std::unique_ptr<ProgressCallback>> progressCallback)
: m_entry_point_factory(std::move(entryPointFactory)),
m_pointer_bit_count(pointerBitCount),
m_offset_block_bit_count(offsetBlockBitCount),
m_insert_block(insertBlock),
m_memory(memory)
m_memory(memory),
m_progress_callback(std::move(progressCallback))
{
}
void PerformStep(ZoneLoader& zoneLoader, ILoadingStream& stream) override
{
const auto inputStream =
ZoneInputStream::Create(m_pointer_bit_count, m_offset_block_bit_count, zoneLoader.m_blocks, m_insert_block, stream, m_memory);
const auto inputStream = ZoneInputStream::Create(
m_pointer_bit_count, m_offset_block_bit_count, zoneLoader.m_blocks, m_insert_block, stream, m_memory, std::move(m_progress_callback));
const auto entryPoint = m_entry_point_factory(*inputStream);
assert(entryPoint);
@@ -37,6 +39,7 @@ namespace
unsigned m_offset_block_bit_count;
block_t m_insert_block;
MemoryManager& m_memory;
std::optional<std::unique_ptr<ProgressCallback>> m_progress_callback;
};
} // namespace
@@ -46,8 +49,10 @@ namespace step
const unsigned pointerBitCount,
const unsigned offsetBlockBitCount,
const block_t insertBlock,
MemoryManager& memory)
MemoryManager& memory,
std::optional<std::unique_ptr<ProgressCallback>> progressCallback)
{
return std::make_unique<StepLoadZoneContent>(std::move(entryPointFactory), pointerBitCount, offsetBlockBitCount, insertBlock, memory);
return std::make_unique<StepLoadZoneContent>(
std::move(entryPointFactory), pointerBitCount, offsetBlockBitCount, insertBlock, memory, std::move(progressCallback));
}
} // namespace step

View File

@@ -13,5 +13,6 @@ namespace step
unsigned pointerBitCount,
unsigned offsetBlockBitCount,
block_t insertBlock,
MemoryManager& memory);
MemoryManager& memory,
std::optional<std::unique_ptr<ProgressCallback>> progressCallback);
}