Reformat code with clang format

This commit is contained in:
Clang Format
2023-11-19 15:28:38 +01:00
committed by Jan
parent 22e17272fd
commit 6b4f5d94a8
1099 changed files with 16763 additions and 18076 deletions

View File

@ -1,7 +1,7 @@
#include "AssetLoader.h"
#include <cassert>
#include <algorithm>
#include <cassert>
AssetLoader::AssetLoader(const asset_type_t assetType, Zone* zone, IZoneInputStream* stream)
: ContentLoaderBase(zone, stream),

View File

@ -1,11 +1,11 @@
#pragma once
#include <vector>
#include <unordered_set>
#include "Zone/ZoneTypes.h"
#include "Pool/XAssetInfo.h"
#include "ContentLoaderBase.h"
#include "Pool/XAssetInfo.h"
#include "Zone/ZoneTypes.h"
#include <unordered_set>
#include <vector>
class AssetLoader : public ContentLoaderBase
{
@ -18,7 +18,7 @@ protected:
scr_string_t* varScriptString;
AssetLoader(asset_type_t assetType, Zone* zone, IZoneInputStream* stream);
void AddDependency(XAssetInfoGeneric* assetInfo);
scr_string_t UseScriptString(scr_string_t scrString);

View File

@ -9,4 +9,4 @@ protected:
public:
explicit AssetLoadingActions(Zone* zone);
};
};

View File

@ -1,4 +1,5 @@
#include "ContentLoaderBase.h"
#include <cassert>
const void* ContentLoaderBase::PTR_FOLLOWING = reinterpret_cast<void*>(-1);

View File

@ -1,7 +1,7 @@
#pragma once
#include "Zone/Zone.h"
#include "Zone/Stream/IZoneInputStream.h"
#include "Zone/Zone.h"
class ContentLoaderBase
{

View File

@ -13,4 +13,4 @@ std::string BlockOverflowException::DetailedMessage()
char const* BlockOverflowException::what() const noexcept
{
return "Invalid Zone. XBlock overflowed.";
}
}

View File

@ -14,7 +14,7 @@ InvalidChunkSizeException::InvalidChunkSizeException(const size_t size, const si
std::string InvalidChunkSizeException::DetailedMessage()
{
if(m_max > 0)
if (m_max > 0)
{
return "Zone chunk size has a chunk size of " + std::to_string(m_size) + " which is larger than the maximum of " + std::to_string(m_max);
}
@ -27,4 +27,4 @@ std::string InvalidChunkSizeException::DetailedMessage()
char const* InvalidChunkSizeException::what() const noexcept
{
return "Zone has invalid chunk size";
}
}

View File

@ -14,4 +14,4 @@ std::string InvalidFileNameException::DetailedMessage()
char const* InvalidFileNameException::what() const noexcept
{
return "The filename when created and when loaded does not match";
}
}

View File

@ -8,4 +8,4 @@ std::string InvalidHashException::DetailedMessage()
char const* InvalidHashException::what() const noexcept
{
return "Loaded fastfile has an invalid hash.";
}
}

View File

@ -1,5 +1,5 @@
#include "InvalidMagicException.h"
InvalidMagicException::InvalidMagicException(const char* expectedMagic)
{
m_expected_magic = expectedMagic;
@ -13,4 +13,4 @@ std::string InvalidMagicException::DetailedMessage()
char const* InvalidMagicException::what() const noexcept
{
return "Encountered invalid magic when loading.";
}
}

View File

@ -13,4 +13,4 @@ std::string InvalidOffsetBlockException::DetailedMessage()
char const* InvalidOffsetBlockException::what() const noexcept
{
return "Zone referenced invalid block";
}
}

View File

@ -8,11 +8,11 @@ InvalidOffsetBlockOffsetException::InvalidOffsetBlockOffsetException(XBlock* blo
std::string InvalidOffsetBlockOffsetException::DetailedMessage()
{
return "Zone referenced offset " + std::to_string(m_referenced_offset) + " of block " + m_referenced_block->m_name
+ " which is larger than its size " + std::to_string(m_referenced_block->m_buffer_size);
return "Zone referenced offset " + std::to_string(m_referenced_offset) + " of block " + m_referenced_block->m_name + " which is larger than its size "
+ std::to_string(m_referenced_block->m_buffer_size);
}
char const* InvalidOffsetBlockOffsetException::what() const noexcept
{
return "Zone referenced offset of block that is out of bounds";
}
}

View File

@ -8,4 +8,4 @@ std::string InvalidSignatureException::DetailedMessage()
char const* InvalidSignatureException::what() const noexcept
{
return "Loaded fastfile has an invalid signature.";
}
}

View File

@ -14,4 +14,4 @@ std::string InvalidVersionException::DetailedMessage()
char const* InvalidVersionException::what() const noexcept
{
return "Encountered invalid version when loading.";
}
}

View File

@ -14,4 +14,4 @@ std::string InvalidXBlockSizeException::DetailedMessage()
char const* InvalidXBlockSizeException::what() const noexcept
{
return "Zone has invalid block size";
}
}

View File

@ -1,7 +1,8 @@
#pragma once
#include <cstdint>
#include "LoadingException.h"
#include <cstdint>
class InvalidXBlockSizeException final : public LoadingException
{
uint64_t m_size;

View File

@ -13,4 +13,4 @@ std::string OutOfBlockBoundsException::DetailedMessage()
char const* OutOfBlockBoundsException::what() const noexcept
{
return "Invalid Zone. Out of XBlock bounds.";
}
}

View File

@ -8,4 +8,4 @@ std::string TooManyAuthedGroupsException::DetailedMessage()
char const* TooManyAuthedGroupsException::what() const noexcept
{
return "Loaded fastfile has too many authed groups.";
}
}

View File

@ -1,5 +1,5 @@
#include "UnexpectedEndOfFileException.h"
UnexpectedEndOfFileException::UnexpectedEndOfFileException() = default;
std::string UnexpectedEndOfFileException::DetailedMessage()
@ -10,4 +10,4 @@ std::string UnexpectedEndOfFileException::DetailedMessage()
char const* UnexpectedEndOfFileException::what() const noexcept
{
return "Unexpected end of file";
}
}

View File

@ -13,4 +13,4 @@ std::string UnsupportedAssetTypeException::DetailedMessage()
char const* UnsupportedAssetTypeException::what() const noexcept
{
return "Zone has unsupported asset type.";
}
}

View File

@ -1,7 +1,7 @@
#pragma once
#include "Zone/Zone.h"
#include "Zone/Stream/IZoneInputStream.h"
#include "Zone/Zone.h"
class IContentLoadingEntryPoint
{
@ -9,4 +9,4 @@ public:
virtual ~IContentLoadingEntryPoint() = default;
virtual void Load(Zone* zone, IZoneInputStream* stream) = 0;
};
};

View File

@ -1,7 +1,7 @@
#pragma once
#include "Loading/ZoneLoader.h"
#include "ILoadingStream.h"
#include "Loading/ZoneLoader.h"
class ZoneLoader;

View File

@ -1,7 +1,7 @@
#pragma once
#include <cstdint>
#include <cstddef>
#include <cstdint>
class ILoadingStream
{
@ -10,4 +10,4 @@ public:
virtual size_t Load(void* buffer, size_t length) = 0;
virtual int64_t Pos() = 0;
};
};

View File

@ -14,4 +14,4 @@ public:
IZoneLoaderFactory& operator=(IZoneLoaderFactory&& other) noexcept = default;
virtual ZoneLoader* CreateLoaderForHeader(ZoneHeader& header, std::string& fileName) = 0;
};
};

View File

@ -14,4 +14,4 @@ size_t LoadingFileStream::Load(void* buffer, const size_t length)
int64_t LoadingFileStream::Pos()
{
return m_stream.tellg();
}
}

View File

@ -1,8 +1,8 @@
#pragma once
#include <istream>
#include "ILoadingStream.h"
#include <istream>
class LoadingFileStream final : public ILoadingStream
{
std::istream& m_stream;

View File

@ -1,14 +1,14 @@
#include "ProcessorAuthedBlocks.h"
#include <cassert>
#include <memory>
#include <cstring>
#include "Game/IW4/IW4.h"
#include "Loading/Exception/InvalidHashException.h"
#include "Loading/Exception/TooManyAuthedGroupsException.h"
#include "Loading/Exception/UnexpectedEndOfFileException.h"
#include <cassert>
#include <cstring>
#include <memory>
class ProcessorAuthedBlocks::Impl
{
ProcessorAuthedBlocks* const m_base;
@ -30,7 +30,9 @@ class ProcessorAuthedBlocks::Impl
size_t m_current_chunk_size;
public:
Impl(ProcessorAuthedBlocks* base, const unsigned authedChunkCount, const size_t chunkSize,
Impl(ProcessorAuthedBlocks* base,
const unsigned authedChunkCount,
const size_t chunkSize,
const unsigned maxMasterBlockCount,
std::unique_ptr<IHashFunction> hashFunction,
IHashProvider* masterBlockHashProvider)
@ -76,8 +78,7 @@ public:
m_master_block_hash_provider->GetHash(m_current_group - 1, &masterBlockHash, &masterBlockHashSize);
if (masterBlockHashSize != m_hash_function->GetHashSize()
|| std::memcmp(m_current_chunk_hash_buffer.get(), masterBlockHash,
m_hash_function->GetHashSize()) != 0)
|| std::memcmp(m_current_chunk_hash_buffer.get(), masterBlockHash, m_hash_function->GetHashSize()) != 0)
throw InvalidHashException();
memcpy(m_chunk_hashes_buffer.get(), m_chunk_buffer.get(), m_authed_chunk_count * m_hash_function->GetHashSize());
@ -88,7 +89,8 @@ public:
{
if (std::memcmp(m_current_chunk_hash_buffer.get(),
&m_chunk_hashes_buffer[(m_current_chunk_in_group - 1) * m_hash_function->GetHashSize()],
m_hash_function->GetHashSize()) != 0)
m_hash_function->GetHashSize())
!= 0)
throw InvalidHashException();
if (++m_current_chunk_in_group > m_authed_chunk_count)
@ -136,12 +138,12 @@ public:
}
};
ProcessorAuthedBlocks::ProcessorAuthedBlocks(const unsigned authedChunkCount, const size_t chunkSize,
ProcessorAuthedBlocks::ProcessorAuthedBlocks(const unsigned authedChunkCount,
const size_t chunkSize,
const unsigned maxMasterBlockCount,
std::unique_ptr<IHashFunction> hashFunction,
IHashProvider* masterBlockHashProvider)
: m_impl(new Impl(this, authedChunkCount, chunkSize, maxMasterBlockCount, std::move(hashFunction),
masterBlockHashProvider))
: m_impl(new Impl(this, authedChunkCount, chunkSize, maxMasterBlockCount, std::move(hashFunction), masterBlockHashProvider))
{
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <memory>
#include "Crypto.h"
#include "Loading/StreamProcessor.h"
#include "Loading/IHashProvider.h"
#include "Loading/StreamProcessor.h"
#include <memory>
class ProcessorAuthedBlocks final : public StreamProcessor
{
@ -11,8 +11,11 @@ class ProcessorAuthedBlocks final : public StreamProcessor
Impl* m_impl;
public:
ProcessorAuthedBlocks(unsigned authedChunkCount, size_t chunkSize, unsigned maxMasterBlockCount,
std::unique_ptr<IHashFunction> hashFunction, IHashProvider* masterBlockHashProvider);
ProcessorAuthedBlocks(unsigned authedChunkCount,
size_t chunkSize,
unsigned maxMasterBlockCount,
std::unique_ptr<IHashFunction> hashFunction,
IHashProvider* masterBlockHashProvider);
~ProcessorAuthedBlocks() override;
ProcessorAuthedBlocks(const ProcessorAuthedBlocks& other) = delete;
ProcessorAuthedBlocks(ProcessorAuthedBlocks&& other) noexcept = default;

View File

@ -10,8 +10,7 @@ ProcessorCaptureData::ProcessorCaptureData(const size_t captureSize)
{
}
ProcessorCaptureData::~ProcessorCaptureData()
= default;
ProcessorCaptureData::~ProcessorCaptureData() = default;
size_t ProcessorCaptureData::Load(void* buffer, const size_t length)
{
@ -29,7 +28,7 @@ size_t ProcessorCaptureData::Load(void* buffer, const size_t length)
m_captured_data_size += loadedSize;
if(length > dataToCapture)
if (length > dataToCapture)
loadedSize += m_base_stream->Load(&static_cast<uint8_t*>(buffer)[dataToCapture], length - dataToCapture);
return loadedSize;

View File

@ -1,9 +1,9 @@
#pragma once
#include <memory>
#include "Loading/StreamProcessor.h"
#include "Utils/ICapturedDataProvider.h"
#include <memory>
class ProcessorCaptureData final : public StreamProcessor, public ICapturedDataProvider
{
std::unique_ptr<uint8_t[]> m_data;

View File

@ -24,7 +24,7 @@ size_t ProcessorIW4xDecryption::Load(void* buffer, const size_t length)
const auto readLen = m_base_stream->Load(buffer, length);
auto* charBuffer = static_cast<uint8_t*>(buffer);
for(auto i = 0u; i < readLen; i++)
for (auto i = 0u; i < readLen; i++)
{
auto value = charBuffer[i];
value ^= m_last_byte;

View File

@ -1,13 +1,13 @@
#include "ProcessorInflate.h"
#include <stdexcept>
#include "Loading/Exception/InvalidCompressionException.h"
#include <cstdint>
#include <memory>
#include <stdexcept>
#include <zlib.h>
#include <zutil.h>
#include "Loading/Exception/InvalidCompressionException.h"
class ProcessorInflate::Impl
{
z_stream m_stream{};
@ -65,7 +65,7 @@ public:
auto ret = inflate(&m_stream, Z_SYNC_FLUSH);
if(ret < 0)
if (ret < 0)
throw InvalidCompressionException();
}

View File

@ -11,18 +11,17 @@ ProcessorStreamCipher::~ProcessorStreamCipher()
m_cipher = nullptr;
}
size_t ProcessorStreamCipher::Load(void* buffer, const size_t length)
{
if(m_base_stream != nullptr)
if (m_base_stream != nullptr)
{
const size_t readSize = m_base_stream->Load(buffer, length);
if(readSize > 0)
if (readSize > 0)
m_cipher->Process(buffer, buffer, readSize);
return readSize;
}
return 0;
}
}

View File

@ -1,6 +1,6 @@
#pragma once
#include "Loading/StreamProcessor.h"
#include "Crypto.h"
#include "Loading/StreamProcessor.h"
class ProcessorStreamCipher final : public StreamProcessor
{

View File

@ -1,14 +1,15 @@
#include "ProcessorXChunks.h"
#include "Zone/ZoneTypes.h"
#include "Loading/Exception/InvalidChunkSizeException.h"
#include <vector>
#include <thread>
#include <mutex>
#include <condition_variable>
#include "Loading/Exception/InvalidChunkSizeException.h"
#include "Zone/ZoneTypes.h"
#include <cassert>
#include <condition_variable>
#include <cstring>
#include <memory>
#include <mutex>
#include <thread>
#include <vector>
class DBLoadStream
{
@ -59,15 +60,15 @@ class DBLoadStream
}
public:
DBLoadStream(const int streamIndex, const size_t chunkSize,
std::vector<std::unique_ptr<IXChunkProcessor>>& chunkProcessors) : m_processors(chunkProcessors)
DBLoadStream(const int streamIndex, const size_t chunkSize, std::vector<std::unique_ptr<IXChunkProcessor>>& chunkProcessors)
: m_processors(chunkProcessors)
{
m_index = streamIndex;
m_chunk_size = chunkSize;
for(auto& buffer : m_buffers)
for (auto& buffer : m_buffers)
buffer = std::make_unique<uint8_t[]>(chunkSize);
m_input_buffer = m_buffers[0].get();
m_output_buffer = m_buffers[1].get();
@ -246,8 +247,8 @@ public:
m_eof_stream = 0;
}
ProcessorXChunksImpl(ProcessorXChunks* base, const int numStreams, const size_t xChunkSize,
const size_t vanillaBufferSize) : ProcessorXChunksImpl(base, numStreams, xChunkSize)
ProcessorXChunksImpl(ProcessorXChunks* base, const int numStreams, const size_t xChunkSize, const size_t vanillaBufferSize)
: ProcessorXChunksImpl(base, numStreams, xChunkSize)
{
m_vanilla_buffer_size = vanillaBufferSize;
}
@ -334,4 +335,4 @@ size_t ProcessorXChunks::Load(void* buffer, const size_t length)
int64_t ProcessorXChunks::Pos()
{
return m_impl->Pos();
}
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <memory>
#include "Loading/StreamProcessor.h"
#include "Zone/XChunk/IXChunkProcessor.h"
#include <memory>
class ProcessorXChunks : public StreamProcessor
{
class ProcessorXChunksImpl;

View File

@ -1,4 +1,5 @@
#include "StepAddProcessor.h"
#include <cassert>
StepAddProcessor::StepAddProcessor(std::unique_ptr<StreamProcessor> streamProcessor)
@ -13,4 +14,4 @@ void StepAddProcessor::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* strea
zoneLoader->AddStreamProcessor(std::move(m_stream_processor));
m_stream_processor = nullptr;
}
}

View File

@ -1,9 +1,9 @@
#pragma once
#include <memory>
#include "Loading/ILoadingStep.h"
#include <memory>
class StepAddProcessor final : public ILoadingStep
{
std::unique_ptr<StreamProcessor> m_stream_processor;

View File

@ -1,4 +1,5 @@
#include "StepAllocXBlocks.h"
#include "Loading/Exception/InvalidXBlockSizeException.h"
const uint64_t StepAllocXBlocks::MAX_XBLOCK_SIZE = 0x3C000000;
@ -11,20 +12,20 @@ void StepAllocXBlocks::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* strea
stream->Load(blockSizes, sizeof(xblock_size_t) * blockCount);
uint64_t totalMemory = 0;
for(unsigned int block = 0; block < blockCount; block++)
for (unsigned int block = 0; block < blockCount; block++)
{
totalMemory += blockSizes[block];
}
if(totalMemory > MAX_XBLOCK_SIZE)
if (totalMemory > MAX_XBLOCK_SIZE)
{
throw InvalidXBlockSizeException(totalMemory, MAX_XBLOCK_SIZE);
}
for(unsigned int block = 0; block < blockCount; block++)
for (unsigned int block = 0; block < blockCount; block++)
{
zoneLoader->m_blocks[block]->Alloc(blockSizes[block]);
}
delete[] blockSizes;
}
}

View File

@ -37,4 +37,4 @@ void StepDumpData::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
}
tempFile.close();
}
}

View File

@ -10,4 +10,4 @@ public:
explicit StepDumpData(unsigned int dumpCount);
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
};
};

View File

@ -1,5 +1,7 @@
#include "StepLoadHash.h"
#include "Loading/Exception/UnexpectedEndOfFileException.h"
#include <cassert>
StepLoadHash::StepLoadHash(const size_t hashSize, const unsigned hashCount)
@ -9,8 +11,7 @@ StepLoadHash::StepLoadHash(const size_t hashSize, const unsigned hashCount)
{
}
StepLoadHash::~StepLoadHash()
= default;
StepLoadHash::~StepLoadHash() = default;
void StepLoadHash::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
{
@ -36,7 +37,7 @@ void StepLoadHash::GetCapturedData(const uint8_t** pCapturedData, size_t* pSize)
{
assert(pCapturedData != nullptr);
assert(pSize != nullptr);
*pCapturedData = m_hashes.get();
*pSize = m_hash_size * m_hash_count;
}

View File

@ -1,10 +1,10 @@
#pragma once
#include <memory>
#include "Utils/ICapturedDataProvider.h"
#include "Loading/ILoadingStep.h"
#include "Loading/IHashProvider.h"
#include "Loading/ILoadingStep.h"
#include "Utils/ICapturedDataProvider.h"
#include <memory>
class StepLoadHash final : public ILoadingStep, public IHashProvider, public ICapturedDataProvider
{

View File

@ -1,5 +1,7 @@
#include "StepLoadSignature.h"
#include "Loading/Exception/UnexpectedEndOfFileException.h"
#include <cassert>
StepLoadSignature::StepLoadSignature(const size_t signatureSize)
@ -17,8 +19,8 @@ StepLoadSignature::~StepLoadSignature()
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, m_signature_size) != m_signature_size)
throw UnexpectedEndOfFileException();
}
@ -31,4 +33,4 @@ void StepLoadSignature::GetSignature(const uint8_t** pSignature, size_t* pSize)
*pSignature = m_signature;
*pSize = m_signature_size;
}
}

View File

@ -1,8 +1,13 @@
#include "StepLoadZoneContent.h"
#include "Zone/Stream/Impl/XBlockInputStream.h"
#include <cassert>
StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint, Zone* zone, const int offsetBlockBitCount, const block_t insertBlock)
StepLoadZoneContent::StepLoadZoneContent(std::unique_ptr<IContentLoadingEntryPoint> entryPoint,
Zone* zone,
const int offsetBlockBitCount,
const block_t insertBlock)
: m_content_loader(std::move(entryPoint)),
m_zone(zone),
m_offset_block_bit_count(offsetBlockBitCount),

View File

@ -1,9 +1,9 @@
#pragma once
#include <memory>
#include "Loading/ILoadingStep.h"
#include "Loading/IContentLoadingEntryPoint.h"
#include "Loading/ILoadingStep.h"
#include <memory>
class StepLoadZoneContent final : public ILoadingStep
{

View File

@ -1,9 +1,9 @@
#pragma once
#include <cstddef>
#include "Utils/ClassUtils.h"
#include "Loading/ILoadingStep.h"
#include "Utils/ClassUtils.h"
#include <cstddef>
class StepLoadZoneSizes final : public ILoadingStep
{

View File

@ -1,4 +1,5 @@
#include "StepRemoveProcessor.h"
#include <cassert>
StepRemoveProcessor::StepRemoveProcessor(StreamProcessor* streamProcessor)

View File

@ -10,11 +10,11 @@ void StepSkipBytes::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
uint8_t tempBuffer[128];
unsigned int skippedBytes = 0;
while(skippedBytes < m_skip_count)
while (skippedBytes < m_skip_count)
{
unsigned int toSkip;
if(m_skip_count - skippedBytes < sizeof(tempBuffer))
if (m_skip_count - skippedBytes < sizeof(tempBuffer))
{
toSkip = m_skip_count - skippedBytes;
}
@ -27,4 +27,4 @@ void StepSkipBytes::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
skippedBytes += toSkip;
}
}
}

View File

@ -10,4 +10,4 @@ public:
explicit StepSkipBytes(unsigned int skipCount);
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
};
};

View File

@ -1,15 +1,15 @@
#include "StepVerifyFileName.h"
#include <sstream>
#include "Loading/Exception/InvalidFileNameException.h"
#include <sstream>
StepVerifyFileName::StepVerifyFileName(std::string fileName, const size_t fileNameBufferSize)
{
m_file_name = std::move(fileName);
m_file_name_buffer_size = fileNameBufferSize;
if(m_file_name.length() > m_file_name_buffer_size)
if (m_file_name.length() > m_file_name_buffer_size)
m_file_name.erase(m_file_name_buffer_size);
}
@ -19,12 +19,12 @@ void StepVerifyFileName::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* str
unsigned bufferOffset = 0;
char c;
for(; bufferOffset < m_file_name_buffer_size; bufferOffset++)
for (; bufferOffset < m_file_name_buffer_size; bufferOffset++)
{
stream->Load(&c, sizeof(char));
if(c == '\00')
if (c == '\00')
{
bufferOffset++;
break;
@ -34,7 +34,7 @@ void StepVerifyFileName::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* str
}
// Skip the rest of the buffer which should be null bytes
while(bufferOffset < m_file_name_buffer_size)
while (bufferOffset < m_file_name_buffer_size)
{
stream->Load(&c, sizeof(char));
bufferOffset++;
@ -42,6 +42,6 @@ void StepVerifyFileName::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* str
std::string originalFileName = originalFilenameStream.str();
if(originalFileName != m_file_name)
if (originalFileName != m_file_name)
throw InvalidFileNameException(m_file_name, originalFileName);
}
}

View File

@ -11,4 +11,4 @@ public:
explicit StepVerifyFileName(std::string fileName, size_t fileNameBufferSize);
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
};
};

View File

@ -1,12 +1,14 @@
#include "StepVerifyHash.h"
#include <memory>
#include <cstring>
#include "Loading/Exception/InvalidHashException.h"
StepVerifyHash::StepVerifyHash(std::unique_ptr<IHashFunction> hashFunction, const unsigned hashIndex, IHashProvider* hashProvider,
ICapturedDataProvider* dataProvider)
#include <cstring>
#include <memory>
StepVerifyHash::StepVerifyHash(std::unique_ptr<IHashFunction> hashFunction,
const unsigned hashIndex,
IHashProvider* hashProvider,
ICapturedDataProvider* dataProvider)
: m_hash_function(std::move(hashFunction)),
m_hash_index(hashIndex),
m_hash_provider(hashProvider),
@ -14,8 +16,7 @@ StepVerifyHash::StepVerifyHash(std::unique_ptr<IHashFunction> hashFunction, cons
{
}
StepVerifyHash::~StepVerifyHash()
= default;
StepVerifyHash::~StepVerifyHash() = default;
void StepVerifyHash::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
{
@ -35,6 +36,6 @@ void StepVerifyHash::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream)
m_hash_function->Process(dataToHash, dataToHashSize);
m_hash_function->Finish(hashMemory.get());
if(std::memcmp(hashData, hashMemory.get(), m_hash_function->GetHashSize()) != 0)
if (std::memcmp(hashData, hashMemory.get(), m_hash_function->GetHashSize()) != 0)
throw InvalidHashException();
}

View File

@ -1,11 +1,11 @@
#pragma once
#include <memory>
#include "Crypto.h"
#include "Loading/IHashProvider.h"
#include "Loading/ILoadingStep.h"
#include "Utils/ICapturedDataProvider.h"
#include "Loading/IHashProvider.h"
#include <memory>
class StepVerifyHash final : public ILoadingStep
{

View File

@ -1,9 +1,9 @@
#include "StepVerifyMagic.h"
#include <cstring>
#include "Loading/Exception/InvalidMagicException.h"
#include <cstring>
StepVerifyMagic::StepVerifyMagic(const char* magic)
{
m_magic = magic;
@ -14,11 +14,11 @@ void StepVerifyMagic::PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream
{
char currentCharacter;
for(unsigned i = 0; i < m_magic_len; i++)
for (unsigned i = 0; i < m_magic_len; i++)
{
stream->Load(&currentCharacter, sizeof(char));
if(currentCharacter != m_magic[i])
if (currentCharacter != m_magic[i])
throw InvalidMagicException(m_magic);
}
}
}

View File

@ -11,4 +11,4 @@ public:
explicit StepVerifyMagic(const char* magic);
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
};
};

View File

@ -1,8 +1,12 @@
#include "StepVerifySignature.h"
#include "Loading/Exception/InvalidSignatureException.h"
#include <cassert>
StepVerifySignature::StepVerifySignature(std::unique_ptr<IPublicKeyAlgorithm> signatureAlgorithm, ISignatureProvider* signatureProvider, ICapturedDataProvider* signatureDataProvider)
StepVerifySignature::StepVerifySignature(std::unique_ptr<IPublicKeyAlgorithm> signatureAlgorithm,
ISignatureProvider* signatureProvider,
ICapturedDataProvider* signatureDataProvider)
: m_algorithm(std::move(signatureAlgorithm)),
m_signature_provider(signatureProvider),
m_signature_data_provider(signatureDataProvider)

View File

@ -1,7 +1,7 @@
#pragma once
#include "Loading/ILoadingStep.h"
#include "Crypto.h"
#include "Loading/ILoadingStep.h"
#include "Loading/ISignatureProvider.h"
#include "Utils/ICapturedDataProvider.h"
@ -12,7 +12,9 @@ class StepVerifySignature final : public ILoadingStep
ICapturedDataProvider* m_signature_data_provider;
public:
StepVerifySignature(std::unique_ptr<IPublicKeyAlgorithm> signatureAlgorithm, ISignatureProvider* signatureProvider, ICapturedDataProvider* signatureDataProvider);
StepVerifySignature(std::unique_ptr<IPublicKeyAlgorithm> signatureAlgorithm,
ISignatureProvider* signatureProvider,
ICapturedDataProvider* signatureDataProvider);
~StepVerifySignature() override = default;
StepVerifySignature(const StepVerifySignature& other) = delete;
StepVerifySignature(StepVerifySignature&& other) noexcept = default;
@ -20,4 +22,4 @@ public:
StepVerifySignature& operator=(StepVerifySignature&& other) noexcept = default;
void PerformStep(ZoneLoader* zoneLoader, ILoadingStream* stream) override;
};
};

View File

@ -8,4 +8,4 @@ StreamProcessor::StreamProcessor()
void StreamProcessor::SetBaseStream(ILoadingStream* baseStream)
{
m_base_stream = baseStream;
}
}

View File

@ -1,10 +1,10 @@
#include "ZoneLoader.h"
#include <algorithm>
#include "Exception/LoadingException.h"
#include "LoadingFileStream.h"
#include <algorithm>
ZoneLoader::ZoneLoader(std::unique_ptr<Zone> zone)
: m_processor_chain_dirty(false),
m_zone(std::move(zone))
@ -30,10 +30,12 @@ void ZoneLoader::AddXBlock(std::unique_ptr<XBlock> block)
{
m_blocks.push_back(block.get());
std::sort(m_blocks.begin(), m_blocks.end(), [](XBlock* b1, XBlock* b2) -> bool
{
return b1->m_index < b2->m_index;
});
std::sort(m_blocks.begin(),
m_blocks.end(),
[](XBlock* b1, XBlock* b2) -> bool
{
return b1->m_index < b2->m_index;
});
m_zone->GetMemory()->AddBlock(std::move(block));
}

View File

@ -1,13 +1,13 @@
#pragma once
#include "ILoadingStep.h"
#include "Zone/Zone.h"
#include "Zone/XBlock.h"
#include "StreamProcessor.h"
#include "Zone/XBlock.h"
#include "Zone/Zone.h"
#include <vector>
#include <istream>
#include <memory>
#include <vector>
class ILoadingStep;