From 4ce82ad63c89bd49a5b0487776949784f295242c Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 2 May 2025 17:43:34 +0100 Subject: [PATCH] refactor: update ZoneLoading classes codestyle --- src/ZoneLoading/Loading/ContentLoaderBase.h | 4 ++++ src/ZoneLoading/Loading/IHashProvider.h | 8 ++++++- src/ZoneLoading/Loading/ILoadingStep.h | 5 ++++ src/ZoneLoading/Loading/ILoadingStream.h | 1 - src/ZoneLoading/Loading/ISignatureProvider.h | 7 ++++++ src/ZoneLoading/Loading/LoadingFileStream.h | 7 ++++-- .../Loading/Steps/StepAddProcessor.h | 5 ++-- .../Loading/Steps/StepAllocXBlocks.cpp | 5 +++- .../Loading/Steps/StepAllocXBlocks.h | 2 -- .../Loading/Steps/StepLoadHash.cpp | 2 +- src/ZoneLoading/Loading/Steps/StepLoadHash.h | 10 ++++---- .../Loading/Steps/StepLoadSignature.cpp | 14 ++++------- .../Loading/Steps/StepLoadSignature.h | 10 ++++---- .../Loading/Steps/StepLoadZoneContent.cpp | 8 ++----- .../Loading/Steps/StepLoadZoneContent.h | 11 +++++---- .../Loading/Steps/StepLoadZoneSizes.h | 12 +++++----- .../Loading/Steps/StepRemoveProcessor.h | 5 ++-- .../Loading/Steps/StepVerifyFileName.cpp | 2 +- .../Loading/Steps/StepVerifyFileName.h | 7 +++--- .../Loading/Steps/StepVerifyHash.cpp | 4 +--- .../Loading/Steps/StepVerifyHash.h | 16 +++++-------- .../Loading/Steps/StepVerifyMagic.h | 7 +++--- .../Loading/Steps/StepVerifySignature.h | 14 ++++------- src/ZoneLoading/Loading/ZoneLoader.h | 23 ++++++++++--------- 24 files changed, 102 insertions(+), 87 deletions(-) diff --git a/src/ZoneLoading/Loading/ContentLoaderBase.h b/src/ZoneLoading/Loading/ContentLoaderBase.h index 515859a8..b28af42f 100644 --- a/src/ZoneLoading/Loading/ContentLoaderBase.h +++ b/src/ZoneLoading/Loading/ContentLoaderBase.h @@ -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); diff --git a/src/ZoneLoading/Loading/IHashProvider.h b/src/ZoneLoading/Loading/IHashProvider.h index da76becb..7ba464ac 100644 --- a/src/ZoneLoading/Loading/IHashProvider.h +++ b/src/ZoneLoading/Loading/IHashProvider.h @@ -1,10 +1,16 @@ #pragma once -#include #include 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; }; diff --git a/src/ZoneLoading/Loading/ILoadingStep.h b/src/ZoneLoading/Loading/ILoadingStep.h index 6f29f718..25bf055d 100644 --- a/src/ZoneLoading/Loading/ILoadingStep.h +++ b/src/ZoneLoading/Loading/ILoadingStep.h @@ -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; }; diff --git a/src/ZoneLoading/Loading/ILoadingStream.h b/src/ZoneLoading/Loading/ILoadingStream.h index d9512718..a6486e30 100644 --- a/src/ZoneLoading/Loading/ILoadingStream.h +++ b/src/ZoneLoading/Loading/ILoadingStream.h @@ -1,6 +1,5 @@ #pragma once -#include #include class ILoadingStream diff --git a/src/ZoneLoading/Loading/ISignatureProvider.h b/src/ZoneLoading/Loading/ISignatureProvider.h index 009eaaea..590ff5f4 100644 --- a/src/ZoneLoading/Loading/ISignatureProvider.h +++ b/src/ZoneLoading/Loading/ISignatureProvider.h @@ -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; }; diff --git a/src/ZoneLoading/Loading/LoadingFileStream.h b/src/ZoneLoading/Loading/LoadingFileStream.h index 8073f477..170e091d 100644 --- a/src/ZoneLoading/Loading/LoadingFileStream.h +++ b/src/ZoneLoading/Loading/LoadingFileStream.h @@ -1,15 +1,18 @@ #pragma once + #include "ILoadingStream.h" +#include #include 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; }; diff --git a/src/ZoneLoading/Loading/Steps/StepAddProcessor.h b/src/ZoneLoading/Loading/Steps/StepAddProcessor.h index 661ec0e6..62632928 100644 --- a/src/ZoneLoading/Loading/Steps/StepAddProcessor.h +++ b/src/ZoneLoading/Loading/Steps/StepAddProcessor.h @@ -6,10 +6,11 @@ class StepAddProcessor final : public ILoadingStep { - std::unique_ptr m_stream_processor; - public: explicit StepAddProcessor(std::unique_ptr streamProcessor); void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override; + +private: + std::unique_ptr m_stream_processor; }; diff --git a/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.cpp b/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.cpp index 352d814b..31d2f39c 100644 --- a/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.cpp +++ b/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.cpp @@ -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) { diff --git a/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.h b/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.h index 99f1cc3a..fcc400e9 100644 --- a/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.h +++ b/src/ZoneLoading/Loading/Steps/StepAllocXBlocks.h @@ -4,8 +4,6 @@ class StepAllocXBlocks final : public ILoadingStep { - static const uint64_t MAX_XBLOCK_SIZE; - public: void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override; }; diff --git a/src/ZoneLoading/Loading/Steps/StepLoadHash.cpp b/src/ZoneLoading/Loading/Steps/StepLoadHash.cpp index 545ccd84..4fb7c9e8 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadHash.cpp +++ b/src/ZoneLoading/Loading/Steps/StepLoadHash.cpp @@ -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); diff --git a/src/ZoneLoading/Loading/Steps/StepLoadHash.h b/src/ZoneLoading/Loading/Steps/StepLoadHash.h index c7e4cdf8..234278b7 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadHash.h +++ b/src/ZoneLoading/Loading/Steps/StepLoadHash.h @@ -4,14 +4,11 @@ #include "Loading/ILoadingStep.h" #include "Utils/ICapturedDataProvider.h" +#include #include class StepLoadHash final : public ILoadingStep, public IHashProvider, public ICapturedDataProvider { - const size_t m_hash_size; - const unsigned m_hash_count; - std::unique_ptr 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 m_hashes; }; diff --git a/src/ZoneLoading/Loading/Steps/StepLoadSignature.cpp b/src/ZoneLoading/Loading/Steps/StepLoadSignature.cpp index 8fbc19e8..bab62d9a 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadSignature.cpp +++ b/src/ZoneLoading/Loading/Steps/StepLoadSignature.cpp @@ -5,22 +5,16 @@ #include StepLoadSignature::StepLoadSignature(const size_t signatureSize) + : m_signature(std::make_unique(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; } diff --git a/src/ZoneLoading/Loading/Steps/StepLoadSignature.h b/src/ZoneLoading/Loading/Steps/StepLoadSignature.h index 822653ce..f84c1e57 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadSignature.h +++ b/src/ZoneLoading/Loading/Steps/StepLoadSignature.h @@ -3,15 +3,17 @@ #include "Loading/ILoadingStep.h" #include "Loading/ISignatureProvider.h" +#include + 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 m_signature; + size_t m_signature_size; }; diff --git a/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp b/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp index 7dbdb015..f8ec9518 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp +++ b/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.cpp @@ -2,8 +2,6 @@ #include "Zone/Stream/Impl/XBlockInputStream.h" -#include - StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr entryPoint, Zone* zone, const int offsetBlockBitCount, @@ -17,9 +15,7 @@ StepLoadZoneContent::StepLoadZoneContent(std::unique_ptrm_blocks, stream, m_offset_block_bit_count, m_insert_block); + const auto inputStream = std::make_unique(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()); } diff --git a/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.h b/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.h index 450c7f16..ba30d924 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.h +++ b/src/ZoneLoading/Loading/Steps/StepLoadZoneContent.h @@ -7,13 +7,14 @@ class StepLoadZoneContent final : public ILoadingStep { - std::unique_ptr m_content_loader; - Zone* m_zone; - int m_offset_block_bit_count; - block_t m_insert_block; - public: StepLoadZoneContent(std::unique_ptr entryPoint, Zone* zone, int offsetBlockBitCount, block_t insertBlock); void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override; + +private: + std::unique_ptr m_content_loader; + Zone* m_zone; + int m_offset_block_bit_count; + block_t m_insert_block; }; diff --git a/src/ZoneLoading/Loading/Steps/StepLoadZoneSizes.h b/src/ZoneLoading/Loading/Steps/StepLoadZoneSizes.h index 10061adf..d0a0df06 100644 --- a/src/ZoneLoading/Loading/Steps/StepLoadZoneSizes.h +++ b/src/ZoneLoading/Loading/Steps/StepLoadZoneSizes.h @@ -1,20 +1,20 @@ #pragma once #include "Loading/ILoadingStep.h" -#include "Utils/ClassUtils.h" #include 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; }; diff --git a/src/ZoneLoading/Loading/Steps/StepRemoveProcessor.h b/src/ZoneLoading/Loading/Steps/StepRemoveProcessor.h index 8049bad5..1b5b5805 100644 --- a/src/ZoneLoading/Loading/Steps/StepRemoveProcessor.h +++ b/src/ZoneLoading/Loading/Steps/StepRemoveProcessor.h @@ -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; }; diff --git a/src/ZoneLoading/Loading/Steps/StepVerifyFileName.cpp b/src/ZoneLoading/Loading/Steps/StepVerifyFileName.cpp index d1ab39c0..682235ff 100644 --- a/src/ZoneLoading/Loading/Steps/StepVerifyFileName.cpp +++ b/src/ZoneLoading/Loading/Steps/StepVerifyFileName.cpp @@ -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); diff --git a/src/ZoneLoading/Loading/Steps/StepVerifyFileName.h b/src/ZoneLoading/Loading/Steps/StepVerifyFileName.h index 542d08e2..eb569f62 100644 --- a/src/ZoneLoading/Loading/Steps/StepVerifyFileName.h +++ b/src/ZoneLoading/Loading/Steps/StepVerifyFileName.h @@ -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; }; diff --git a/src/ZoneLoading/Loading/Steps/StepVerifyHash.cpp b/src/ZoneLoading/Loading/Steps/StepVerifyHash.cpp index dcbacf8f..9226a69d 100644 --- a/src/ZoneLoading/Loading/Steps/StepVerifyHash.cpp +++ b/src/ZoneLoading/Loading/Steps/StepVerifyHash.cpp @@ -16,8 +16,6 @@ StepVerifyHash::StepVerifyHash(std::unique_ptr 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 hashMemory = std::make_unique(m_hash_function->GetHashSize()); + const auto hashMemory = std::make_unique(m_hash_function->GetHashSize()); m_hash_function->Init(); m_hash_function->Process(dataToHash, dataToHashSize); m_hash_function->Finish(hashMemory.get()); diff --git a/src/ZoneLoading/Loading/Steps/StepVerifyHash.h b/src/ZoneLoading/Loading/Steps/StepVerifyHash.h index b85fb3d7..0fe86d53 100644 --- a/src/ZoneLoading/Loading/Steps/StepVerifyHash.h +++ b/src/ZoneLoading/Loading/Steps/StepVerifyHash.h @@ -9,21 +9,17 @@ class StepVerifyHash final : public ILoadingStep { - std::unique_ptr m_hash_function; - unsigned m_hash_index; - IHashProvider* m_hash_provider; - ICapturedDataProvider* m_data_provider; - public: StepVerifyHash(std::unique_ptr 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 m_hash_function; + unsigned m_hash_index; + IHashProvider* m_hash_provider; + ICapturedDataProvider* m_data_provider; }; diff --git a/src/ZoneLoading/Loading/Steps/StepVerifyMagic.h b/src/ZoneLoading/Loading/Steps/StepVerifyMagic.h index 9eed7410..19c82427 100644 --- a/src/ZoneLoading/Loading/Steps/StepVerifyMagic.h +++ b/src/ZoneLoading/Loading/Steps/StepVerifyMagic.h @@ -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; }; diff --git a/src/ZoneLoading/Loading/Steps/StepVerifySignature.h b/src/ZoneLoading/Loading/Steps/StepVerifySignature.h index 3ce85bfe..0c1d70ee 100644 --- a/src/ZoneLoading/Loading/Steps/StepVerifySignature.h +++ b/src/ZoneLoading/Loading/Steps/StepVerifySignature.h @@ -7,19 +7,15 @@ class StepVerifySignature final : public ILoadingStep { - std::unique_ptr m_algorithm; - ISignatureProvider* m_signature_provider; - ICapturedDataProvider* m_signature_data_provider; - public: StepVerifySignature(std::unique_ptr 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 m_algorithm; + ISignatureProvider* m_signature_provider; + ICapturedDataProvider* m_signature_data_provider; }; diff --git a/src/ZoneLoading/Loading/ZoneLoader.h b/src/ZoneLoading/Loading/ZoneLoader.h index f0bfe3f1..25fc2fac 100644 --- a/src/ZoneLoading/Loading/ZoneLoader.h +++ b/src/ZoneLoading/Loading/ZoneLoader.h @@ -13,18 +13,7 @@ class ILoadingStep; class ZoneLoader { - std::vector> m_steps; - std::vector> m_processors; - - bool m_processor_chain_dirty; - - std::unique_ptr m_zone; - - ILoadingStream* BuildLoadingChain(ILoadingStream* rootStream); - public: - std::vector m_blocks; - explicit ZoneLoader(std::unique_ptr zone); void AddXBlock(std::unique_ptr block); @@ -34,4 +23,16 @@ public: void RemoveStreamProcessor(StreamProcessor* streamProcessor); std::unique_ptr LoadZone(std::istream& stream); + + std::vector m_blocks; + +private: + ILoadingStream* BuildLoadingChain(ILoadingStream* rootStream); + + std::vector> m_steps; + std::vector> m_processors; + + bool m_processor_chain_dirty; + + std::unique_ptr m_zone; };