mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-05-07 13:04:58 +00:00
refactor: update ZoneLoading classes codestyle
This commit is contained in:
parent
446c38d8ee
commit
4ce82ad63c
@ -11,6 +11,10 @@ protected:
|
||||
|
||||
public:
|
||||
virtual ~ContentLoaderBase() = default;
|
||||
ContentLoaderBase(const ContentLoaderBase& other) = default;
|
||||
ContentLoaderBase(ContentLoaderBase&& other) noexcept = default;
|
||||
ContentLoaderBase& operator=(const ContentLoaderBase& other) = delete;
|
||||
ContentLoaderBase& operator=(ContentLoaderBase&& other) noexcept = delete;
|
||||
|
||||
protected:
|
||||
explicit ContentLoaderBase(Zone& zone);
|
||||
|
@ -1,10 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
class IHashProvider
|
||||
{
|
||||
public:
|
||||
IHashProvider() = default;
|
||||
virtual ~IHashProvider() = default;
|
||||
IHashProvider(const IHashProvider& other) = default;
|
||||
IHashProvider(IHashProvider&& other) noexcept = default;
|
||||
IHashProvider& operator=(const IHashProvider& other) = default;
|
||||
IHashProvider& operator=(IHashProvider&& other) noexcept = default;
|
||||
|
||||
virtual void GetHash(unsigned hashIndex, const uint8_t** pHash, size_t* pSize) = 0;
|
||||
};
|
||||
|
@ -8,7 +8,12 @@ class ZoneLoader;
|
||||
class ILoadingStep
|
||||
{
|
||||
public:
|
||||
ILoadingStep() = default;
|
||||
virtual ~ILoadingStep() = default;
|
||||
ILoadingStep(const ILoadingStep& other) = default;
|
||||
ILoadingStep(ILoadingStep&& other) noexcept = default;
|
||||
ILoadingStep& operator=(const ILoadingStep& other) = default;
|
||||
ILoadingStep& operator=(ILoadingStep&& other) noexcept = default;
|
||||
|
||||
virtual void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) = 0;
|
||||
};
|
||||
|
@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
class ILoadingStream
|
||||
|
@ -4,5 +4,12 @@
|
||||
class ISignatureProvider
|
||||
{
|
||||
public:
|
||||
ISignatureProvider() = default;
|
||||
virtual ~ISignatureProvider() = default;
|
||||
ISignatureProvider(const ISignatureProvider& other) = default;
|
||||
ISignatureProvider(ISignatureProvider&& other) noexcept = default;
|
||||
ISignatureProvider& operator=(const ISignatureProvider& other) = default;
|
||||
ISignatureProvider& operator=(ISignatureProvider&& other) noexcept = default;
|
||||
|
||||
virtual void GetSignature(const uint8_t** pSignature, size_t* pSize) = 0;
|
||||
};
|
||||
|
@ -1,15 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "ILoadingStream.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
|
||||
class LoadingFileStream final : public ILoadingStream
|
||||
{
|
||||
std::istream& m_stream;
|
||||
|
||||
public:
|
||||
explicit LoadingFileStream(std::istream& stream);
|
||||
|
||||
size_t Load(void* buffer, size_t length) override;
|
||||
int64_t Pos() override;
|
||||
|
||||
private:
|
||||
std::istream& m_stream;
|
||||
};
|
||||
|
@ -6,10 +6,11 @@
|
||||
|
||||
class StepAddProcessor final : public ILoadingStep
|
||||
{
|
||||
std::unique_ptr<StreamProcessor> m_stream_processor;
|
||||
|
||||
public:
|
||||
explicit StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<StreamProcessor> m_stream_processor;
|
||||
};
|
||||
|
@ -2,7 +2,10 @@
|
||||
|
||||
#include "Loading/Exception/InvalidXBlockSizeException.h"
|
||||
|
||||
const uint64_t StepAllocXBlocks::MAX_XBLOCK_SIZE = 0x3C000000;
|
||||
namespace
|
||||
{
|
||||
constexpr uint64_t MAX_XBLOCK_SIZE = 0x3C000000;
|
||||
}
|
||||
|
||||
void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
|
@ -4,8 +4,6 @@
|
||||
|
||||
class StepAllocXBlocks final : public ILoadingStep
|
||||
{
|
||||
static const uint64_t MAX_XBLOCK_SIZE;
|
||||
|
||||
public:
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
};
|
||||
|
@ -25,7 +25,7 @@ void StepLoadHash::GetHash(const unsigned hashIndex, const uint8_t** pHash, size
|
||||
{
|
||||
assert(pHash != nullptr);
|
||||
assert(pSize != nullptr);
|
||||
assert(hashIndex >= 0 && hashIndex < m_hash_count);
|
||||
assert(hashIndex < m_hash_count);
|
||||
|
||||
assert(m_hashes);
|
||||
|
||||
|
@ -4,14 +4,11 @@
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Utils/ICapturedDataProvider.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
class StepLoadHash final : public ILoadingStep, public IHashProvider, public ICapturedDataProvider
|
||||
{
|
||||
const size_t m_hash_size;
|
||||
const unsigned m_hash_count;
|
||||
std::unique_ptr<uint8_t[]> m_hashes;
|
||||
|
||||
public:
|
||||
StepLoadHash(size_t hashSize, unsigned hashCount);
|
||||
~StepLoadHash() override;
|
||||
@ -24,4 +21,9 @@ public:
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
void GetHash(unsigned hashIndex, const uint8_t** pHash, size_t* pSize) override;
|
||||
void GetCapturedData(const uint8_t** pCapturedData, size_t* pSize) override;
|
||||
|
||||
private:
|
||||
const size_t m_hash_size;
|
||||
const unsigned m_hash_count;
|
||||
std::unique_ptr<uint8_t[]> m_hashes;
|
||||
};
|
||||
|
@ -5,22 +5,16 @@
|
||||
#include <cassert>
|
||||
|
||||
StepLoadSignature::StepLoadSignature(const size_t signatureSize)
|
||||
: m_signature(std::make_unique<uint8_t[]>(signatureSize)),
|
||||
m_signature_size(signatureSize)
|
||||
{
|
||||
m_signature_size = signatureSize;
|
||||
m_signature = new uint8_t[signatureSize];
|
||||
}
|
||||
|
||||
StepLoadSignature::~StepLoadSignature()
|
||||
{
|
||||
delete[] m_signature;
|
||||
m_signature = nullptr;
|
||||
}
|
||||
|
||||
void StepLoadSignature::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
assert(stream != nullptr);
|
||||
|
||||
if (stream->Load(m_signature, m_signature_size) != m_signature_size)
|
||||
if (stream->Load(m_signature.get(), m_signature_size) != m_signature_size)
|
||||
throw UnexpectedEndOfFileException();
|
||||
}
|
||||
|
||||
@ -31,6 +25,6 @@ void StepLoadSignature::GetSignature(const uint8_t** pSignature, size_t* pSize)
|
||||
|
||||
assert(m_signature != nullptr);
|
||||
|
||||
*pSignature = m_signature;
|
||||
*pSignature = m_signature.get();
|
||||
*pSize = m_signature_size;
|
||||
}
|
||||
|
@ -3,15 +3,17 @@
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Loading/ISignatureProvider.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class StepLoadSignature final : public ILoadingStep, public ISignatureProvider
|
||||
{
|
||||
uint8_t* m_signature;
|
||||
size_t m_signature_size;
|
||||
|
||||
public:
|
||||
explicit StepLoadSignature(size_t signatureSize);
|
||||
~StepLoadSignature() override;
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
void GetSignature(const uint8_t** pSignature, size_t* pSize) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8_t[]> m_signature;
|
||||
size_t m_signature_size;
|
||||
};
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
#include "Zone/Stream/Impl/XBlockInputStream.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint,
|
||||
Zone* zone,
|
||||
const int offsetBlockBitCount,
|
||||
@ -17,9 +15,7 @@ StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoi
|
||||
|
||||
void StepLoadZoneContent::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
auto* inputStream = new XBlockInputStream(zoneLoader->m_blocks, stream, m_offset_block_bit_count, m_insert_block);
|
||||
const auto inputStream = std::make_unique<XBlockInputStream>(zoneLoader->m_blocks, stream, m_offset_block_bit_count, m_insert_block);
|
||||
|
||||
m_content_loader->Load(inputStream);
|
||||
|
||||
delete inputStream;
|
||||
m_content_loader->Load(inputStream.get());
|
||||
}
|
||||
|
@ -7,13 +7,14 @@
|
||||
|
||||
class StepLoadZoneContent final : public ILoadingStep
|
||||
{
|
||||
std::unique_ptr<IContentLoadingEntryPoint> m_content_loader;
|
||||
Zone* m_zone;
|
||||
int m_offset_block_bit_count;
|
||||
block_t m_insert_block;
|
||||
|
||||
public:
|
||||
StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, Zone* zone, int offsetBlockBitCount, block_t insertBlock);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<IContentLoadingEntryPoint> m_content_loader;
|
||||
Zone* m_zone;
|
||||
int m_offset_block_bit_count;
|
||||
block_t m_insert_block;
|
||||
};
|
||||
|
@ -1,20 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include "Loading/ILoadingStep.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
class StepLoadZoneSizes final : public ILoadingStep
|
||||
{
|
||||
size_t m_size;
|
||||
size_t m_external_size;
|
||||
|
||||
public:
|
||||
StepLoadZoneSizes();
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
_NODISCARD size_t GetSize() const;
|
||||
_NODISCARD size_t GetExternalSize() const;
|
||||
[[nodiscard]] size_t GetSize() const;
|
||||
[[nodiscard]] size_t GetExternalSize() const;
|
||||
|
||||
private:
|
||||
size_t m_size;
|
||||
size_t m_external_size;
|
||||
};
|
||||
|
@ -4,10 +4,11 @@
|
||||
|
||||
class StepRemoveProcessor final : public ILoadingStep
|
||||
{
|
||||
StreamProcessor* m_stream_processor;
|
||||
|
||||
public:
|
||||
explicit StepRemoveProcessor(StreamProcessor* streamProcessor);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
StreamProcessor* m_stream_processor;
|
||||
};
|
||||
|
@ -39,7 +39,7 @@ void StepVerifyFileName::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* str
|
||||
bufferOffset++;
|
||||
}
|
||||
|
||||
std::string originalFileName = originalFilenameStream.str();
|
||||
const auto originalFileName = originalFilenameStream.str();
|
||||
|
||||
if (originalFileName != m_expected_file_name)
|
||||
throw InvalidFileNameException(m_expected_file_name, originalFileName);
|
||||
|
@ -4,11 +4,12 @@
|
||||
|
||||
class StepVerifyFileName final : public ILoadingStep
|
||||
{
|
||||
std::string m_expected_file_name;
|
||||
size_t m_file_name_buffer_size;
|
||||
|
||||
public:
|
||||
explicit StepVerifyFileName(std::string fileName, size_t fileNameBufferSize);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
std::string m_expected_file_name;
|
||||
size_t m_file_name_buffer_size;
|
||||
};
|
||||
|
@ -16,8 +16,6 @@ StepVerifyHash::StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hash
|
||||
{
|
||||
}
|
||||
|
||||
StepVerifyHash::~StepVerifyHash() = default;
|
||||
|
||||
void StepVerifyHash::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
{
|
||||
const uint8_t* dataToHash = nullptr;
|
||||
@ -31,7 +29,7 @@ void StepVerifyHash::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
|
||||
if (hashSize != m_hash_function->GetHashSize())
|
||||
throw InvalidHashException();
|
||||
|
||||
const std::unique_ptr<uint8_t[]> hashMemory = std::make_unique<uint8_t[]>(m_hash_function->GetHashSize());
|
||||
const auto hashMemory = std::make_unique<uint8_t[]>(m_hash_function->GetHashSize());
|
||||
m_hash_function->Init();
|
||||
m_hash_function->Process(dataToHash, dataToHashSize);
|
||||
m_hash_function->Finish(hashMemory.get());
|
||||
|
@ -9,21 +9,17 @@
|
||||
|
||||
class StepVerifyHash final : public ILoadingStep
|
||||
{
|
||||
std::unique_ptr<cryptography::IHashFunction> m_hash_function;
|
||||
unsigned m_hash_index;
|
||||
IHashProvider* m_hash_provider;
|
||||
ICapturedDataProvider* m_data_provider;
|
||||
|
||||
public:
|
||||
StepVerifyHash(std::unique_ptr<cryptography::IHashFunction> hashFunction,
|
||||
unsigned hashIndex,
|
||||
IHashProvider* hashProvider,
|
||||
ICapturedDataProvider* dataProvider);
|
||||
~StepVerifyHash();
|
||||
StepVerifyHash(const StepVerifyHash& other) = delete;
|
||||
StepVerifyHash(StepVerifyHash&& other) noexcept = default;
|
||||
StepVerifyHash& operator=(const StepVerifyHash& other) = delete;
|
||||
StepVerifyHash& operator=(StepVerifyHash&& other) noexcept = default;
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<cryptography::IHashFunction> m_hash_function;
|
||||
unsigned m_hash_index;
|
||||
IHashProvider* m_hash_provider;
|
||||
ICapturedDataProvider* m_data_provider;
|
||||
};
|
||||
|
@ -4,11 +4,12 @@
|
||||
|
||||
class StepVerifyMagic final : public ILoadingStep
|
||||
{
|
||||
const char* m_magic;
|
||||
size_t m_magic_len;
|
||||
|
||||
public:
|
||||
explicit StepVerifyMagic(const char* magic);
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
const char* m_magic;
|
||||
size_t m_magic_len;
|
||||
};
|
||||
|
@ -7,19 +7,15 @@
|
||||
|
||||
class StepVerifySignature final : public ILoadingStep
|
||||
{
|
||||
std::unique_ptr<cryptography::IPublicKeyAlgorithm> m_algorithm;
|
||||
ISignatureProvider* m_signature_provider;
|
||||
ICapturedDataProvider* m_signature_data_provider;
|
||||
|
||||
public:
|
||||
StepVerifySignature(std::unique_ptr<cryptography::IPublicKeyAlgorithm> signatureAlgorithm,
|
||||
ISignatureProvider* signatureProvider,
|
||||
ICapturedDataProvider* signatureDataProvider);
|
||||
~StepVerifySignature() override = default;
|
||||
StepVerifySignature(const StepVerifySignature& other) = delete;
|
||||
StepVerifySignature(StepVerifySignature&& other) noexcept = default;
|
||||
StepVerifySignature& operator=(const StepVerifySignature& other) = delete;
|
||||
StepVerifySignature& operator=(StepVerifySignature&& other) noexcept = default;
|
||||
|
||||
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<cryptography::IPublicKeyAlgorithm> m_algorithm;
|
||||
ISignatureProvider* m_signature_provider;
|
||||
ICapturedDataProvider* m_signature_data_provider;
|
||||
};
|
||||
|
@ -13,18 +13,7 @@ class ILoadingStep;
|
||||
|
||||
class ZoneLoader
|
||||
{
|
||||
std::vector<std::unique_ptr<ILoadingStep>> m_steps;
|
||||
std::vector<std::unique_ptr<StreamProcessor>> m_processors;
|
||||
|
||||
bool m_processor_chain_dirty;
|
||||
|
||||
std::unique_ptr<Zone> m_zone;
|
||||
|
||||
ILoadingStream* BuildLoadingChain(ILoadingStream* rootStream);
|
||||
|
||||
public:
|
||||
std::vector<XBlock*> m_blocks;
|
||||
|
||||
explicit ZoneLoader(std::unique_ptr<Zone> zone);
|
||||
|
||||
void AddXBlock(std::unique_ptr<XBlock> block);
|
||||
@ -34,4 +23,16 @@ public:
|
||||
void RemoveStreamProcessor(StreamProcessor* streamProcessor);
|
||||
|
||||
std::unique_ptr<Zone> LoadZone(std::istream& stream);
|
||||
|
||||
std::vector<XBlock*> m_blocks;
|
||||
|
||||
private:
|
||||
ILoadingStream* BuildLoadingChain(ILoadingStream* rootStream);
|
||||
|
||||
std::vector<std::unique_ptr<ILoadingStep>> m_steps;
|
||||
std::vector<std::unique_ptr<StreamProcessor>> m_processors;
|
||||
|
||||
bool m_processor_chain_dirty;
|
||||
|
||||
std::unique_ptr<Zone> m_zone;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user