- pass ´hashfile´ to filesystem as parameter

Avoid global variables, also check args as late as possible.
This commit is contained in:
Christoph Oelckers 2022-04-29 02:20:35 +02:00
parent ac1cfa6027
commit 72be9bcc27
3 changed files with 41 additions and 35 deletions

View file

@ -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<FString> &filenames, bool quiet, LumpFilterInfo* filter, bool allowduplicates)
void FileSystem::InitMultipleFiles (TArray<FString> &filenames, bool quiet, LumpFilterInfo* filter, bool allowduplicates, FILE* hashfile)
{
int numfiles;
@ -234,7 +232,7 @@ void FileSystem::InitMultipleFiles (TArray<FString> &filenames, bool quiet, Lump
for(unsigned i=0;i<filenames.Size(); i++)
{
AddFile (filenames[i], nullptr, quiet, filter);
AddFile (filenames[i], nullptr, quiet, filter, hashfile);
if (i == (unsigned)MaxIwadIndex) MoveLumpsInFolder("after_iwad/");
FStringf path("filter/%s", Files.Last()->GetHash().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);
}
}

View file

@ -68,8 +68,8 @@ public:
void SetMaxIwadNum(int x) { MaxIwadIndex = x; }
void InitSingleFile(const char *filename, bool quiet = false);
void InitMultipleFiles (TArray<FString> &filenames, bool quiet = false, LumpFilterInfo* filter = nullptr, bool allowduplicates = false);
void AddFile (const char *filename, FileReader *wadinfo, bool quiet, LumpFilterInfo* filter);
void InitMultipleFiles (TArray<FString> &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) {}

View file

@ -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<FString> 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<FString> 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();