forked from Mirrors/openclonk
Rename C4Group_GetFileCRC/SHA1 to GetFileCRC/SHA1
These functions aren't used for files in groups and consequently broken for them. Remove the dead code.
parent
a135349703
commit
b660f093fc
|
@ -47,7 +47,6 @@
|
|||
#include <StdPNG.h>
|
||||
#include <zlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
|
||||
//------------------------------ File Sort Lists -------------------------------------------
|
||||
|
@ -410,82 +409,6 @@ bool C4Group_ReadFile(const char *szFile, char **pData, size_t *iSize)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool C4Group_GetFileCRC(const char *szFilename, uint32_t *pCRC32)
|
||||
{
|
||||
if (!pCRC32) return false;
|
||||
// doesn't exist physically?
|
||||
char szPath[_MAX_PATH + 1];
|
||||
if (FileExists(szFilename))
|
||||
SCopy(szFilename, szPath, _MAX_PATH);
|
||||
else
|
||||
{
|
||||
// Expect file to be packed: Extract to temporary
|
||||
SCopy(GetFilename(szFilename), szPath, _MAX_PATH);
|
||||
MakeTempFilename(szPath);
|
||||
if (!C4Group_CopyItem(szFilename, szPath)) return false;
|
||||
}
|
||||
// open file
|
||||
CStdFile File;
|
||||
if (!File.Open(szFilename))
|
||||
return false;
|
||||
// calculcate CRC
|
||||
uint32_t iCRC32 = 0;
|
||||
for (;;)
|
||||
{
|
||||
// read a chunk of data
|
||||
BYTE szData[CStdFileBufSize]; size_t iSize = 0;
|
||||
if (!File.Read(szData, CStdFileBufSize, &iSize))
|
||||
if (!iSize)
|
||||
break;
|
||||
// update CRC
|
||||
iCRC32 = crc32(iCRC32, szData, iSize);
|
||||
}
|
||||
// close file
|
||||
File.Close();
|
||||
// okay
|
||||
*pCRC32 = iCRC32;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool C4Group_GetFileSHA1(const char *szFilename, BYTE *pSHA1)
|
||||
{
|
||||
if (!pSHA1) return false;
|
||||
// doesn't exist physically?
|
||||
char szPath[_MAX_PATH + 1];
|
||||
if (FileExists(szFilename))
|
||||
SCopy(szFilename, szPath, _MAX_PATH);
|
||||
else
|
||||
{
|
||||
// Expect file to be packed: Extract to temporary
|
||||
SCopy(GetFilename(szFilename), szPath, _MAX_PATH);
|
||||
MakeTempFilename(szPath);
|
||||
if (!C4Group_CopyItem(szFilename, szPath)) return false;
|
||||
}
|
||||
// open file
|
||||
CStdFile File;
|
||||
if (!File.Open(szFilename))
|
||||
return false;
|
||||
// calculcate CRC
|
||||
SHA_CTX ctx;
|
||||
if (!SHA1_Init(&ctx)) return false;
|
||||
for (;;)
|
||||
{
|
||||
// read a chunk of data
|
||||
BYTE szData[CStdFileBufSize]; size_t iSize = 0;
|
||||
if (!File.Read(szData, CStdFileBufSize, &iSize))
|
||||
if (!iSize)
|
||||
break;
|
||||
// update CRC
|
||||
if (!SHA1_Update(&ctx, szData, iSize))
|
||||
return false;
|
||||
}
|
||||
// close file
|
||||
File.Close();
|
||||
// finish calculation
|
||||
SHA1_Final(pSHA1, &ctx);
|
||||
return true;
|
||||
}
|
||||
|
||||
void MemScramble(BYTE *bypBuffer, int iSize)
|
||||
{
|
||||
int cnt; BYTE temp;
|
||||
|
@ -1322,7 +1245,7 @@ bool C4Group::View(const char *szFiles)
|
|||
|
||||
// Calculate group file crc
|
||||
uint32_t crc = 0;
|
||||
C4Group_GetFileCRC(GetFullName().getData(), &crc);
|
||||
GetFileCRC(GetFullName().getData(), &crc);
|
||||
|
||||
// Display list
|
||||
ResetSearch();
|
||||
|
|
|
@ -82,8 +82,6 @@ bool C4Group_UnpackDirectory(const char *szFilename);
|
|||
bool C4Group_ExplodeDirectory(const char *szFilename);
|
||||
bool C4Group_SetOriginal(const char *szFilename, bool fOriginal);
|
||||
bool C4Group_ReadFile(const char *szFilename, char **pData, size_t *iSize);
|
||||
bool C4Group_GetFileCRC(const char *szFilename, uint32_t *pCRC32);
|
||||
bool C4Group_GetFileSHA1(const char *szFilename, BYTE *pSHA1);
|
||||
|
||||
extern const char *C4CFN_FLS[];
|
||||
|
||||
|
|
|
@ -360,7 +360,7 @@ bool C4UpdatePackage::Execute(C4Group *pGroup)
|
|||
return false;*/
|
||||
// check checksum
|
||||
uint32_t iCRC32;
|
||||
if (!C4Group_GetFileCRC(TargetGrp.GetFullName().getData(), &iCRC32))
|
||||
if (!GetFileCRC(TargetGrp.GetFullName().getData(), &iCRC32))
|
||||
return false;
|
||||
int i = 0;
|
||||
for (; i < UpGrpCnt; i++)
|
||||
|
@ -394,7 +394,7 @@ bool C4UpdatePackage::Execute(C4Group *pGroup)
|
|||
{
|
||||
// check the result
|
||||
uint32_t iResChks;
|
||||
if (!C4Group_GetFileCRC(strTarget, &iResChks))
|
||||
if (!GetFileCRC(strTarget, &iResChks))
|
||||
return false;
|
||||
if (iResChks != GrpChks2)
|
||||
{
|
||||
|
@ -468,7 +468,7 @@ int C4UpdatePackage::Check(C4Group *pGroup)
|
|||
|
||||
// check source crc
|
||||
uint32_t iCRC32;
|
||||
if (!C4Group_GetFileCRC(DestPath, &iCRC32))
|
||||
if (!GetFileCRC(DestPath, &iCRC32))
|
||||
return C4UPD_CHK_BAD_SOURCE;
|
||||
// equal to destination group?
|
||||
if (iCRC32 == GrpChks2)
|
||||
|
@ -664,9 +664,9 @@ bool C4UpdatePackage::MakeUpdate(const char *strFile1, const char *strFile2, con
|
|||
sprintf(Name, "%s Update", GetFilename(strFile1));
|
||||
SCopy(strFile1, DestPath, _MAX_PATH);
|
||||
GrpUpdate = true;
|
||||
if (!C4Group_GetFileCRC(strFile1, &GrpChks1[UpGrpCnt]))
|
||||
if (!GetFileCRC(strFile1, &GrpChks1[UpGrpCnt]))
|
||||
{ WriteLog("Error: could not calc checksum for %s!\n", strFile1); return false; }
|
||||
if (!C4Group_GetFileCRC(strFile2, &GrpChks2))
|
||||
if (!GetFileCRC(strFile2, &GrpChks2))
|
||||
{ WriteLog("Error: could not calc checksum for %s!\n", strFile2); return false; }
|
||||
if (fContinued)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <openssl/sha.h>
|
||||
|
||||
CStdFile::CStdFile()
|
||||
{
|
||||
|
@ -333,3 +334,57 @@ size_t CStdFile::AccessedEntrySize()
|
|||
assert(!hgzFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GetFileCRC(const char *szFilename, uint32_t *pCRC32)
|
||||
{
|
||||
if (!pCRC32) return false;
|
||||
// open file
|
||||
CStdFile File;
|
||||
if (!File.Open(szFilename))
|
||||
return false;
|
||||
// calculcate CRC
|
||||
uint32_t iCRC32 = 0;
|
||||
for (;;)
|
||||
{
|
||||
// read a chunk of data
|
||||
BYTE szData[CStdFileBufSize]; size_t iSize = 0;
|
||||
if (!File.Read(szData, CStdFileBufSize, &iSize))
|
||||
if (!iSize)
|
||||
break;
|
||||
// update CRC
|
||||
iCRC32 = crc32(iCRC32, szData, iSize);
|
||||
}
|
||||
// close file
|
||||
File.Close();
|
||||
// okay
|
||||
*pCRC32 = iCRC32;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GetFileSHA1(const char *szFilename, BYTE *pSHA1)
|
||||
{
|
||||
if (!pSHA1) return false;
|
||||
// open file
|
||||
CStdFile File;
|
||||
if (!File.Open(szFilename))
|
||||
return false;
|
||||
// calculcate CRC
|
||||
SHA_CTX ctx;
|
||||
if (!SHA1_Init(&ctx)) return false;
|
||||
for (;;)
|
||||
{
|
||||
// read a chunk of data
|
||||
BYTE szData[CStdFileBufSize]; size_t iSize = 0;
|
||||
if (!File.Read(szData, CStdFileBufSize, &iSize))
|
||||
if (!iSize)
|
||||
break;
|
||||
// update CRC
|
||||
if (!SHA1_Update(&ctx, szData, iSize))
|
||||
return false;
|
||||
}
|
||||
// close file
|
||||
File.Close();
|
||||
// finish calculation
|
||||
SHA1_Final(pSHA1, &ctx);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -78,5 +78,7 @@ protected:
|
|||
};
|
||||
|
||||
int UncompressedFileSize(const char *szFileName);
|
||||
bool GetFileCRC(const char *szFilename, uint32_t *pCRC32);
|
||||
bool GetFileSHA1(const char *szFilename, BYTE *pSHA1);
|
||||
|
||||
#endif // INC_CSTDFILE
|
||||
|
|
|
@ -224,7 +224,7 @@ bool C4Record::Stop(StdStrBuf *pRecordName, BYTE *pRecordSHA1)
|
|||
if (pRecordName)
|
||||
pRecordName->Copy(sFilename);
|
||||
if (pRecordSHA1)
|
||||
if (!C4Group_GetFileSHA1(sFilename.getData(), pRecordSHA1))
|
||||
if (!GetFileSHA1(sFilename.getData(), pRecordSHA1))
|
||||
return false;
|
||||
|
||||
// ok
|
||||
|
|
|
@ -396,7 +396,7 @@ bool C4Network2Res::SetByFile(const char *strFilePath, bool fTemp, C4Network2Res
|
|||
{ if (!fSilent) LogF("SetByFile: file %s not found!", strFilePath); return false; }
|
||||
// calc checksum
|
||||
uint32_t iCRC32;
|
||||
if (!C4Group_GetFileCRC(szFullFile.getData(), &iCRC32)) return false;
|
||||
if (!GetFileCRC(szFullFile.getData(), &iCRC32)) return false;
|
||||
#ifdef C4NET2RES_DEBUG_LOG
|
||||
// log
|
||||
LogSilentF("Network: Resource: complete %d:%s is file %s (%s)", iResID, szResName, szFile, fTemp ? "temp" : "static");
|
||||
|
@ -658,7 +658,7 @@ bool C4Network2Res::GetStandalone(char *pTo, int32_t iMaxL, bool fSetOfficial, b
|
|||
|
||||
// calc checksum
|
||||
uint32_t iCRC32;
|
||||
if (!C4Group_GetFileCRC(szStandalone, &iCRC32))
|
||||
if (!GetFileCRC(szStandalone, &iCRC32))
|
||||
{ if (!fSilent) Log("GetStandalone: could not calculate checksum!"); return false; }
|
||||
// set / check
|
||||
if (!fSetOfficial && iCRC32 != Core.getFileCRC())
|
||||
|
@ -688,7 +688,7 @@ bool C4Network2Res::CalculateSHA()
|
|||
SCopy(szFile, szStandalone, _MAX_PATH);
|
||||
// get the hash
|
||||
BYTE hash[SHA_DIGEST_LENGTH];
|
||||
if (!C4Group_GetFileSHA1(szStandalone, hash))
|
||||
if (!GetFileSHA1(szStandalone, hash))
|
||||
return false;
|
||||
// save it back
|
||||
Core.SetFileSHA(hash);
|
||||
|
|
Loading…
Reference in New Issue