From efa82cf38bf92672b32854c18b7d3186a7daf4a1 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Fri, 3 Apr 2015 20:22:18 -0500 Subject: [PATCH] Consolidate archive sorting into FResourceFile base class --- src/d_iwad.cpp | 2 +- src/resourcefiles/file_7z.cpp | 16 ++-------------- src/resourcefiles/file_directory.cpp | 19 +------------------ src/resourcefiles/file_zip.cpp | 15 +-------------- src/resourcefiles/resourcefile.cpp | 21 +++++++++++++++++++++ src/resourcefiles/resourcefile.h | 1 + 6 files changed, 27 insertions(+), 47 deletions(-) diff --git a/src/d_iwad.cpp b/src/d_iwad.cpp index d6b1b092d..4a46a93cd 100644 --- a/src/d_iwad.cpp +++ b/src/d_iwad.cpp @@ -253,7 +253,7 @@ void FIWadManager::ParseIWadInfo(const char *fn, const char *data, int datasize) //========================================================================== // -// Lool for IWAD definition lump +// Look for IWAD definition lump // //========================================================================== diff --git a/src/resourcefiles/file_7z.cpp b/src/resourcefiles/file_7z.cpp index 81b740582..1fb553932 100644 --- a/src/resourcefiles/file_7z.cpp +++ b/src/resourcefiles/file_7z.cpp @@ -179,7 +179,7 @@ struct F7ZLump : public FResourceLump //========================================================================== // -// Zip file +// 7-zip file // //========================================================================== @@ -190,8 +190,6 @@ class F7ZFile : public FResourceFile F7ZLump *Lumps; C7zArchive *Archive; - static int STACK_ARGS lumpcmp(const void * a, const void * b); - public: F7ZFile(const char * filename, FileReader *filer); bool Open(bool quiet); @@ -201,15 +199,6 @@ public: -int STACK_ARGS F7ZFile::lumpcmp(const void * a, const void * b) -{ - F7ZLump * rec1 = (F7ZLump *)a; - F7ZLump * rec2 = (F7ZLump *)b; - - return rec1->FullName.CompareNoCase(rec2->FullName); -} - - //========================================================================== // // 7Z file @@ -328,8 +317,7 @@ bool F7ZFile::Open(bool quiet) if (!quiet) Printf(", %d lumps\n", NumLumps); - // Entries in archives are sorted alphabetically - qsort(&Lumps[0], NumLumps, sizeof(F7ZLump), lumpcmp); + PostProcessArchive(&Lumps[0], sizeof(F7ZLump)); return true; } diff --git a/src/resourcefiles/file_directory.cpp b/src/resourcefiles/file_directory.cpp index 0b74bda7b..08cb99ea9 100644 --- a/src/resourcefiles/file_directory.cpp +++ b/src/resourcefiles/file_directory.cpp @@ -86,8 +86,6 @@ class FDirectory : public FResourceFile { TArray Lumps; - static int STACK_ARGS lumpcmp(const void * a, const void * b); - int AddDirectory(const char *dirpath); void AddEntry(const char *fullpath, int size); @@ -122,20 +120,6 @@ FDirectory::FDirectory(const char * directory) } -//========================================================================== -// -// -// -//========================================================================== - -int STACK_ARGS FDirectory::lumpcmp(const void * a, const void * b) -{ - FDirectoryLump * rec1 = (FDirectoryLump *)a; - FDirectoryLump * rec2 = (FDirectoryLump *)b; - - return rec1->FullName.CompareNoCase(rec2->FullName); -} - #ifdef _WIN32 //========================================================================== // @@ -299,8 +283,7 @@ bool FDirectory::Open(bool quiet) { NumLumps = AddDirectory(Filename); if (!quiet) Printf(", %d lumps\n", NumLumps); - // Entries in Zips are sorted alphabetically. - qsort(&Lumps[0], NumLumps, sizeof(FDirectoryLump), lumpcmp); + PostProcessArchive(&Lumps[0], sizeof(FDirectoryLump)); return true; } diff --git a/src/resourcefiles/file_zip.cpp b/src/resourcefiles/file_zip.cpp index bbca89d40..5d6ff6c9e 100644 --- a/src/resourcefiles/file_zip.cpp +++ b/src/resourcefiles/file_zip.cpp @@ -138,8 +138,6 @@ class FZipFile : public FResourceFile { FZipLump *Lumps; - static int STACK_ARGS lumpcmp(const void * a, const void * b); - public: FZipFile(const char * filename, FileReader *file); virtual ~FZipFile(); @@ -148,16 +146,6 @@ public: }; - -int STACK_ARGS FZipFile::lumpcmp(const void * a, const void * b) -{ - FZipLump * rec1 = (FZipLump *)a; - FZipLump * rec2 = (FZipLump *)b; - - return rec1->FullName.CompareNoCase(rec2->FullName); -} - - //========================================================================== // // Zip file @@ -274,8 +262,7 @@ bool FZipFile::Open(bool quiet) if (!quiet) Printf(", %d lumps\n", NumLumps); - // Entries in Zips are sorted alphabetically. - qsort(Lumps, NumLumps, sizeof(FZipLump), lumpcmp); + PostProcessArchive(&Lumps[0], sizeof(FZipLump)); return true; } diff --git a/src/resourcefiles/resourcefile.cpp b/src/resourcefiles/resourcefile.cpp index 41d7f8a99..181559f85 100644 --- a/src/resourcefiles/resourcefile.cpp +++ b/src/resourcefiles/resourcefile.cpp @@ -316,6 +316,27 @@ FResourceFile::~FResourceFile() delete Reader; } +int STACK_ARGS lumpcmp(const void * a, const void * b) +{ + FResourceLump * rec1 = (FResourceLump *)a; + FResourceLump * rec2 = (FResourceLump *)b; + + return rec1->FullName.CompareNoCase(rec2->FullName); +} + +//========================================================================== +// +// FResourceFile :: PostProcessArchive +// +// Sorts files by name. +// +//========================================================================== + +void FResourceFile::PostProcessArchive(void *lumps, size_t lumpsize) +{ + // Entries in archives are sorted alphabetically + qsort(lumps, NumLumps, lumpsize, lumpcmp); +} //========================================================================== // diff --git a/src/resourcefiles/resourcefile.h b/src/resourcefiles/resourcefile.h index bcd030e8f..8fd7366ef 100644 --- a/src/resourcefiles/resourcefile.h +++ b/src/resourcefiles/resourcefile.h @@ -76,6 +76,7 @@ public: DWORD LumpCount() const { return NumLumps; } DWORD GetFirstLump() const { return FirstLump; } void SetFirstLump(DWORD f) { FirstLump = f; } + void PostProcessArchive(void *lumps, size_t lumpsize); // for archives that can contain directories virtual void FindStrifeTeaserVoices (); virtual bool Open(bool quiet) = 0;