- read snapshots from zip.

This commit is contained in:
Christoph Oelckers 2016-09-22 01:28:05 +02:00
commit 5dfc396bb9
12 changed files with 90 additions and 76 deletions

View file

@ -306,17 +306,12 @@ FZipFile::~FZipFile()
//
//==========================================================================
FCompressedBuffer FZipFile::GetRawLump(int lumpnum)
FCompressedBuffer FZipLump::GetRawData()
{
if ((unsigned)lumpnum >= NumLumps)
{
return{ 0,0,0,0,0,nullptr };
}
FZipLump *lmp = &Lumps[lumpnum];
FCompressedBuffer cbuf = { (unsigned)lmp->LumpSize, (unsigned)lmp->CompressedSize, lmp->Method, lmp->GPFlags, lmp->CRC32, new char[lmp->CompressedSize] };
Reader->Seek(lmp->Position, SEEK_SET);
Reader->Read(cbuf.mBuffer, lmp->CompressedSize);
FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)CompressedSize, Method, GPFlags, CRC32, new char[CompressedSize] };
if (Flags & LUMPFZIP_NEEDFILESTART) SetLumpAddress();
Owner->Reader->Seek(Position, SEEK_SET);
Owner->Reader->Read(cbuf.mBuffer, CompressedSize);
return cbuf;
}

View file

@ -3,28 +3,6 @@
#include "resourcefile.h"
// This holds a compresed Zip entry with all needed info to decompress it.
struct FCompressedBuffer
{
unsigned mSize;
unsigned mCompressedSize;
int mMethod;
int mZipFlags;
unsigned mCRC32;
char *mBuffer;
bool Decompress(char *destbuffer);
void Clean()
{
mSize = mCompressedSize = 0;
if (mBuffer != nullptr)
{
delete[] mBuffer;
mBuffer = nullptr;
}
}
};
enum
{
LUMPFZIP_NEEDFILESTART = 128
@ -50,6 +28,7 @@ struct FZipLump : public FResourceLump
private:
void SetLumpAddress();
virtual int GetFileOffset();
FCompressedBuffer GetRawData();
};
@ -68,7 +47,6 @@ public:
virtual ~FZipFile();
bool Open(bool quiet);
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
FCompressedBuffer GetRawLump(int lumpnum);
};

View file

@ -40,6 +40,7 @@
#include "doomerrors.h"
#include "gi.h"
#include "doomstat.h"
#include "w_zip.h"
//==========================================================================
@ -191,6 +192,23 @@ void FResourceLump::CheckEmbedded()
}
//==========================================================================
//
// this is just for completeness. For non-Zips only an uncompressed lump can
// be returned.
//
//==========================================================================
FCompressedBuffer FResourceLump::GetRawData()
{
FCompressedBuffer cbuf = { (unsigned)LumpSize, (unsigned)LumpSize, METHOD_STORED, 0, 0, new char[LumpSize] };
memcpy(cbuf.mBuffer, CacheLump(), LumpSize);
cbuf.mCRC32 = crc32(0, (BYTE*)cbuf.mBuffer, LumpSize);
ReleaseCache();
return cbuf;
}
//==========================================================================
//
// Returns the owner's FileReader if it can be used to access this lump

View file

@ -8,6 +8,28 @@
class FResourceFile;
class FTexture;
// This holds a compresed Zip entry with all needed info to decompress it.
struct FCompressedBuffer
{
unsigned mSize;
unsigned mCompressedSize;
int mMethod;
int mZipFlags;
unsigned mCRC32;
char *mBuffer;
bool Decompress(char *destbuffer);
void Clean()
{
mSize = mCompressedSize = 0;
if (mBuffer != nullptr)
{
delete[] mBuffer;
mBuffer = nullptr;
}
}
};
struct FResourceLump
{
friend class FResourceFile;
@ -46,6 +68,7 @@ struct FResourceLump
virtual int GetIndexNum() const { return 0; }
void LumpNameSetup(FString iname);
void CheckEmbedded();
virtual FCompressedBuffer GetRawData();
void *CacheLump();
int ReleaseCache();