From 72be9bcc2754d85116f61bd0e05f2c8bc6e762b6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 29 Apr 2022 02:20:35 +0200 Subject: [PATCH] =?UTF-8?q?-=20pass=20=C2=B4hashfile=C2=B4=20to=20filesyst?= =?UTF-8?q?em=20as=20parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid global variables, also check args as late as possible. --- src/common/filesystem/filesystem.cpp | 10 ++--- src/common/filesystem/filesystem.h | 4 +- src/d_main.cpp | 62 ++++++++++++++++------------ 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/common/filesystem/filesystem.cpp b/src/common/filesystem/filesystem.cpp index ff991d8b8..4afb284e1 100644 --- a/src/common/filesystem/filesystem.cpp +++ b/src/common/filesystem/filesystem.cpp @@ -47,8 +47,6 @@ #include "printf.h" #include "md5.h" -extern FILE* hashfile; - // MACROS ------------------------------------------------------------------ #define NULL_INDEX (0xffffffff) @@ -208,7 +206,7 @@ void FileSystem::InitSingleFile(const char* filename, bool quiet) InitMultipleFiles(filenames, true); } -void FileSystem::InitMultipleFiles (TArray &filenames, bool quiet, LumpFilterInfo* filter, bool allowduplicates) +void FileSystem::InitMultipleFiles (TArray &filenames, bool quiet, LumpFilterInfo* filter, bool allowduplicates, FILE* hashfile) { int numfiles; @@ -234,7 +232,7 @@ void FileSystem::InitMultipleFiles (TArray &filenames, bool quiet, Lump for(unsigned i=0;iGetHash().GetChars()); @@ -310,7 +308,7 @@ int FileSystem::AddFromBuffer(const char* name, const char* type, char* data, in // [RH] Removed reload hack //========================================================================== -void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, LumpFilterInfo* filter) +void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, LumpFilterInfo* filter, FILE* hashfile) { int startlump; bool isdir = false; @@ -378,7 +376,7 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, bool quiet, L FString path; path.Format("%s:%s", filename, lump->getName()); auto embedded = lump->NewReader(); - AddFile(path, &embedded, quiet, filter); + AddFile(path, &embedded, quiet, filter, hashfile); } } diff --git a/src/common/filesystem/filesystem.h b/src/common/filesystem/filesystem.h index 4052a7f4c..2dc80f7ff 100644 --- a/src/common/filesystem/filesystem.h +++ b/src/common/filesystem/filesystem.h @@ -68,8 +68,8 @@ public: void SetMaxIwadNum(int x) { MaxIwadIndex = x; } void InitSingleFile(const char *filename, bool quiet = false); - void InitMultipleFiles (TArray &filenames, bool quiet = false, LumpFilterInfo* filter = nullptr, bool allowduplicates = false); - void AddFile (const char *filename, FileReader *wadinfo, bool quiet, LumpFilterInfo* filter); + void InitMultipleFiles (TArray &filenames, bool quiet = false, LumpFilterInfo* filter = nullptr, bool allowduplicates = false, FILE* hashfile = nullptr); + void AddFile (const char *filename, FileReader *wadinfo, bool quiet, LumpFilterInfo* filter, FILE* hashfile); int CheckIfResourceFileLoaded (const char *name) noexcept; void AddAdditionalFile(const char* filename, FileReader* wadinfo = NULL) {} diff --git a/src/d_main.cpp b/src/d_main.cpp index a47f1cf2f..a7d3d2382 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -317,7 +317,6 @@ FString startmap; bool autostart; bool advancedemo; FILE *debugfile; -FILE *hashfile; gamestate_t wipegamestate = GS_DEMOSCREEN; // can be -1 to force a wipe bool PageBlank; FGameTexture *Advisory; @@ -2954,6 +2953,39 @@ static void System_SetTransition(int type) bool CheckSkipGameOptionBlock(const char* str); +//========================================================================== +// +// +// +//========================================================================== + +static FILE* D_GetHashFile() +{ + FILE *hashfile = nullptr; + + if (Args->CheckParm("-hashfiles")) + { + const char *filename = "fileinfo.txt"; + Printf("Hashing loaded content to: %s\n", filename); + hashfile = fopen(filename, "w"); + if (hashfile) + { + Printf("Notice: File hashing is incredibly verbose. Expect loading files to take much longer than usual.\n"); + fprintf(hashfile, "%s version %s (%s)\n", GAMENAME, GetVersionString(), GetGitHash()); +#ifdef __VERSION__ + fprintf(hashfile, "Compiler version: %s\n", __VERSION__); +#endif + fprintf(hashfile, "Command line:"); + for (int i = 0; i < Args->NumArgs(); ++i) + { + fprintf(hashfile, " %s", Args->GetArg(i)); + } + fprintf(hashfile, "\n"); + } + } + return hashfile; +} + //========================================================================== // // D_InitGame @@ -2994,11 +3026,6 @@ static int D_InitGame(const FIWADInfo* iwad_info, TArray allwads) exec->AddPullins(allwads, GameConfig); } - if (hashfile) - { - Printf("Notice: File hashing is incredibly verbose. Expect loading files to take much longer than usual.\n"); - } - if (!batchrun) Printf ("W_Init: Init WADfiles.\n"); LumpFilterInfo lfi; @@ -3030,7 +3057,8 @@ static int D_InitGame(const FIWADInfo* iwad_info, TArray allwads) }; bool allowduplicates = Args->CheckParm("-allowduplicates"); - fileSystem.InitMultipleFiles (allwads, false, &lfi, allowduplicates); + auto hashfile = D_GetHashFile(); + fileSystem.InitMultipleFiles (allwads, false, &lfi, allowduplicates, hashfile); allwads.Clear(); allwads.ShrinkToFit(); SetMapxxFlag(); @@ -3468,26 +3496,6 @@ static int D_DoomMain_Internal (void) Printf("\n"); } - if (Args->CheckParm("-hashfiles")) - { - const char *filename = "fileinfo.txt"; - Printf("Hashing loaded content to: %s\n", filename); - hashfile = fopen(filename, "w"); - if (hashfile) - { - fprintf(hashfile, "%s version %s (%s)\n", GAMENAME, GetVersionString(), GetGitHash()); -#ifdef __VERSION__ - fprintf(hashfile, "Compiler version: %s\n", __VERSION__); -#endif - fprintf(hashfile, "Command line:"); - for (int i = 0; i < Args->NumArgs(); ++i) - { - fprintf(hashfile, " %s", Args->GetArg(i)); - } - fprintf(hashfile, "\n"); - } - } - if (!batchrun) Printf(PRINT_LOG, "%s version %s\n", GAMENAME, GetVersionString()); D_DoomInit();