From ddfb2223dba16a6b4389eb15a7e5f7a028103dc8 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 7 Dec 2019 09:44:43 +0100 Subject: [PATCH] - added a directory list function to the file system. - fixed lookup for resources by ID - it always picked the first candidate from the hash chain without checking the actual ID. --- source/common/filesystem/filesystem.cpp | 38 ++++++++++--------------- source/common/filesystem/filesystem.h | 1 + 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/source/common/filesystem/filesystem.cpp b/source/common/filesystem/filesystem.cpp index 86c819f48..05f022ad4 100644 --- a/source/common/filesystem/filesystem.cpp +++ b/source/common/filesystem/filesystem.cpp @@ -48,6 +48,7 @@ #include "filesystem.h" #include "resourcefile.h" #include "v_text.h" +#include "c_dispatch.h" //#include "md5.h" //#include "doomstat.h" @@ -322,6 +323,7 @@ int FileSystem::FindResource (int resid, const char *type, int filenum) const no for (i = fli[int(resid) % NumEntries]; i != NULL_INDEX; i = nli[i]) { if (filenum > 0 && FileInfo[i].rfnum != filenum) continue; + if (FileInfo[i].lump->ResourceId != resid) continue; auto lump = FileInfo[i].lump; if (lump->LumpName[lookuptype] == lname) return i; } @@ -1064,28 +1066,18 @@ static void PrintLastError () } #endif -#if 0 -void FileSystem::HashDump() +CCMD(printfs) { - FILE* f = fopen("fs_hash.txt", "wb"); - for (int list = 0; list < 5; list++) - { - fprintf(f, "List %d\n------------\n", list); - auto fli = FirstFileIndex[list]; - auto nli = NextFileIndex[list]; - for (int hash = 0; hash < NumEntries; hash++) - { - if (fli[hash] != NULL_INDEX) - { - fprintf(f, "\tHash %d\n", hash); - for (uint32_t i = fli[hash]; i != NULL_INDEX; i = nli[i]) - { - auto lump = FileInfo[i].lump; - fprintf(f, "\t\t%s (%d)\t%d, %d\n", lump->LumpName[list].GetChars(), lump->LumpName[list].GetIndex(), lump->Size(), i); - } - } - } - } - fclose(f); + fileSystem.PrintDirectory(); +} + +void FileSystem::PrintDirectory() +{ + for (int i = 0; i < NumEntries; i++) + { + auto lump = FileInfo[i].lump; + auto f = GetFileContainer(i); + auto n = GetResourceFileFullName(f); + Printf("%5d: %9d %64s %4s %3d %s\n", i, lump->LumpSize, lump->LumpName[0].GetChars(), lump->LumpName[4].GetChars(), lump->ResourceId, n); + } } -#endif \ No newline at end of file diff --git a/source/common/filesystem/filesystem.h b/source/common/filesystem/filesystem.h index cf3b6b307..03d406728 100644 --- a/source/common/filesystem/filesystem.h +++ b/source/common/filesystem/filesystem.h @@ -148,6 +148,7 @@ public: { return FileInfo[lump].lump; } + void PrintDirectory(); protected: