This commit is contained in:
Christoph Oelckers 2015-03-25 23:20:20 +01:00
commit 3d2eaf81db
3 changed files with 78 additions and 0 deletions

View file

@ -214,6 +214,7 @@ bool autostart;
FString StoredWarp; FString StoredWarp;
bool advancedemo; bool advancedemo;
FILE *debugfile; FILE *debugfile;
FILE *hashfile;
event_t events[MAXEVENTS]; event_t events[MAXEVENTS];
int eventhead; int eventhead;
int eventtail; int eventtail;
@ -2220,6 +2221,26 @@ void D_DoomMain (void)
execLogfile(logfile); execLogfile(logfile);
} }
if (Args->CheckParm("-hashfiles"))
{
FString 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");
}
}
D_DoomInit(); D_DoomInit();
PClass::StaticInit (); PClass::StaticInit ();
atterm(FinalGC); atterm(FinalGC);
@ -2289,6 +2310,11 @@ void D_DoomMain (void)
pwads.Clear(); pwads.Clear();
pwads.ShrinkToFit(); pwads.ShrinkToFit();
if (hashfile)
{
Printf("Notice: File hashing is incredibly verbose. Expect loading files to take much longer then usual.\n");
}
Printf ("W_Init: Init WADfiles.\n"); Printf ("W_Init: Init WADfiles.\n");
Wads.InitMultipleFiles (allwads); Wads.InitMultipleFiles (allwads);
allwads.Clear(); allwads.Clear();

View file

@ -172,6 +172,7 @@ extern bool playeringame[/*MAXPLAYERS*/];
// File handling stuff. // File handling stuff.
extern FILE* debugfile; extern FILE* debugfile;
extern FILE* hashfile;
// if true, load all graphics at level load // if true, load all graphics at level load
extern bool precache; extern bool precache;

View file

@ -56,6 +56,7 @@
#include "doomerrors.h" #include "doomerrors.h"
#include "resourcefiles/resourcefile.h" #include "resourcefiles/resourcefile.h"
#include "md5.h" #include "md5.h"
#include "doomstat.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
@ -300,6 +301,56 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo)
AddFile(path, embedded); AddFile(path, embedded);
} }
} }
if (hashfile)
{
BYTE cksum[16];
char cksumout[33];
memset(cksumout, 0, sizeof(cksumout));
FileReader *reader = wadinfo;
if (reader != NULL)
{
MD5Context md5;
reader->Seek(0, SEEK_SET);
md5.Update(reader, reader->GetLength());
md5.Final(cksum);
for (size_t j = 0; j < sizeof(cksum); ++j)
{
sprintf(cksumout + (j * 2), "%02X", cksum[j]);
}
fprintf(hashfile, "file: %s, hash: %s, size: %d\n", filename, cksumout, reader->GetLength());
}
else
fprintf(hashfile, "file: %s, Directory structure\n", filename);
for (DWORD i = 0; i < resfile->LumpCount(); i++)
{
FResourceLump *lump = resfile->GetLump(i);
if (!(lump->Flags & LUMPF_EMBEDDED))
{
reader = lump->NewReader();
MD5Context md5;
md5.Update(reader, lump->LumpSize);
md5.Final(cksum);
for (size_t j = 0; j < sizeof(cksum); ++j)
{
sprintf(cksumout + (j * 2), "%02X", cksum[j]);
}
fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %d\n", filename, lump->FullName ? lump->FullName : lump->Name, cksumout, lump->LumpSize);
delete reader;
}
}
}
return; return;
} }
} }