Get rid of FUncompressedFile::Lumps

(RFF is inoperable in this commit!)
This commit is contained in:
Christoph Oelckers 2023-12-12 19:59:05 +01:00
parent 27a356814c
commit 854097024f
8 changed files with 38 additions and 168 deletions

View file

@ -107,8 +107,6 @@ bool FGrpFile::Open(LumpFilterInfo* filter)
GrpLump *fileinfo = new GrpLump[NumLumps];
Reader.Read (fileinfo, NumLumps * sizeof(GrpLump));
Lumps.Resize(NumLumps);
int Position = sizeof(GrpHeader) + NumLumps * sizeof(GrpLump);
for(uint32_t i = 0; i < NumLumps; i++)
@ -122,13 +120,6 @@ bool FGrpFile::Open(LumpFilterInfo* filter)
Entries[i].ResourceID = -1;
Entries[i].Method = METHOD_STORED;
Entries[i].FileName = NormalizeFileName(fileinfo[i].Name);
Lumps[i].Owner = this;
Lumps[i].Position = Position;
Lumps[i].LumpSize = Entries[i].Length;
Position += fileinfo[i].Size;
Lumps[i].Flags = 0;
Lumps[i].LumpNameSetup(fileinfo[i].NameWithZero, stringpool);
}
GenerateHash();
delete[] fileinfo;

View file

@ -76,13 +76,6 @@ bool FLumpFile::Open(LumpFilterInfo*)
Entries[0].Length = Reader.GetLength();
Entries[0].Method = METHOD_STORED;
Entries[0].Flags = 0;
Lumps.Resize(1);
Lumps[0].LumpNameSetup(ExtractBaseName(FileName, true).c_str(), stringpool);
Lumps[0].Owner = this;
Lumps[0].Position = 0;
Lumps[0].LumpSize = (int)Reader.GetLength();
Lumps[0].Flags = 0;
NumLumps = 1;
return true;
}

View file

@ -103,8 +103,6 @@ bool FPakFile::Open(LumpFilterInfo* filter)
Reader.Seek (header.dirofs, FileReader::SeekSet);
Reader.Read (fileinfo.Data(), NumLumps * sizeof(dpackfile_t));
Lumps.Resize(NumLumps);
for(uint32_t i = 0; i < NumLumps; i++)
{
Entries[i].Position = LittleLong(fileinfo[i].filepos);
@ -114,16 +112,8 @@ bool FPakFile::Open(LumpFilterInfo* filter)
Entries[i].ResourceID = -1;
Entries[i].Method = METHOD_STORED;
Entries[i].FileName = NormalizeFileName(fileinfo[i].name);
Lumps[i].LumpNameSetup(fileinfo[i].name, stringpool);
Lumps[i].Flags = LUMPF_FULLPATH;
Lumps[i].Owner = this;
Lumps[i].Position = LittleLong(fileinfo[i].filepos);
Lumps[i].LumpSize = LittleLong(fileinfo[i].filelen);
Lumps[i].CheckEmbedded(filter);
}
GenerateHash();
PostProcessArchive(&Lumps[0], sizeof(Lumps[0]), filter);
return true;
}

View file

@ -67,22 +67,6 @@ struct RFFLump
uint32_t IndexNum; // Used by .sfx, possibly others
};
//==========================================================================
//
// Blood RFF lump (uncompressed lump with encryption)
//
//==========================================================================
struct FRFFLump : public FUncompressedLump
{
virtual FileReader *GetReader();
virtual int FillCache() override;
uint32_t IndexNum;
int GetIndexNum() const { return IndexNum; }
};
//==========================================================================
//
// BloodCrypt
@ -108,13 +92,10 @@ void BloodCrypt (void *data, int key, int len)
class FRFFFile : public FResourceFile
{
FRFFLump *Lumps;
public:
FRFFFile(const char * filename, FileReader &file, StringPool* sp);
virtual ~FRFFFile();
virtual bool Open(LumpFilterInfo* filter);
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
};
@ -127,7 +108,6 @@ public:
FRFFFile::FRFFFile(const char *filename, FileReader &file, StringPool* sp)
: FResourceFile(filename, file, sp)
{
Lumps = NULL;
}
//==========================================================================
@ -151,8 +131,6 @@ bool FRFFFile::Open(LumpFilterInfo*)
Reader.Read (lumps, header.NumLumps * sizeof(RFFLump));
BloodCrypt (lumps, header.DirOfs, header.NumLumps * sizeof(RFFLump));
Lumps = new FRFFLump[NumLumps];
for (uint32_t i = 0; i < NumLumps; ++i)
{
Entries[i].Position = LittleLong(lumps[i].FilePos);
@ -172,14 +150,6 @@ bool FRFFFile::Open(LumpFilterInfo*)
Entries[i].Namespace = ns_global;
Entries[i].ResourceID = LittleLong(lumps[i].IndexNum);
Lumps[i].Position = LittleLong(lumps[i].FilePos);
Lumps[i].LumpSize = LittleLong(lumps[i].Size);
Lumps[i].Owner = this;
if (lumps[i].Flags & 0x10)
{
Lumps[i].Flags |= LUMPF_COMPRESSED; // flags the lump as not directly usable
}
Lumps[i].IndexNum = LittleLong(lumps[i].IndexNum);
// Rearrange the name and extension to construct the fullname.
char name[13];
strncpy(name, lumps[i].Name, 8);
@ -191,7 +161,6 @@ bool FRFFFile::Open(LumpFilterInfo*)
name[len+2] = lumps[i].Extension[1];
name[len+3] = lumps[i].Extension[2];
name[len+4] = 0;
Lumps[i].LumpNameSetup(name, stringpool);
Entries[i].FileName = NormalizeFileName(name);
}
delete[] lumps;
@ -199,41 +168,12 @@ bool FRFFFile::Open(LumpFilterInfo*)
return true;
}
FRFFFile::~FRFFFile()
{
if (Lumps != NULL)
{
delete[] Lumps;
}
}
//==========================================================================
//
// Get reader (only returns non-NULL if not encrypted)
//
//==========================================================================
FileReader *FRFFLump::GetReader()
{
// Don't return the reader if this lump is encrypted
// In that case always force caching of the lump
if (!(Flags & LUMPF_COMPRESSED))
{
return FUncompressedLump::GetReader();
}
else
{
return NULL;
}
}
//==========================================================================
//
// Fills the lump cache and performs decryption
//
//==========================================================================
#if 0
int FRFFLump::FillCache()
{
int res = FUncompressedLump::FillCache();
@ -250,6 +190,7 @@ int FRFFLump::FillCache()
}
return res;
}
#endif
//==========================================================================

View file

@ -72,8 +72,7 @@ bool FSSIFile::Open(int version, int EntryCount, LumpFilterInfo*)
{
AllocateEntries(EntryCount*2);
NumLumps = EntryCount*2;
Lumps.Resize(EntryCount*2);
int32_t j = (version == 2 ? 267 : 254) + (EntryCount * 121);
for (uint32_t i = 0; i < NumLumps; i+=2)
@ -108,23 +107,6 @@ bool FSSIFile::Open(int version, int EntryCount, LumpFilterInfo*)
Entries[i + 1].Method = METHOD_STORED;
if (strstr(fn, ".GRP")) Entries[i + 1].Flags |= RESFF_EMBEDDED;
// swap back...
std::swap(fn[strlength - 1], fn[strlength - 3]);
Lumps[i].LumpNameSetup(fn, stringpool);
Lumps[i].Position = j;
Lumps[i].LumpSize = flength;
Lumps[i].Owner = this;
if (strstr(fn, ".GRP")) Lumps[i].Flags |= LUMPF_EMBEDDED;
// SSI files can swap the order of the extension's characters - but there's no reliable detection for this and it can be mixed inside the same container,
// so we have no choice but to create another file record for the altered name.
std::swap(fn[strlength - 1], fn[strlength - 3]);
Lumps[i+1].LumpNameSetup(fn, stringpool);
Lumps[i+1].Position = j;
Lumps[i+1].LumpSize = flength;
Lumps[i+1].Owner = this;
if (strstr(fn, ".GRP")) Lumps[i+1].Flags |= LUMPF_EMBEDDED;
j += flength;
Reader.Seek(104, FileReader::SeekCur);

View file

@ -82,8 +82,7 @@ bool FWHResFile::Open(LumpFilterInfo*)
Reader.Read(directory, 4096);
int nl =1024/3;
Lumps.Resize(nl);
int k;
for (k = 0; k < nl; k++)
{
@ -114,15 +113,8 @@ bool FWHResFile::Open(LumpFilterInfo*)
Entries[i].ResourceID = -1;
Entries[i].Method = METHOD_STORED;
Entries[i].FileName = NormalizeFileName(synthname.c_str());
Lumps[i].LumpNameSetup(synthname.c_str(), stringpool);
Lumps[i].Owner = this;
Lumps[i].Position = offset;
Lumps[i].LumpSize = length;
i++;
}
Lumps.Clamp(NumLumps);
Lumps.ShrinkToFit();
return true;
}

View file

@ -683,48 +683,6 @@ int FResourceFile::FindEntry(const char *name)
return -1;
}
//==========================================================================
//
// Caches a lump's content and increases the reference counter
//
//==========================================================================
FileReader *FUncompressedLump::GetReader()
{
Owner->GetContainerReader()->Seek(Position, FileReader::SeekSet);
return Owner->GetContainerReader();
}
//==========================================================================
//
// Caches a lump's content and increases the reference counter
//
//==========================================================================
int FUncompressedLump::FillCache()
{
const char * buffer = Owner->GetContainerReader()->GetBuffer();
if (buffer != NULL)
{
// This is an in-memory file so the cache can point directly to the file's data.
Cache = const_cast<char*>(buffer) + Position;
RefCount = -1;
return -1;
}
Owner->GetContainerReader()->Seek(Position, FileReader::SeekSet);
Cache = new char[LumpSize];
auto read = Owner->GetContainerReader()->Read(Cache, LumpSize);
if (read != LumpSize)
{
throw FileSystemException("only read %d of %d bytes", (int)read, (int)LumpSize);
}
RefCount = 1;
return 1;
}
//==========================================================================
//
@ -740,6 +698,38 @@ FUncompressedFile::FUncompressedFile(const char *filename, FileReader &r, String
: FResourceFile(filename, r, sp)
{}
//==========================================================================
//
// Caches a lump's content and increases the reference counter
//
//==========================================================================
FileReader FUncompressedFile::GetEntryReader(uint32_t entry, bool newreader)
{
FileReader fr;
if (entry < NumLumps)
{
if (!Entries[entry].Flags & RESFF_COMPRESSED)
{
if (!newreader)
{
fr.OpenFilePart(Reader, Entries[entry].Position, Entries[entry].Length);
}
else
{
fr.OpenFile(FileName, Entries[entry].Position, Entries[entry].Length);
}
}
else
{
FileReader fri;
fri.OpenFilePart(Reader, Entries[entry].Position, Entries[entry].CompressedSize);
fr.OpenDecompressor(fri, Entries[entry].Length, Entries[entry].Method | METHOD_TRANSFEROWNER, true, true);
}
}
return fr;
}
//==========================================================================
//

View file

@ -3,25 +3,16 @@
#include "resourcefile.h"
namespace FileSys {
struct FUncompressedLump : public FResourceLump
{
int Position;
virtual FileReader *GetReader();
virtual int FillCache() override;
virtual int GetFileOffset() { return Position; }
};
// Base class for uncompressed resource files (WAD, GRP, PAK and single lumps)
class FUncompressedFile : public FResourceFile
{
protected:
TArray<FUncompressedLump> Lumps;
FUncompressedFile(const char *filename, StringPool* sp);
FUncompressedFile(const char *filename, FileReader &r, StringPool* sp);
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
//FileData Read(int entry) override; todo later. It's only needed for optimization once everything works
FileReader GetEntryReader(uint32_t entry, bool) override;
};