From 860a0c290bcec0c5ca76566aee502496bf5aa978 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 17 Dec 2023 17:13:15 +0100 Subject: [PATCH] fixed some filesystem issues with directories and compression. --- source/common/filesystem/source/file_directory.cpp | 6 +++--- source/common/filesystem/source/file_grp.cpp | 2 +- source/common/filesystem/source/file_hog.cpp | 2 +- source/common/filesystem/source/file_lump.cpp | 2 +- source/common/filesystem/source/file_mvl.cpp | 2 +- source/common/filesystem/source/file_pak.cpp | 2 +- source/common/filesystem/source/file_rff.cpp | 2 +- source/common/filesystem/source/file_ssi.cpp | 4 ++-- source/common/filesystem/source/file_wad.cpp | 11 ++++++++++- source/common/filesystem/source/file_whres.cpp | 2 +- 10 files changed, 22 insertions(+), 13 deletions(-) diff --git a/source/common/filesystem/source/file_directory.cpp b/source/common/filesystem/source/file_directory.cpp index 0b9c101cea..01eee7bf2a 100644 --- a/source/common/filesystem/source/file_directory.cpp +++ b/source/common/filesystem/source/file_directory.cpp @@ -101,7 +101,7 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy else { mBasePath = nullptr; - AllocateEntries(list.size()); + AllocateEntries((int)list.size()); for(auto& entry : list) { if (mBasePath == nullptr) @@ -122,7 +122,7 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy } - if (filter->filenamecheck == nullptr || filter->filenamecheck(fi.c_str(), entry.FilePath.c_str())) + if (filter == nullptr || filter->filenamecheck == nullptr || filter->filenamecheck(fi.c_str(), entry.FilePath.c_str())) { if (entry.Length > 0x7fffffff) { @@ -131,7 +131,7 @@ int FDirectory::AddDirectory(const char *dirpath, LumpFilterInfo* filter, FileSy } // for internal access we use the normalized form of the relative path. Entries[count].FileName = NormalizeFileName(entry.FilePathRel.c_str()); - Entries[count].Length = entry.Length; + Entries[count].CompressedSize = Entries[count].Length = entry.Length; Entries[count].Flags = RESFF_FULLPATH; Entries[count].ResourceID = -1; Entries[count].Method = METHOD_STORED; diff --git a/source/common/filesystem/source/file_grp.cpp b/source/common/filesystem/source/file_grp.cpp index 39d8abc191..57206b4b10 100644 --- a/source/common/filesystem/source/file_grp.cpp +++ b/source/common/filesystem/source/file_grp.cpp @@ -88,7 +88,7 @@ static bool OpenGrp(FResourceFile* file, LumpFilterInfo* filter) for(uint32_t i = 0; i < NumLumps; i++) { Entries[i].Position = Position; - Entries[i].Length = LittleLong(fileinfo[i].Size); + Entries[i].CompressedSize = Entries[i].Length = LittleLong(fileinfo[i].Size); Position += fileinfo[i].Size; Entries[i].Flags = 0; Entries[i].Namespace = ns_global; diff --git a/source/common/filesystem/source/file_hog.cpp b/source/common/filesystem/source/file_hog.cpp index cc4eef4ff0..d12f7e2d86 100644 --- a/source/common/filesystem/source/file_hog.cpp +++ b/source/common/filesystem/source/file_hog.cpp @@ -63,7 +63,7 @@ static bool OpenHog(FResourceFile* rf, LumpFilterInfo* filter) FResourceEntry Entry; Entry.Position = Reader->Tell(); - Entry.Length = elength; + Entry.CompressedSize = Entry.Length = elength; Entry.Flags = 0; Entry.CRC32 = 0; Entry.Namespace = ns_global; diff --git a/source/common/filesystem/source/file_lump.cpp b/source/common/filesystem/source/file_lump.cpp index b08f3bf652..b01d46b5d3 100644 --- a/source/common/filesystem/source/file_lump.cpp +++ b/source/common/filesystem/source/file_lump.cpp @@ -48,7 +48,7 @@ static bool OpenLump(FResourceFile* file, LumpFilterInfo*) Entries[0].Namespace = ns_global; Entries[0].ResourceID = -1; Entries[0].Position = 0; - Entries[0].Length = file->GetContainerReader()->GetLength(); + Entries[0].CompressedSize = Entries[0].Length = file->GetContainerReader()->GetLength(); Entries[0].Method = METHOD_STORED; Entries[0].Flags = 0; return true; diff --git a/source/common/filesystem/source/file_mvl.cpp b/source/common/filesystem/source/file_mvl.cpp index 48babef16d..f08db31618 100644 --- a/source/common/filesystem/source/file_mvl.cpp +++ b/source/common/filesystem/source/file_mvl.cpp @@ -58,7 +58,7 @@ static bool OpenMvl(FResourceFile* rf, LumpFilterInfo* filter) uint32_t elength = Reader->ReadUInt32(); Entries[i].Position = pos; - Entries[i].Length = elength; + Entries[i].CompressedSize = Entries[i].Length = elength; Entries[i].ResourceID = -1; Entries[i].FileName = rf->NormalizeFileName(name); diff --git a/source/common/filesystem/source/file_pak.cpp b/source/common/filesystem/source/file_pak.cpp index c1d559eb94..b66a0f3d99 100644 --- a/source/common/filesystem/source/file_pak.cpp +++ b/source/common/filesystem/source/file_pak.cpp @@ -80,7 +80,7 @@ static bool OpenPak(FResourceFile* file, LumpFilterInfo* filter) for(uint32_t i = 0; i < NumLumps; i++) { Entries[i].Position = LittleLong(fileinfo[i].filepos); - Entries[i].Length = LittleLong(fileinfo[i].filelen); + Entries[i].CompressedSize = Entries[i].Length = LittleLong(fileinfo[i].filelen); Entries[i].Flags = RESFF_FULLPATH; Entries[i].Namespace = ns_global; Entries[i].ResourceID = -1; diff --git a/source/common/filesystem/source/file_rff.cpp b/source/common/filesystem/source/file_rff.cpp index a3545d3b90..673a08ce06 100644 --- a/source/common/filesystem/source/file_rff.cpp +++ b/source/common/filesystem/source/file_rff.cpp @@ -110,7 +110,7 @@ static bool OpenRFF(FResourceFile* file, LumpFilterInfo*) for (uint32_t i = 0; i < NumLumps; ++i) { Entries[i].Position = LittleLong(lumps[i].FilePos); - Entries[i].Length = LittleLong(lumps[i].Size); + Entries[i].CompressedSize = Entries[i].Length = LittleLong(lumps[i].Size); Entries[i].Flags = 0; Entries[i].Method = METHOD_STORED; if (lumps[i].Flags & 0x10) diff --git a/source/common/filesystem/source/file_ssi.cpp b/source/common/filesystem/source/file_ssi.cpp index a5efec8c19..82885c6bb7 100644 --- a/source/common/filesystem/source/file_ssi.cpp +++ b/source/common/filesystem/source/file_ssi.cpp @@ -63,7 +63,7 @@ static bool OpenSSI(FResourceFile* file, int version, int EntryCount, LumpFilter int flength = Reader->ReadInt32(); Entries[i].Position = j; - Entries[i].Length = flength; + Entries[i].CompressedSize = Entries[i].Length = flength; Entries[i].Flags = 0; Entries[i].Namespace = ns_global; Entries[i].Method = METHOD_STORED; @@ -76,7 +76,7 @@ static bool OpenSSI(FResourceFile* file, int version, int EntryCount, LumpFilter std::swap(fn[strlength - 1], fn[strlength - 3]); Entries[i + 1].Position = j; - Entries[i + 1].Length = flength; + Entries[i + 1].CompressedSize = Entries[i + 1].Length = flength; Entries[i + 1].Flags = 0; Entries[i + 1].Namespace = ns_global; Entries[i + 1].ResourceID = -1; diff --git a/source/common/filesystem/source/file_wad.cpp b/source/common/filesystem/source/file_wad.cpp index c35d4ce591..4f8574b73d 100644 --- a/source/common/filesystem/source/file_wad.cpp +++ b/source/common/filesystem/source/file_wad.cpp @@ -148,13 +148,22 @@ bool FWadFile::Open(LumpFilterInfo*, FileSystemMessageFunc Printf) Entries[i].FileName = nullptr; Entries[i].Position = isBigEndian ? BigLong(fileinfo[i].FilePos) : LittleLong(fileinfo[i].FilePos); - Entries[i].Length = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size); + Entries[i].CompressedSize = Entries[i].Length = isBigEndian ? BigLong(fileinfo[i].Size) : LittleLong(fileinfo[i].Size); + Entries[i].Namespace = ns_global; Entries[i].Flags = ishigh? RESFF_SHORTNAME | RESFF_COMPRESSED : RESFF_SHORTNAME; Entries[i].Method = ishigh == 1? METHOD_LZSS : METHOD_STORED; Entries[i].FileName = stringpool->Strdup(n); // This doesn't set up the namespace yet. } + for (uint32_t i = 0; i < NumLumps; i++) + { + if (Entries[i].Method == METHOD_LZSS) + { + // compressed size is implicit. + Entries[i].CompressedSize = (i == NumLumps - 1 ? Reader.GetLength() : Entries[i + 1].Position) - Entries[i].Position; + } + } GenerateHash(); // Do this before the lump processing below. diff --git a/source/common/filesystem/source/file_whres.cpp b/source/common/filesystem/source/file_whres.cpp index c0c7be6161..d1d2d1a508 100644 --- a/source/common/filesystem/source/file_whres.cpp +++ b/source/common/filesystem/source/file_whres.cpp @@ -81,7 +81,7 @@ bool OpenWHRes(FResourceFile* file, LumpFilterInfo*) std::string synthname = BaseName + num; Entries[i].Position = offset; - Entries[i].Length = length; + Entries[i].CompressedSize = Entries[i].Length = length; Entries[i].Flags = RESFF_FULLPATH; Entries[i].Namespace = ns_global; Entries[i].ResourceID = -1;