take OpenDecompressor out of FileReader and fixed exploding decompression
This commit is contained in:
parent
6f8c3c60c4
commit
9bcbdfa09c
6 changed files with 79 additions and 71 deletions
62
src/common/filesystem/include/fs_decompress.h
Normal file
62
src/common/filesystem/include/fs_decompress.h
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
#pragma once
|
||||
#include "fs_files.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
// Zip compression methods, extended by some internal types to be passed to OpenDecompressor
|
||||
enum ECompressionMethod
|
||||
{
|
||||
METHOD_STORED = 0,
|
||||
METHOD_SHRINK = 1,
|
||||
METHOD_IMPLODE = 6,
|
||||
METHOD_DEFLATE = 8,
|
||||
METHOD_BZIP2 = 12,
|
||||
METHOD_LZMA = 14,
|
||||
METHOD_XZ = 95,
|
||||
METHOD_PPMD = 98,
|
||||
METHOD_LZSS = 1337, // not used in Zips - this is for Console Doom compression
|
||||
METHOD_ZLIB = 1338, // Zlib stream with header, used by compressed nodes.
|
||||
METHOD_RFFCRYPT = 1339, // not actual compression but can be put in here to make handling easier.
|
||||
METHOD_IMPLODE_MIN = 1000, // having discrete types for these avoids keeping around the GPFlags word in Zips.
|
||||
METHOD_IMPLODE_0 = 1000,
|
||||
METHOD_IMPLODE_2 = 1002,
|
||||
METHOD_IMPLODE_4 = 1004,
|
||||
METHOD_IMPLODE_6 = 1006,
|
||||
METHOD_IMPLODE_MAX = 1006,
|
||||
METHOD_INVALID = 0x7fff,
|
||||
METHOD_TRANSFEROWNER = 0x8000,
|
||||
};
|
||||
|
||||
enum EDecompressFlags
|
||||
{
|
||||
DCF_TRANSFEROWNER = 1,
|
||||
DCF_SEEKABLE = 2,
|
||||
DCF_EXCEPTIONS = 4
|
||||
};
|
||||
|
||||
bool OpenDecompressor(FileReader& self, FileReader &parent, FileReader::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.
|
||||
|
||||
// This holds a compresed Zip entry with all needed info to decompress it.
|
||||
struct FCompressedBuffer
|
||||
{
|
||||
size_t mSize;
|
||||
size_t mCompressedSize;
|
||||
int mMethod;
|
||||
unsigned mCRC32;
|
||||
char* mBuffer;
|
||||
const char* filename;
|
||||
|
||||
bool Decompress(char* destbuffer);
|
||||
void Clean()
|
||||
{
|
||||
mSize = mCompressedSize = 0;
|
||||
if (mBuffer != nullptr)
|
||||
{
|
||||
delete[] mBuffer;
|
||||
mBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -72,37 +72,6 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
// Zip compression methods, extended by some internal types to be passed to OpenDecompressor
|
||||
enum ECompressionMethod
|
||||
{
|
||||
METHOD_STORED = 0,
|
||||
METHOD_SHRINK = 1,
|
||||
METHOD_IMPLODE = 6,
|
||||
METHOD_DEFLATE = 8,
|
||||
METHOD_BZIP2 = 12,
|
||||
METHOD_LZMA = 14,
|
||||
METHOD_XZ = 95,
|
||||
METHOD_PPMD = 98,
|
||||
METHOD_LZSS = 1337, // not used in Zips - this is for Console Doom compression
|
||||
METHOD_ZLIB = 1338, // Zlib stream with header, used by compressed nodes.
|
||||
METHOD_RFFCRYPT = 1339, // not actual compression but can be put in here to make handling easier.
|
||||
METHOD_IMPLODE_MIN = 1000, // having discrete types for these avoids keeping around the GPFlags word in Zips.
|
||||
METHOD_IMPLODE_0 = 1000,
|
||||
METHOD_IMPLODE_2 = 1002,
|
||||
METHOD_IMPLODE_4 = 1004,
|
||||
METHOD_IMPLODE_6 = 1006,
|
||||
METHOD_IMPLODE_MAX = 1006,
|
||||
METHOD_INVALID = 0x7fff,
|
||||
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.
|
||||
|
|
@ -183,28 +152,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
// This holds a compresed Zip entry with all needed info to decompress it.
|
||||
struct FCompressedBuffer
|
||||
{
|
||||
size_t mSize;
|
||||
size_t mCompressedSize;
|
||||
int mMethod;
|
||||
unsigned mCRC32;
|
||||
char* mBuffer;
|
||||
const char* filename;
|
||||
|
||||
bool Decompress(char* destbuffer);
|
||||
void Clean()
|
||||
{
|
||||
mSize = mCompressedSize = 0;
|
||||
if (mBuffer != nullptr)
|
||||
{
|
||||
delete[] mBuffer;
|
||||
mBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class FileReaderInterface
|
||||
{
|
||||
|
|
@ -290,7 +237,6 @@ 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, 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
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include "fs_files.h"
|
||||
#include "fs_decompress.h"
|
||||
|
||||
namespace FileSys {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue