mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-28 23:02:07 +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
|
// Zip compression methods, extended by some internal types to be passed to OpenDecompressor
|
||||||
enum
|
enum ECompressionMethod
|
||||||
{
|
{
|
||||||
METHOD_STORED = 0,
|
METHOD_STORED = 0,
|
||||||
METHOD_SHRINK = 1,
|
METHOD_SHRINK = 1,
|
||||||
|
@ -96,6 +96,13 @@ enum
|
||||||
METHOD_TRANSFEROWNER = 0x8000,
|
METHOD_TRANSFEROWNER = 0x8000,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum EDecompressFlags
|
||||||
|
{
|
||||||
|
DCF_TRANSFEROWNER = 1,
|
||||||
|
DCF_SEEKABLE = 2,
|
||||||
|
DCF_EXCEPTIONS = 4
|
||||||
|
};
|
||||||
|
|
||||||
class FileReader;
|
class FileReader;
|
||||||
|
|
||||||
// an opaque memory buffer to the file's content. Can either own the memory or just point to an external buffer.
|
// 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(std::vector<uint8_t>& data); // take the given array
|
||||||
bool OpenMemoryArray(FileData& 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 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
|
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;
|
FileReaderInterface* fr = nullptr;
|
||||||
DecompressorBase* dec = nullptr;
|
DecompressorBase* dec = nullptr;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
FileReader* p = &parent;
|
FileReader* p = &parent;
|
||||||
switch (method & ~METHOD_TRANSFEROWNER)
|
bool exceptions = !!(flags & DCF_EXCEPTIONS);
|
||||||
|
|
||||||
|
switch (method)
|
||||||
{
|
{
|
||||||
case METHOD_DEFLATE:
|
case METHOD_DEFLATE:
|
||||||
case METHOD_ZLIB:
|
case METHOD_ZLIB:
|
||||||
|
@ -975,13 +977,13 @@ bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, b
|
||||||
}
|
}
|
||||||
if (dec)
|
if (dec)
|
||||||
{
|
{
|
||||||
if (method & METHOD_TRANSFEROWNER)
|
if (flags & DCF_TRANSFEROWNER)
|
||||||
{
|
{
|
||||||
dec->SetOwnsReader();
|
dec->SetOwnsReader();
|
||||||
}
|
}
|
||||||
dec->Length = length;
|
dec->Length = length;
|
||||||
}
|
}
|
||||||
if (!seekable)
|
if (!(flags & DCF_SEEKABLE))
|
||||||
{
|
{
|
||||||
Close();
|
Close();
|
||||||
mReader = fr;
|
mReader = fr;
|
||||||
|
@ -1003,16 +1005,17 @@ bool FileReader::OpenDecompressor(FileReader &parent, Size length, int method, b
|
||||||
|
|
||||||
bool FCompressedBuffer::Decompress(char* destbuffer)
|
bool FCompressedBuffer::Decompress(char* destbuffer)
|
||||||
{
|
{
|
||||||
FileReader mr;
|
|
||||||
mr.OpenMemory(mBuffer, mCompressedSize);
|
|
||||||
if (mMethod == METHOD_STORED)
|
if (mMethod == METHOD_STORED)
|
||||||
{
|
{
|
||||||
return mr.Read(destbuffer, mSize) != mSize;
|
memcpy(destbuffer, mBuffer, mSize);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
FileReader mr;
|
||||||
|
mr.OpenMemory(mBuffer, mCompressedSize);
|
||||||
FileReader frz;
|
FileReader frz;
|
||||||
if (frz.OpenDecompressor(mr, mSize, mMethod, false, false))
|
if (frz.OpenDecompressor(mr, mSize, mMethod))
|
||||||
{
|
{
|
||||||
return frz.Read(destbuffer, mSize) != mSize;
|
return frz.Read(destbuffer, mSize) != mSize;
|
||||||
}
|
}
|
||||||
|
|
|
@ -564,7 +564,7 @@ FileReader FResourceFile::GetEntryReader(uint32_t entry, bool newreader)
|
||||||
{
|
{
|
||||||
FileReader fri;
|
FileReader fri;
|
||||||
fri.OpenFilePart(Reader, Entries[entry].Position, Entries[entry].CompressedSize);
|
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;
|
return fr;
|
||||||
|
|
|
@ -738,7 +738,7 @@ bool MapLoader::LoadExtendedNodes (FileReader &dalump, uint32_t id)
|
||||||
if (compressed)
|
if (compressed)
|
||||||
{
|
{
|
||||||
FileReader zip;
|
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);
|
LoadZNodes(zip, type);
|
||||||
return true;
|
return true;
|
||||||
|
@ -3344,7 +3344,7 @@ void MapLoader::LoadLightmap(MapData *map)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FileReader fr;
|
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;
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue