mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 05:21:16 +00:00
fixed OpenDecompressor flag handling.
This commit is contained in:
parent
e1cf8af9d3
commit
292705ddc3
4 changed files with 23 additions and 13 deletions
|
@ -73,7 +73,7 @@ public:
|
|||
};
|
||||
|
||||
// Zip compression methods, extended by some internal types to be passed to OpenDecompressor
|
||||
enum
|
||||
enum ECompressionMethod
|
||||
{
|
||||
METHOD_STORED = 0,
|
||||
METHOD_SHRINK = 1,
|
||||
|
@ -96,6 +96,13 @@ enum
|
|||
METHOD_TRANSFEROWNER = 0x8000,
|
||||
};
|
||||
|
||||
enum EDecompressFlags
|
||||
{
|
||||
DCF_TRANSFEROWNER = 1,
|
||||
DCF_SEEKABLE = 2,
|
||||
DCF_EXCEPTIONS = 4
|
||||
};
|
||||
|
||||
class FileReader;
|
||||
|
||||
// an opaque memory buffer to the file's content. Can either own the memory or just point to an external buffer.
|
||||
|
@ -283,7 +290,7 @@ public:
|
|||
bool OpenMemoryArray(std::vector<uint8_t>& data); // take the given array
|
||||
bool OpenMemoryArray(FileData& data); // take the given array
|
||||
bool OpenMemoryArray(std::function<bool(std::vector<uint8_t>&)> getter); // read contents to a buffer and return a reader to it
|
||||
bool OpenDecompressor(FileReader &parent, Size length, int method, bool seekable, bool exceptions = false); // creates a decompressor stream. 'seekable' uses a buffered version so that the Seek and Tell methods can be used.
|
||||
bool OpenDecompressor(FileReader &parent, Size length, int method, int flags = 0); // creates a decompressor stream. 'seekable' uses a buffered version so that the Seek and Tell methods can be used.
|
||||
|
||||
Size Tell() const
|
||||
{
|
||||
|
|
|
@ -848,14 +848,16 @@ public:
|
|||
};
|
||||
|
||||
|
||||
bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, bool seekable, bool exceptions)
|
||||
bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, int flags)
|
||||
{
|
||||
FileReaderInterface* fr = nullptr;
|
||||
DecompressorBase* dec = nullptr;
|
||||
try
|
||||
{
|
||||
FileReader* p = &parent;
|
||||
switch (method & ~METHOD_TRANSFEROWNER)
|
||||
bool exceptions = !!(flags & DCF_EXCEPTIONS);
|
||||
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_DEFLATE:
|
||||
case METHOD_ZLIB:
|
||||
|
@ -975,13 +977,13 @@ bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, b
|
|||
}
|
||||
if (dec)
|
||||
{
|
||||
if (method & METHOD_TRANSFEROWNER)
|
||||
if (flags & DCF_TRANSFEROWNER)
|
||||
{
|
||||
dec->SetOwnsReader();
|
||||
}
|
||||
dec->Length = length;
|
||||
}
|
||||
if (!seekable)
|
||||
if (!(flags & DCF_SEEKABLE))
|
||||
{
|
||||
Close();
|
||||
mReader = fr;
|
||||
|
@ -1003,16 +1005,17 @@ bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, b
|
|||
|
||||
bool FCompressedBuffer::Decompress(char* destbuffer)
|
||||
{
|
||||
FileReader mr;
|
||||
mr.OpenMemory(mBuffer, mCompressedSize);
|
||||
if (mMethod == METHOD_STORED)
|
||||
{
|
||||
return mr.Read(destbuffer, mSize) != mSize;
|
||||
memcpy(destbuffer, mBuffer, mSize);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
FileReader mr;
|
||||
mr.OpenMemory(mBuffer, mCompressedSize);
|
||||
FileReader frz;
|
||||
if (frz.OpenDecompressor(mr, mSize, mMethod, false, false))
|
||||
if (frz.OpenDecompressor(mr, mSize, mMethod))
|
||||
{
|
||||
return frz.Read(destbuffer, mSize) != mSize;
|
||||
}
|
||||
|
|
|
@ -564,7 +564,7 @@ FileReader FResourceFile::GetEntryReader(uint32_t entry, bool newreader)
|
|||
{
|
||||
FileReader fri;
|
||||
fri.OpenFilePart(Reader, Entries[entry].Position, Entries[entry].CompressedSize);
|
||||
fr.OpenDecompressor(fri, Entries[entry].Length, Entries[entry].Method | METHOD_TRANSFEROWNER, true, true);
|
||||
fr.OpenDecompressor(fri, Entries[entry].Length, Entries[entry].Method, FileSys::DCF_TRANSFEROWNER | FileSys::DCF_SEEKABLE | FileSys::DCF_EXCEPTIONS);
|
||||
}
|
||||
}
|
||||
return fr;
|
||||
|
|
|
@ -738,7 +738,7 @@ bool MapLoader::LoadExtendedNodes (FileReader &dalump, uint32_t id)
|
|||
if (compressed)
|
||||
{
|
||||
FileReader zip;
|
||||
if (zip.OpenDecompressor(dalump, -1, FileSys::METHOD_ZLIB, false, true))
|
||||
if (zip.OpenDecompressor(dalump, -1, FileSys::METHOD_ZLIB, FileSys::DCF_EXCEPTIONS))
|
||||
{
|
||||
LoadZNodes(zip, type);
|
||||
return true;
|
||||
|
@ -3344,7 +3344,7 @@ void MapLoader::LoadLightmap(MapData *map)
|
|||
return;
|
||||
|
||||
FileReader fr;
|
||||
if (!fr.OpenDecompressor(map->Reader(ML_LIGHTMAP), -1, FileSys::METHOD_ZLIB, false, false))
|
||||
if (!fr.OpenDecompressor(map->Reader(ML_LIGHTMAP), -1, FileSys::METHOD_ZLIB))
|
||||
return;
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue