mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-12-20 01:11:49 +00:00
Reformat code with clang format
This commit is contained in:
@@ -13,4 +13,4 @@ const std::string& IPakLoadException::DetailedMessage() const
|
||||
char const* IPakLoadException::what() const noexcept
|
||||
{
|
||||
return "There was an error when trying to load an ipak file.";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#include "IPak.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <filesystem>
|
||||
|
||||
#include "Exception/IPakLoadException.h"
|
||||
#include "IPakStreamManager.h"
|
||||
#include "ObjContainer/IPak/IPakTypes.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "zlib.h"
|
||||
|
||||
#include "Utils/FileUtils.h"
|
||||
#include "Exception/IPakLoadException.h"
|
||||
#include "ObjContainer/IPak/IPakTypes.h"
|
||||
#include "IPakStreamManager.h"
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -57,7 +56,8 @@ class IPak::Impl : public ObjContainerReferenceable
|
||||
m_index_entries.push_back(indexEntry);
|
||||
}
|
||||
|
||||
std::sort(m_index_entries.begin(), m_index_entries.end(),
|
||||
std::sort(m_index_entries.begin(),
|
||||
m_index_entries.end(),
|
||||
[](const IPakIndexEntry& entry1, const IPakIndexEntry& entry2)
|
||||
{
|
||||
return entry1.key.combinedKey < entry2.key.combinedKey;
|
||||
@@ -152,8 +152,7 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
~Impl() override
|
||||
= default;
|
||||
~Impl() override = default;
|
||||
|
||||
std::string GetName() override
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "ObjContainer/ObjContainerReferenceable.h"
|
||||
#include "ObjContainer/ObjContainerRepository.h"
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/ObjStream.h"
|
||||
#include "Zone/Zone.h"
|
||||
|
||||
#include <istream>
|
||||
|
||||
class IPak final : public ObjContainerReferenceable
|
||||
{
|
||||
class Impl;
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#include "IPakEntryReadStream.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
|
||||
#include <minilzo.h>
|
||||
|
||||
#include "ObjContainer/IPak/IPakTypes.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include <minilzo.h>
|
||||
|
||||
using namespace ipak_consts;
|
||||
|
||||
IPakEntryReadStream::IPakEntryReadStream(std::istream& stream, IPakStreamManagerActions* streamManagerActions,
|
||||
uint8_t* chunkBuffer, const int64_t startOffset, const size_t entrySize)
|
||||
IPakEntryReadStream::IPakEntryReadStream(
|
||||
std::istream& stream, IPakStreamManagerActions* streamManagerActions, uint8_t* chunkBuffer, const int64_t startOffset, const size_t entrySize)
|
||||
: m_chunk_buffer(chunkBuffer),
|
||||
m_stream(stream),
|
||||
m_stream_manager_actions(streamManagerActions),
|
||||
@@ -85,8 +84,8 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
|
||||
// Check whether we need to load additional data that was not previously loaded
|
||||
if (endPos > m_buffer_end_pos)
|
||||
{
|
||||
const auto readChunkCount = ReadChunks(&m_chunk_buffer[m_buffer_end_pos - startPos], m_buffer_end_pos,
|
||||
static_cast<size_t>(endPos - m_buffer_end_pos) / IPAK_CHUNK_SIZE);
|
||||
const auto readChunkCount =
|
||||
ReadChunks(&m_chunk_buffer[m_buffer_end_pos - startPos], m_buffer_end_pos, static_cast<size_t>(endPos - m_buffer_end_pos) / IPAK_CHUNK_SIZE);
|
||||
|
||||
m_buffer_end_pos += static_cast<int64_t>(readChunkCount) * IPAK_CHUNK_SIZE;
|
||||
|
||||
@@ -100,20 +99,18 @@ bool IPakEntryReadStream::SetChunkBufferWindow(const int64_t startPos, size_t ch
|
||||
// Check whether the end position is already part of the loaded data
|
||||
if (endPos > m_buffer_start_pos && endPos <= m_buffer_end_pos)
|
||||
{
|
||||
assert(IPAK_CHUNK_SIZE * IPAK_CHUNK_COUNT_PER_READ - static_cast<size_t>(m_buffer_start_pos - startPos) >= static_cast<size_t>(endPos - m_buffer_start_pos));
|
||||
assert(IPAK_CHUNK_SIZE * IPAK_CHUNK_COUNT_PER_READ - static_cast<size_t>(m_buffer_start_pos - startPos)
|
||||
>= static_cast<size_t>(endPos - m_buffer_start_pos));
|
||||
|
||||
// Move data to make sure the end is at the appropriate position to be able to load the missing data in the front
|
||||
memmove(&m_chunk_buffer[m_buffer_start_pos - startPos], m_chunk_buffer, static_cast<size_t>(endPos - m_buffer_start_pos));
|
||||
|
||||
// We already established that the start of the buffer is not already loaded so we will need to load additional data nonetheless
|
||||
const auto readChunkCount = ReadChunks(m_chunk_buffer,
|
||||
startPos,
|
||||
static_cast<size_t>(m_buffer_start_pos - startPos) / IPAK_CHUNK_SIZE);
|
||||
const auto readChunkCount = ReadChunks(m_chunk_buffer, startPos, static_cast<size_t>(m_buffer_start_pos - startPos) / IPAK_CHUNK_SIZE);
|
||||
|
||||
m_buffer_start_pos = startPos;
|
||||
m_buffer_end_pos = readChunkCount == (m_buffer_start_pos - startPos) / IPAK_CHUNK_SIZE
|
||||
? endPos
|
||||
: startPos + static_cast<int64_t>(readChunkCount) * IPAK_CHUNK_SIZE;
|
||||
m_buffer_end_pos =
|
||||
readChunkCount == (m_buffer_start_pos - startPos) / IPAK_CHUNK_SIZE ? endPos : startPos + static_cast<int64_t>(readChunkCount) * IPAK_CHUNK_SIZE;
|
||||
|
||||
return m_buffer_end_pos == endPos;
|
||||
}
|
||||
@@ -143,8 +140,7 @@ bool IPakEntryReadStream::ValidateBlockHeader(const IPakDataBlockHeader* blockHe
|
||||
{
|
||||
// If compressed is not 0 or 1 it will not be read and therefore it is okay when the offset does not match
|
||||
// The game uses IPAK_COMMAND_SKIP as value for compressed when it intends to skip the specified amount of data
|
||||
if (blockHeader->commands[currentCommand].compressed == 0
|
||||
|| blockHeader->commands[currentCommand].compressed == 1)
|
||||
if (blockHeader->commands[currentCommand].compressed == 0 || blockHeader->commands[currentCommand].compressed == 1)
|
||||
{
|
||||
std::cerr << "IPak block offset (" << blockHeader->countAndOffset.offset << ") is not the file head (" << m_file_head << ") -> Invalid\n";
|
||||
return false;
|
||||
@@ -192,8 +188,7 @@ bool IPakEntryReadStream::NextBlock()
|
||||
const auto chunkStartPos = AlignBackwards<int64_t>(m_pos, IPAK_CHUNK_SIZE);
|
||||
const auto blockOffsetInChunk = static_cast<size_t>(m_pos - chunkStartPos);
|
||||
|
||||
auto estimatedChunksToRead = AlignForward(m_entry_size - static_cast<size_t>(m_pos - m_base_pos), IPAK_CHUNK_SIZE)
|
||||
/ IPAK_CHUNK_SIZE;
|
||||
auto estimatedChunksToRead = AlignForward(m_entry_size - static_cast<size_t>(m_pos - m_base_pos), IPAK_CHUNK_SIZE) / IPAK_CHUNK_SIZE;
|
||||
|
||||
if (estimatedChunksToRead > IPAK_CHUNK_COUNT_PER_READ)
|
||||
estimatedChunksToRead = IPAK_CHUNK_COUNT_PER_READ;
|
||||
@@ -222,8 +217,7 @@ bool IPakEntryReadStream::ProcessCommand(const size_t commandSize, const int com
|
||||
if (compressed == 1)
|
||||
{
|
||||
lzo_uint outputSize = sizeof(m_decompress_buffer);
|
||||
const auto result = lzo1x_decompress_safe(&m_chunk_buffer[m_pos - m_buffer_start_pos], commandSize,
|
||||
m_decompress_buffer, &outputSize, nullptr);
|
||||
const auto result = lzo1x_decompress_safe(&m_chunk_buffer[m_pos - m_buffer_start_pos], commandSize, m_decompress_buffer, &outputSize, nullptr);
|
||||
|
||||
if (result != LZO_E_OK)
|
||||
{
|
||||
@@ -261,8 +255,7 @@ bool IPakEntryReadStream::AdvanceStream()
|
||||
return false;
|
||||
}
|
||||
|
||||
ProcessCommand(m_current_block->commands[m_next_command].size,
|
||||
m_current_block->commands[m_next_command].compressed);
|
||||
ProcessCommand(m_current_block->commands[m_next_command].size, m_current_block->commands[m_next_command].compressed);
|
||||
m_next_command++;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <istream>
|
||||
|
||||
#include "Utils/ObjStream.h"
|
||||
#include "IPakStreamManager.h"
|
||||
#include "ObjContainer/IPak/IPakTypes.h"
|
||||
#include "Utils/ObjStream.h"
|
||||
|
||||
#include <istream>
|
||||
|
||||
class IPakEntryReadStream final : public objbuf
|
||||
{
|
||||
@@ -33,14 +33,12 @@ class IPakEntryReadStream final : public objbuf
|
||||
int64_t m_buffer_start_pos;
|
||||
int64_t m_buffer_end_pos;
|
||||
|
||||
template <typename T>
|
||||
static T AlignForward(const T num, const T alignTo)
|
||||
template<typename T> static T AlignForward(const T num, const T alignTo)
|
||||
{
|
||||
return (num + alignTo - 1) / alignTo * alignTo;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static T AlignBackwards(const T num, const T alignTo)
|
||||
template<typename T> static T AlignBackwards(const T num, const T alignTo)
|
||||
{
|
||||
return num / alignTo * alignTo;
|
||||
}
|
||||
@@ -86,8 +84,8 @@ class IPakEntryReadStream final : public objbuf
|
||||
/**
|
||||
* \brief Processes a command with the specified parameters at the current position.
|
||||
* \param commandSize The size of the command data
|
||||
* \param compressed The compression value of the command. Can be \c 0 for uncompressed or \c 1 for lzo compression. Any other value skips the specified size of data.
|
||||
* \return \c true if the specified command could be correctly processed or \c otherwise.
|
||||
* \param compressed The compression value of the command. Can be \c 0 for uncompressed or \c 1 for lzo compression. Any other value skips the specified
|
||||
* size of data. \return \c true if the specified command could be correctly processed or \c otherwise.
|
||||
*/
|
||||
bool ProcessCommand(size_t commandSize, int compressed);
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "IPakStreamManager.h"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "IPakEntryReadStream.h"
|
||||
#include "ObjContainer/IPak/IPakTypes.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
using namespace ipak_consts;
|
||||
|
||||
class IPakStreamManager::Impl final : public IPakStreamManagerActions
|
||||
@@ -71,10 +71,12 @@ public:
|
||||
m_stream_mutex.lock();
|
||||
|
||||
ChunkBuffer* reservedChunkBuffer;
|
||||
const auto freeChunkBuffer = std::find_if(m_chunk_buffers.begin(), m_chunk_buffers.end(), [](ChunkBuffer* chunkBuffer)
|
||||
{
|
||||
return chunkBuffer->m_using_stream == nullptr;
|
||||
});
|
||||
const auto freeChunkBuffer = std::find_if(m_chunk_buffers.begin(),
|
||||
m_chunk_buffers.end(),
|
||||
[](ChunkBuffer* chunkBuffer)
|
||||
{
|
||||
return chunkBuffer->m_using_stream == nullptr;
|
||||
});
|
||||
|
||||
if (freeChunkBuffer == m_chunk_buffers.end())
|
||||
{
|
||||
@@ -109,10 +111,12 @@ public:
|
||||
{
|
||||
m_stream_mutex.lock();
|
||||
|
||||
const auto openStreamEntry = std::find_if(m_open_streams.begin(), m_open_streams.end(), [stream](const ManagedStream& managedStream)
|
||||
{
|
||||
return managedStream.m_stream == stream;
|
||||
});
|
||||
const auto openStreamEntry = std::find_if(m_open_streams.begin(),
|
||||
m_open_streams.end(),
|
||||
[stream](const ManagedStream& managedStream)
|
||||
{
|
||||
return managedStream.m_stream == stream;
|
||||
});
|
||||
|
||||
if (openStreamEntry != m_open_streams.end())
|
||||
{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <istream>
|
||||
|
||||
#include "Utils/ClassUtils.h"
|
||||
#include "Utils/ObjStream.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <istream>
|
||||
#include <mutex>
|
||||
|
||||
class IPakStreamManagerActions
|
||||
{
|
||||
public:
|
||||
@@ -31,4 +31,4 @@ public:
|
||||
IPakStreamManager& operator=(IPakStreamManager&& other) noexcept = delete;
|
||||
|
||||
_NODISCARD std::unique_ptr<iobjstream> OpenStream(int64_t startPosition, size_t length) const;
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user