Added -hashfiles command
This commit is contained in:
parent
502120e78f
commit
bf6cdba0bb
3 changed files with 78 additions and 0 deletions
|
|
@ -56,6 +56,7 @@
|
|||
#include "doomerrors.h"
|
||||
#include "resourcefiles/resourcefile.h"
|
||||
#include "md5.h"
|
||||
#include "doomstat.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
@ -300,6 +301,56 @@ void FWadCollection::AddFile (const char *filename, FileReader *wadinfo)
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue