2019-10-03 22:52:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef __RESFILE_H
|
|
|
|
#define __RESFILE_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "files.h"
|
|
|
|
#include "zstring.h"
|
|
|
|
|
|
|
|
class FResourceFile;
|
|
|
|
class FTexture;
|
|
|
|
|
|
|
|
enum ELumpFlags
|
|
|
|
{
|
2019-10-28 22:46:15 +00:00
|
|
|
LUMPF_ZIPFILE=1, // contains a full path
|
|
|
|
LUMPF_BLOODCRYPT = 2, // encrypted
|
|
|
|
LUMPF_COMPRESSED = 4, // compressed
|
|
|
|
LUMPF_SEQUENTIAL = 8, // compressed but a sequential reader can be retrieved.
|
2019-10-03 22:52:19 +00:00
|
|
|
};
|
|
|
|
|
2019-10-28 22:46:15 +00:00
|
|
|
class FResourceFile;
|
|
|
|
|
2019-10-03 22:52:19 +00:00
|
|
|
// 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;
|
|
|
|
|
2019-10-28 22:46:15 +00:00
|
|
|
int LumpSize = 0;
|
|
|
|
int RefCount = 0;
|
|
|
|
int Flags = 0;
|
2019-10-28 23:15:36 +00:00
|
|
|
int PathLen = 0;
|
|
|
|
int ExtStart = -1;
|
2019-10-28 22:46:15 +00:00
|
|
|
FString FullName; // Name with extension and path
|
|
|
|
FResourceFile * Owner = nullptr;
|
|
|
|
TArray<uint8_t> Cache;
|
2019-10-03 22:52:19 +00:00
|
|
|
|
2019-10-28 22:46:15 +00:00
|
|
|
FResourceLump() = default;
|
2019-10-03 22:52:19 +00:00
|
|
|
|
|
|
|
virtual ~FResourceLump();
|
2019-10-28 22:46:15 +00:00
|
|
|
virtual FileReader *GetReader();
|
2019-10-03 22:52:19 +00:00
|
|
|
virtual FileReader NewReader();
|
|
|
|
virtual int GetFileOffset() { return -1; }
|
|
|
|
virtual int GetIndexNum() const { return 0; }
|
|
|
|
void LumpNameSetup(FString iname);
|
2019-10-28 22:46:15 +00:00
|
|
|
virtual FCompressedBuffer GetRawData();
|
2019-10-03 22:52:19 +00:00
|
|
|
|
|
|
|
void *CacheLump();
|
|
|
|
int ReleaseCache();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int FillCache() { return -1; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class FResourceFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileReader Reader;
|
|
|
|
FString FileName;
|
|
|
|
protected:
|
|
|
|
uint32_t NumLumps;
|
|
|
|
|
|
|
|
FResourceFile(const char *filename);
|
|
|
|
FResourceFile(const char *filename, FileReader &r);
|
|
|
|
|
2019-10-28 22:46:15 +00:00
|
|
|
// for archives that can contain directories
|
|
|
|
void PostProcessArchive(void *lumps, size_t lumpsize);
|
|
|
|
|
2019-10-03 22:52:19 +00:00
|
|
|
private:
|
|
|
|
uint32_t FirstLump;
|
|
|
|
|
2019-10-28 22:46:15 +00:00
|
|
|
int FilterLumps(FString filtername, void *lumps, size_t lumpsize, uint32_t max);
|
|
|
|
bool FindPrefixRange(FString filter, void *lumps, size_t lumpsize, uint32_t max, uint32_t &start, uint32_t &end);
|
|
|
|
void JunkLeftoverFilters(void *lumps, size_t lumpsize, uint32_t max);
|
|
|
|
static FResourceFile *DoOpenResourceFile(const char *filename, FileReader &file, bool quiet, bool containeronly);
|
|
|
|
|
2019-10-03 22:52:19 +00:00
|
|
|
public:
|
|
|
|
static FResourceFile *OpenResourceFile(const char *filename, FileReader &file, bool quiet = false, bool containeronly = false);
|
|
|
|
static FResourceFile *OpenResourceFile(const char *filename, bool quiet = false, bool containeronly = false);
|
2019-10-28 22:46:15 +00:00
|
|
|
static FResourceFile *OpenDirectory(const char *filename, bool quiet = false);
|
2019-10-03 22:52:19 +00:00
|
|
|
virtual ~FResourceFile();
|
|
|
|
// If this FResourceFile represents a directory, the Reader object is not usable so don't return it.
|
|
|
|
FileReader *GetReader() { return Reader.isOpen()? &Reader : nullptr; }
|
|
|
|
uint32_t LumpCount() const { return NumLumps; }
|
|
|
|
uint32_t GetFirstLump() const { return FirstLump; }
|
|
|
|
void SetFirstLump(uint32_t f) { FirstLump = f; }
|
2019-10-28 22:46:15 +00:00
|
|
|
|
2019-10-03 22:52:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
virtual bool Open(bool quiet) = 0;
|
|
|
|
virtual FResourceLump *GetLump(int no) = 0;
|
|
|
|
FResourceLump *FindLump(const char *name);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FUncompressedLump : public FResourceLump
|
|
|
|
{
|
|
|
|
int Position;
|
|
|
|
|
|
|
|
virtual FileReader *GetReader();
|
|
|
|
virtual int FillCache();
|
|
|
|
virtual int GetFileOffset() { return Position; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-10-28 22:46:15 +00:00
|
|
|
// Base class for uncompressed resource files (GRP, PAK and single lumps)
|
2019-10-03 22:52:19 +00:00
|
|
|
class FUncompressedFile : public FResourceFile
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
TArray<FUncompressedLump> Lumps;
|
|
|
|
|
|
|
|
FUncompressedFile(const char *filename);
|
|
|
|
FUncompressedFile(const char *filename, FileReader &r);
|
|
|
|
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
|
|
|
|
};
|
|
|
|
|
2019-10-28 22:46:15 +00:00
|
|
|
|
|
|
|
struct FExternalLump : public FResourceLump
|
|
|
|
{
|
|
|
|
FString Filename;
|
|
|
|
|
|
|
|
FExternalLump(const char *_filename, int filesize = -1);
|
|
|
|
virtual int FillCache();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-10-03 22:52:19 +00:00
|
|
|
#endif
|