mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 04:22:34 +00:00
- generate a hash identifier for each loaded resource file.
This is not useful by itself but can be used for adding new features later, e.g. mod-wide compatibility settings or file specific lump replacement or injection.
This commit is contained in:
parent
bcef440511
commit
31aa855a51
8 changed files with 42 additions and 2 deletions
|
@ -316,6 +316,7 @@ bool F7ZFile::Open(bool quiet)
|
||||||
|
|
||||||
if (!quiet && !batchrun) Printf(", %d lumps\n", NumLumps);
|
if (!quiet && !batchrun) Printf(", %d lumps\n", NumLumps);
|
||||||
|
|
||||||
|
GenerateHash();
|
||||||
PostProcessArchive(&Lumps[0], sizeof(F7ZLump));
|
PostProcessArchive(&Lumps[0], sizeof(F7ZLump));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ bool FGrpFile::Open(bool quiet)
|
||||||
Lumps[i].LumpNameSetup(fileinfo[i].NameWithZero);
|
Lumps[i].LumpNameSetup(fileinfo[i].NameWithZero);
|
||||||
}
|
}
|
||||||
if (!quiet && !batchrun) Printf(", %d lumps\n", NumLumps);
|
if (!quiet && !batchrun) Printf(", %d lumps\n", NumLumps);
|
||||||
|
GenerateHash();
|
||||||
delete[] fileinfo;
|
delete[] fileinfo;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,7 @@ bool FPakFile::Open(bool quiet)
|
||||||
Lumps[i].LumpSize = LittleLong(fileinfo[i].filelen);
|
Lumps[i].LumpSize = LittleLong(fileinfo[i].filelen);
|
||||||
Lumps[i].CheckEmbedded();
|
Lumps[i].CheckEmbedded();
|
||||||
}
|
}
|
||||||
|
GenerateHash();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -184,6 +184,7 @@ bool FRFFFile::Open(bool quiet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] lumps;
|
delete[] lumps;
|
||||||
|
GenerateHash();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -203,6 +203,7 @@ bool FWadFile::Open(bool quiet)
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] fileinfo;
|
delete[] fileinfo;
|
||||||
|
GenerateHash(); // Do this before the lump processing below.
|
||||||
|
|
||||||
if (!quiet)
|
if (!quiet)
|
||||||
{
|
{
|
||||||
|
|
|
@ -363,6 +363,7 @@ bool FZipFile::Open(bool quiet)
|
||||||
|
|
||||||
if (!quiet && !batchrun) Printf(TEXTCOLOR_NORMAL ", %d lumps\n", NumLumps);
|
if (!quiet && !batchrun) Printf(TEXTCOLOR_NORMAL ", %d lumps\n", NumLumps);
|
||||||
|
|
||||||
|
GenerateHash();
|
||||||
PostProcessArchive(&Lumps[0], sizeof(FZipLump));
|
PostProcessArchive(&Lumps[0], sizeof(FZipLump));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include "gi.h"
|
#include "gi.h"
|
||||||
#include "doomstat.h"
|
#include "doomstat.h"
|
||||||
#include "doomtype.h"
|
#include "doomtype.h"
|
||||||
|
#include "md5.h"
|
||||||
|
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
@ -353,6 +354,39 @@ int lumpcmp(const void * a, const void * b)
|
||||||
return rec1->FullName.CompareNoCase(rec2->FullName);
|
return rec1->FullName.CompareNoCase(rec2->FullName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//==========================================================================
|
||||||
|
//
|
||||||
|
// FResourceFile :: GenerateHash
|
||||||
|
//
|
||||||
|
// Generates a hash identifier for use in file identification.
|
||||||
|
// Potential uses are mod-wide compatibility settings or localization add-ons.
|
||||||
|
// This only hashes the lump directory but not the actual content
|
||||||
|
//
|
||||||
|
//==========================================================================
|
||||||
|
|
||||||
|
void FResourceFile::GenerateHash()
|
||||||
|
{
|
||||||
|
// hash the lump directory after sorting
|
||||||
|
|
||||||
|
Hash.Format(("%08X-%04X-"), (unsigned)Reader.GetLength(), NumLumps);
|
||||||
|
|
||||||
|
MD5Context md5;
|
||||||
|
|
||||||
|
uint8_t digest[16];
|
||||||
|
for(uint32_t i = 0; i < NumLumps; i++)
|
||||||
|
{
|
||||||
|
auto lump = GetLump(i);
|
||||||
|
md5.Update((const uint8_t*)lump->Name, strlen(lump->Name) + 1); // +1 to hash the terminating 0 as well.
|
||||||
|
md5.Update((const uint8_t*)lump->FullName.GetChars(), lump->FullName.Len() + 1);
|
||||||
|
md5.Update((const uint8_t*)&lump->LumpSize, 4);
|
||||||
|
}
|
||||||
|
md5.Final(digest);
|
||||||
|
for (auto c : digest)
|
||||||
|
{
|
||||||
|
Hash.AppendFormat("%02X", c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// FResourceFile :: PostProcessArchive
|
// FResourceFile :: PostProcessArchive
|
||||||
|
|
|
@ -85,11 +85,13 @@ public:
|
||||||
FString FileName;
|
FString FileName;
|
||||||
protected:
|
protected:
|
||||||
uint32_t NumLumps;
|
uint32_t NumLumps;
|
||||||
|
FString Hash;
|
||||||
|
|
||||||
FResourceFile(const char *filename);
|
FResourceFile(const char *filename);
|
||||||
FResourceFile(const char *filename, FileReader &r);
|
FResourceFile(const char *filename, FileReader &r);
|
||||||
|
|
||||||
// for archives that can contain directories
|
// for archives that can contain directories
|
||||||
|
void GenerateHash();
|
||||||
void PostProcessArchive(void *lumps, size_t lumpsize);
|
void PostProcessArchive(void *lumps, size_t lumpsize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue