2
0
mirror of https://github.com/Laupetin/OpenAssetTools.git synced 2026-05-16 23:11:42 +00:00

chore: reorder methods of ipak entry read stream

This commit is contained in:
Jan Laupetin
2026-05-11 22:16:56 +02:00
parent 36b4ec7781
commit b2c271956a
2 changed files with 39 additions and 38 deletions
@@ -7,6 +7,7 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <minilzo.h> #include <minilzo.h>
#include <utility>
using namespace ipak_consts; using namespace ipak_consts;
@@ -134,7 +135,7 @@ bool IPakEntryReadStream::ValidateBlockHeader(const IPakDataBlockHeader* blockHe
} }
// We expect the current file to be continued where we left off // We expect the current file to be continued where we left off
if (static_cast<int64_t>(blockHeader->countAndOffset.offset) != m_file_head) if (std::cmp_not_equal(blockHeader->countAndOffset.offset, m_file_head))
{ {
// A matching offset is only relevant if a command contains data // A matching offset is only relevant if a command contains data
for (unsigned currentCommand = 0; currentCommand < blockHeader->countAndOffset.count; currentCommand++) for (unsigned currentCommand = 0; currentCommand < blockHeader->countAndOffset.count; currentCommand++)
@@ -191,8 +192,7 @@ bool IPakEntryReadStream::NextBlock()
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 = std::min(estimatedChunksToRead, IPAK_CHUNK_COUNT_PER_READ);
estimatedChunksToRead = IPAK_CHUNK_COUNT_PER_READ;
if (!SetChunkBufferWindow(chunkStartPos, estimatedChunksToRead)) if (!SetChunkBufferWindow(chunkStartPos, estimatedChunksToRead))
return false; return false;
@@ -324,7 +324,7 @@ std::streambuf::int_type IPakEntryReadStream::uflow()
return EOF; return EOF;
} }
std::streamsize IPakEntryReadStream::xsgetn(char* ptr, const std::streamsize count) std::streamsize IPakEntryReadStream::xsgetn(char* ptr, std::streamsize count)
{ {
auto* destBuffer = reinterpret_cast<uint8_t*>(ptr); auto* destBuffer = reinterpret_cast<uint8_t*>(ptr);
std::streamsize countRead = 0; std::streamsize countRead = 0;
@@ -8,31 +8,22 @@
class IPakEntryReadStream final : public objbuf class IPakEntryReadStream final : public objbuf
{ {
static constexpr size_t IPAK_DECOMPRESS_BUFFER_SIZE = 0x8000; public:
IPakEntryReadStream(std::istream& stream, IPakStreamManagerActions* streamManagerActions, uint8_t* chunkBuffer, int64_t startOffset, size_t entrySize);
~IPakEntryReadStream() override;
uint8_t* m_chunk_buffer; [[nodiscard]] bool is_open() const override;
bool close() override;
std::istream& m_stream; protected:
IPakStreamManagerActions* m_stream_manager_actions; std::streamsize showmanyc() override;
int_type underflow() override;
int64_t m_file_offset; int_type uflow() override;
int64_t m_file_head; std::streamsize xsgetn(char* ptr, std::streamsize count) override;
pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode mode) override;
size_t m_entry_size; pos_type seekpos(pos_type pos, std::ios_base::openmode mode) override;
uint8_t m_decompress_buffer[IPAK_DECOMPRESS_BUFFER_SIZE];
IPakDataBlockHeader* m_current_block;
unsigned m_next_command;
uint8_t* m_current_command_buffer;
size_t m_current_command_length;
size_t m_current_command_offset;
int64_t m_pos;
int64_t m_base_pos;
int64_t m_end_pos;
int64_t m_buffer_start_pos;
int64_t m_buffer_end_pos;
private:
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; return (num + alignTo - 1) / alignTo * alignTo;
@@ -95,18 +86,28 @@ class IPakEntryReadStream final : public objbuf
*/ */
bool AdvanceStream(); bool AdvanceStream();
public: static constexpr size_t IPAK_DECOMPRESS_BUFFER_SIZE = 0x8000;
IPakEntryReadStream(std::istream& stream, IPakStreamManagerActions* streamManagerActions, uint8_t* chunkBuffer, int64_t startOffset, size_t entrySize);
~IPakEntryReadStream() override;
[[nodiscard]] bool is_open() const override; uint8_t* m_chunk_buffer;
bool close() override;
protected: std::istream& m_stream;
std::streamsize showmanyc() override; IPakStreamManagerActions* m_stream_manager_actions;
int_type underflow() override;
int_type uflow() override; int64_t m_file_offset;
std::streamsize xsgetn(char* ptr, std::streamsize count) override; int64_t m_file_head;
pos_type seekoff(off_type off, std::ios_base::seekdir dir, std::ios_base::openmode mode) override;
pos_type seekpos(pos_type pos, std::ios_base::openmode mode) override; size_t m_entry_size;
uint8_t m_decompress_buffer[IPAK_DECOMPRESS_BUFFER_SIZE];
IPakDataBlockHeader* m_current_block;
unsigned m_next_command;
uint8_t* m_current_command_buffer;
size_t m_current_command_length;
size_t m_current_command_offset;
int64_t m_pos;
int64_t m_base_pos;
int64_t m_end_pos;
int64_t m_buffer_start_pos;
int64_t m_buffer_end_pos;
}; };