Skip to content

Commit

Permalink
use the FResourceFile interface in favor of FResourceLump's where pos…
Browse files Browse the repository at this point in the history
…sible.
  • Loading branch information
coelckers committed Dec 10, 2023
1 parent 5c04185 commit 749d4e3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/common/filesystem/include/fs_filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ class FileSystem
int AddFromBuffer(const char* name, const char* type, char* data, int size, int id, int flags);
FileReader* GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD
void InitHashChains();
FResourceLump* GetFileAt(int no);

protected:

Expand Down
5 changes: 5 additions & 0 deletions src/common/filesystem/include/resourcefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,12 @@ class FResourceFile
{
auto l = GetLump(entry);
return l ? l->NewReader() : FileReader();
}

int GetEntryFlags(int entry)
{
auto l = GetLump(entry);
return l ? l->Flags : 0;
}

ResourceData Read(int entry)
Expand Down
27 changes: 8 additions & 19 deletions src/common/filesystem/source/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,13 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf

for (uint32_t i=0; i < resfile->EntryCount(); i++)
{
FResourceLump *lump = resfile->GetLump(i);
if (lump->Flags & LUMPF_EMBEDDED)
int flags = resfile->GetEntryFlags(i);
if (flags & LUMPF_EMBEDDED)
{
std::string path = filename;
path += ':';
path += lump->getName();
auto embedded = lump->NewReader();
path += resfile->getName(i);
auto embedded = resfile->GetEntryReader(i, true);
AddFile(path.c_str(), &embedded, filter, Printf, hashfile);
}
}
Expand Down Expand Up @@ -456,19 +456,18 @@ void FileSystem::AddFile (const char *filename, FileReader *filer, LumpFilterInf

for (uint32_t i = 0; i < resfile->EntryCount(); i++)
{
FResourceLump *lump = resfile->GetLump(i);

if (!(lump->Flags & LUMPF_EMBEDDED))
int flags = resfile->GetEntryFlags(i);
if (!(flags & LUMPF_EMBEDDED))
{
auto reader = lump->NewReader();
auto reader = resfile->GetEntryReader(i, true);
md5Hash(filereader, cksum);

for (size_t j = 0; j < sizeof(cksum); ++j)
{
snprintf(cksumout + (j * 2), 3, "%02X", cksum[j]);
}

fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %d\n", filename, lump->getName(), cksumout, lump->LumpSize);
fprintf(hashfile, "file: %s, lump: %s, hash: %s, size: %llu\n", filename, resfile->getName(i), cksumout, (uint64_t)resfile->Length(i));
}
}
}
Expand Down Expand Up @@ -1592,15 +1591,5 @@ static void PrintLastError (FileSystemMessageFunc Printf)
}
#endif

//==========================================================================
//
// NBlood style lookup functions
//
//==========================================================================

FResourceLump* FileSystem::GetFileAt(int no)
{
return FileInfo[no].lump;
}

}
11 changes: 6 additions & 5 deletions src/common/filesystem/source/resourcefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,13 @@ int lumpcmp(const void * a, const void * b)
//
// 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
// This only hashes the directory but not the actual content
//
//==========================================================================

void FResourceFile::GenerateHash()
{
// hash the lump directory after sorting
// hash the directory after sorting
using namespace FileSys::md5;

auto n = snprintf(Hash, 48, "%08X-%04X-", (unsigned)Reader.GetLength(), NumLumps);
Expand All @@ -377,9 +377,10 @@ void FResourceFile::GenerateHash()
uint8_t digest[16];
for(uint32_t i = 0; i < NumLumps; i++)
{
auto lump = GetLump(i);
md5_append(&state, (const uint8_t*)lump->FullName, (unsigned)strlen(lump->FullName) + 1);
md5_append(&state, (const uint8_t*)&lump->LumpSize, 4);
auto name = getName(i);
auto size = Length(i);
md5_append(&state, (const uint8_t*)name, (unsigned)strlen(name) + 1);
md5_append(&state, (const uint8_t*)&size, sizeof(size));
}
md5_finish(&state, digest);
for (auto c : digest)
Expand Down

0 comments on commit 749d4e3

Please sign in to comment.