From f5f9d5b5d8070dcb1a520abaf02ffbfeaf169d69 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 12 Dec 2023 19:20:23 +0100 Subject: [PATCH] got rid of FDirectoryLump. --- src/common/engine/serializer.cpp | 1 - src/common/filesystem/include/resourcefile.h | 4 +- .../filesystem/source/file_directory.cpp | 92 +++---------------- src/g_game.cpp | 2 +- 4 files changed, 16 insertions(+), 83 deletions(-) diff --git a/src/common/engine/serializer.cpp b/src/common/engine/serializer.cpp index ae0ad5ffc5..261aa464cb 100644 --- a/src/common/engine/serializer.cpp +++ b/src/common/engine/serializer.cpp @@ -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]; diff --git a/src/common/filesystem/include/resourcefile.h b/src/common/filesystem/include/resourcefile.h index 9ef51ffc75..0cf08ea321 100644 --- a/src/common/filesystem/include/resourcefile.h +++ b/src/common/filesystem/include/resourcefile.h @@ -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(); diff --git a/src/common/filesystem/source/file_directory.cpp b/src/common/filesystem/source/file_directory.cpp index 9d96eacad2..ab0f8ae049 100644 --- a/src/common/filesystem/source/file_directory.cpp +++ b/src/common/filesystem/source/file_directory.cpp @@ -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 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 diff --git a/src/g_game.cpp b/src/g_game.cpp index c731993b11..eb6f45b0cd 100644 --- a/src/g_game.cpp +++ b/src/g_game.cpp @@ -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(crc32(0, &(*picdata)[0], picdata->size())), (char*)&(*picdata)[0] }; + FCompressedBuffer bufpng = { picdata->size(), picdata->size(), FileSys::METHOD_STORED, static_cast(crc32(0, &(*picdata)[0], picdata->size())), (char*)&(*picdata)[0] }; savegame_content.Push(bufpng); savegame_filenames.Push("savepic.png");