got rid of FDirectoryLump.

This commit is contained in:
Christoph Oelckers 2023-12-12 19:20:23 +01:00
parent 3b0d101607
commit f5f9d5b5d8
4 changed files with 16 additions and 83 deletions

View file

@ -753,7 +753,6 @@ FCompressedBuffer FSerializer::GetCompressedOutput()
EndObject();
buff.filename = nullptr;
buff.mSize = (unsigned)w->mOutString.GetSize();
buff.mZipFlags = 0;
buff.mCRC32 = crc32(0, (const Bytef*)w->mOutString.GetString(), buff.mSize);
uint8_t *compressbuf = new uint8_t[buff.mSize+1];

View file

@ -232,7 +232,7 @@ public:
void SetFirstLump(uint32_t f) { FirstLump = f; }
const char* GetHash() const { return Hash; }
virtual FResourceLump *GetLump(int no) = 0;
virtual FResourceLump* GetLump(int no) { throw FileSystemException("GetLump base function called."); }
int EntryCount() const { return NumLumps; }
int FindEntry(const char* name);
@ -246,7 +246,7 @@ public:
return (entry < NumLumps) ? Entries[entry].Position : 0;
}
FileReader GetEntryReader(int entry, bool newreader = true)
virtual FileReader GetEntryReader(uint32_t entry, bool newreader = true)
{
auto l = GetLump(entry);
return l ? l->NewReader() : FileReader();

View file

@ -48,21 +48,6 @@ std::string FS_FullPath(const char* directory);
std::wstring toWide(const char* str);
#endif
//==========================================================================
//
// Zip Lump
//
//==========================================================================
struct FDirectoryLump : public FResourceLump
{
const char* mBasePath;
FileReader NewReader() override;
int FillCache() override;
};
//==========================================================================
//
// Zip file
@ -71,17 +56,15 @@ struct FDirectoryLump : public FResourceLump
class FDirectory : public FResourceFile
{
TArray<FDirectoryLump> Lumps;
const bool nosubdir;
const char* mBasePath;
int AddDirectory(const char* dirpath, LumpFilterInfo* filter, FileSystemMessageFunc Printf);
void AddEntry(const char* relpath, int size);
public:
FDirectory(const char * dirname, StringPool* sp, bool nosubdirflag = false);
bool Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf);
virtual FResourceLump *GetLump(int no) { return ((unsigned)no < NumLumps)? &Lumps[no] : NULL; }
FileReader GetEntryReader(uint32_t entry, bool newreader = true) override;
};
@ -146,17 +129,13 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy
Printf(FSMessageLevel::Warning, "%s is larger than 2GB and will be ignored\n", entry.FilePath.c_str());
continue;
}
AddEntry(entry.FilePathRel.c_str(), (int)entry.Length);
int index = count;
// for internal access we use the normalized form of the relative path.
Entries[index].FileName = NormalizeFileName(entry.FilePathRel.c_str());
Entries[index].Length = entry.Length;
Entries[index].Flags = RESFF_FULLPATH;
Entries[index].ResourceID = -1;
Entries[index].Method = METHOD_STORED;
Entries[index].Namespace = ns_global;
index++;
Entries[count].FileName = NormalizeFileName(entry.FilePathRel.c_str());
Entries[count].Length = entry.Length;
Entries[count].Flags = RESFF_FULLPATH;
Entries[count].ResourceID = -1;
Entries[count].Method = METHOD_STORED;
Entries[count].Namespace = ns_global;
count++;
}
}
@ -174,7 +153,6 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy
bool FDirectory::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
{
NumLumps = AddDirectory(FileName, filter, Printf);
PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump), filter);
return true;
}
@ -184,61 +162,17 @@ bool FDirectory::Open(LumpFilterInfo* filter, FileSystemMessageFunc Printf)
//
//==========================================================================
void FDirectory::AddEntry(const char* relpath, int size)
{
FDirectoryLump *lump_p = &Lumps[Lumps.Reserve(1)];
// [mxd] Convert name to lowercase
std::string name = relpath;
for (auto& c : name) c = tolower(c);
// The lump's name is only the part relative to the main directory
lump_p->LumpNameSetup(name.c_str(), stringpool);
lump_p->LumpSize = size;
lump_p->Owner = this;
lump_p->Flags = 0;
lump_p->CheckEmbedded(nullptr);
}
//==========================================================================
//
//
//
//==========================================================================
FileReader FDirectoryLump::NewReader()
FileReader FDirectory::GetEntryReader(uint32_t entry, bool newreader)
{
FileReader fr;
std::string fn = mBasePath; fn += this->FullName;
fr.OpenFile(fn.c_str());
if (entry < NumLumps)
{
std::string fn = mBasePath; fn += Entries[entry].FileName;
fr.OpenFile(fn.c_str());
}
return fr;
}
//==========================================================================
//
//
//
//==========================================================================
int FDirectoryLump::FillCache()
{
FileReader fr;
Cache = new char[LumpSize];
std::string fn = mBasePath; fn += this->FullName;
if (!fr.OpenFile(fn.c_str()))
{
throw FileSystemException("unable to open file");
}
auto read = fr.Read(Cache, LumpSize);
if (read != LumpSize)
{
throw FileSystemException("only read %d of %d bytes", (int)read, (int)LumpSize);
}
RefCount = 1;
return 1;
}
//==========================================================================
//
// File open

View file

@ -2427,7 +2427,7 @@ void G_DoSaveGame (bool okForQuicksave, bool forceQuicksave, FString filename, c
}
auto picdata = savepic.GetBuffer();
FCompressedBuffer bufpng = { picdata->size(), picdata->size(), FileSys::METHOD_STORED, 0, static_cast<unsigned int>(crc32(0, &(*picdata)[0], picdata->size())), (char*)&(*picdata)[0] };
FCompressedBuffer bufpng = { picdata->size(), picdata->size(), FileSys::METHOD_STORED, static_cast<unsigned int>(crc32(0, &(*picdata)[0], picdata->size())), (char*)&(*picdata)[0] };
savegame_content.Push(bufpng);
savegame_filenames.Push("savepic.png");