From e04dc6ded7c3ca015095f7826aeb63804624abed Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Thu, 30 Apr 2020 17:39:24 +0200 Subject: Add crc to CC4Group_EntryInfo --- examples/c4ls.c | 2 +- src/cc4group.c | 17 ++++++++++++++++- src/cc4group.h | 3 +++ src/cppc4group.cpp | 1 + src/cppc4group.hpp | 1 + 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/examples/c4ls.c b/examples/c4ls.c index 20b1aca..cd2e6d0 100644 --- a/examples/c4ls.c +++ b/examples/c4ls.c @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) { for(size_t i = 0; i < entries; ++i) { - printf("%c %s %s %s\t%s\n", infos[i].directory ? 'd' : infos[i].executable ? 'x' : ' ', formatTime(infos[i].modified), formatSize(infos[i].totalSize), infos[i].fileName, infos[i].author); + printf("%c %s %s %08X %s\t%s\n", infos[i].directory ? 'd' : infos[i].executable ? 'x' : ' ', formatTime(infos[i].modified), formatSize(infos[i].totalSize), infos[i].crc, infos[i].fileName, infos[i].author); } free(infos); diff --git a/src/cc4group.c b/src/cc4group.c index bd0ea1a..0435c72 100644 --- a/src/cc4group.c +++ b/src/cc4group.c @@ -3089,6 +3089,20 @@ static bool cc4group_getEntryInfoForEntry(CC4Group* const this, const C4GroupEnt } } + uint32_t crc = entry->core.CRC; + if(entry->core.HasCRC != C4GroupEntryCore_ContentsFileNameCRC) + { + if(lazy) + { + crc = 0; + } + else + { + cc4group_calculateEntryCRC(this, (C4GroupEntryData*)entry); + crc = entry->core.CRC; + } + } + C4GroupHeader* headerOrParentHeader = header != NULL ? header : entry->parent != NULL ? entry->parent->header : NULL; *info = (CC4Group_EntryInfo){ @@ -3099,7 +3113,8 @@ static bool cc4group_getEntryInfoForEntry(CC4Group* const this, const C4GroupEnt .totalSize = entry->core.Size, .executable = entry->core.Executable ? true : false, .directory = entry->core.Directory ? true : false, - .official = headerOrParentHeader != NULL ? C4GroupHeader_isOfficial(headerOrParentHeader) : false + .official = headerOrParentHeader != NULL ? C4GroupHeader_isOfficial(headerOrParentHeader) : false, + .crc = crc }; return true; diff --git a/src/cc4group.h b/src/cc4group.h index d06f636..f54811b 100644 --- a/src/cc4group.h +++ b/src/cc4group.h @@ -107,6 +107,9 @@ typedef struct { // cc4group can modify official groups in the usual ways and can change groups' "official" status through the setOfficial method // users of cc4group should honor and change the "official" status how they think is appropriate (or simply ignore it) bool official; + + // the crc checksum, recalculated to C4GroupEntryCore_ContentsFileNameCRC if it is old or not calculated yet + uint32_t crc; } CC4Group_EntryInfo; diff --git a/src/cppc4group.cpp b/src/cppc4group.cpp index b76767b..7864413 100644 --- a/src/cppc4group.cpp +++ b/src/cppc4group.cpp @@ -410,6 +410,7 @@ namespace { info.executable = entryInfo.executable; info.directory = entryInfo.directory; info.official = entryInfo.official; + info.crc = entryInfo.crc; return info; } diff --git a/src/cppc4group.hpp b/src/cppc4group.hpp index e8f7ba1..2c1f6c1 100644 --- a/src/cppc4group.hpp +++ b/src/cppc4group.hpp @@ -50,6 +50,7 @@ public: bool executable; bool directory; bool official; + uint32_t crc; }; // this struct is used in custom tmp memory strategies -- cgit v1.2.3-54-g00ecf