Merge branch 'Fix-BA2GNRLFile-GetFile' into 'master'

Fix BA2 general reading file

See merge request OpenMW/openmw!3365
macos_ci_fix
psi29a 1 year ago
commit c5789b5543

@ -202,23 +202,21 @@ namespace Bsa
Files::IStreamPtr BA2GNRLFile::getFile(const FileRecord& fileRecord) Files::IStreamPtr BA2GNRLFile::getFile(const FileRecord& fileRecord)
{ {
Files::IStreamPtr streamPtr const uint32_t inputSize = fileRecord.packedSize ? fileRecord.packedSize : fileRecord.size;
= Files::openConstrainedFileStream(mFilepath, fileRecord.offset, fileRecord.packedSize); Files::IStreamPtr streamPtr = Files::openConstrainedFileStream(mFilepath, fileRecord.offset, inputSize);
std::istream* fileStream = streamPtr.get(); auto memoryStreamPtr = std::make_unique<MemoryInputStream>(fileRecord.size);
uint32_t uncompressedSize = fileRecord.size; if (fileRecord.packedSize)
auto memoryStreamPtr = std::make_unique<MemoryInputStream>(uncompressedSize);
if (fileRecord.packedSize != 0)
{ {
boost::iostreams::filtering_streambuf<boost::iostreams::input> inputStreamBuf; boost::iostreams::filtering_streambuf<boost::iostreams::input> inputStreamBuf;
inputStreamBuf.push(boost::iostreams::zlib_decompressor()); inputStreamBuf.push(boost::iostreams::zlib_decompressor());
inputStreamBuf.push(*fileStream); inputStreamBuf.push(*streamPtr);
boost::iostreams::basic_array_sink<char> sr(memoryStreamPtr->getRawData(), uncompressedSize); boost::iostreams::basic_array_sink<char> sr(memoryStreamPtr->getRawData(), fileRecord.size);
boost::iostreams::copy(inputStreamBuf, sr); boost::iostreams::copy(inputStreamBuf, sr);
} }
else else
{ {
fileStream->read(memoryStreamPtr->getRawData(), fileRecord.size); streamPtr->read(memoryStreamPtr->getRawData(), fileRecord.size);
} }
return std::make_unique<Files::StreamWithBuffer<MemoryInputStream>>(std::move(memoryStreamPtr)); return std::make_unique<Files::StreamWithBuffer<MemoryInputStream>>(std::move(memoryStreamPtr));
} }

Loading…
Cancel
Save