From df5857b5aff66e5b5c0fd1514a1b3a8a7b929d77 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 12 Feb 2015 20:30:11 -0800 Subject: [PATCH] DiscIO: On decompress to file, write last blocks. --- Source/Core/DiscIO/CompressedBlob.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Source/Core/DiscIO/CompressedBlob.cpp b/Source/Core/DiscIO/CompressedBlob.cpp index 74427c95a1..bd3a05806b 100644 --- a/Source/Core/DiscIO/CompressedBlob.cpp +++ b/Source/Core/DiscIO/CompressedBlob.cpp @@ -316,8 +316,9 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, const CompressedBlobHeader &header = reader->GetHeader(); static const size_t BUFFER_BLOCKS = 32; size_t buffer_size = header.block_size * BUFFER_BLOCKS; + size_t last_buffer_size = header.block_size * (header.num_blocks % BUFFER_BLOCKS); std::vector buffer(buffer_size); - u32 num_buffers = header.num_blocks / BUFFER_BLOCKS; + u32 num_buffers = (header.num_blocks + BUFFER_BLOCKS - 1) / BUFFER_BLOCKS; int progress_monitor = std::max(1, num_buffers / 100); bool was_cancelled = false; @@ -329,8 +330,9 @@ bool DecompressBlobToFile(const std::string& infile, const std::string& outfile, if (was_cancelled) break; } - reader->Read(i * buffer_size, buffer_size, buffer.data()); - f.WriteBytes(buffer.data(), buffer_size); + const size_t sz = i == num_buffers - 1 ? last_buffer_size : buffer_size; + reader->Read(i * buffer_size, sz, buffer.data()); + f.WriteBytes(buffer.data(), sz); } if (was_cancelled)