MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / CalcFileSum

Function CalcFileSum

Libraries/unrar/filefn.cpp:361–431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359
360#if !defined(SFX_MODULE)
361void CalcFileSum(File *SrcFile,uint *CRC32,byte *Blake2,uint Threads,int64 Size,uint Flags)
362{
363 int64 SavePos=SrcFile->Tell();
364#ifndef SILENT
365 int64 FileLength=Size==INT64NDF ? SrcFile->FileLength() : Size;
366#endif
367
368 if ((Flags & (CALCFSUM_SHOWTEXT|CALCFSUM_SHOWPERCENT))!=0)
369 uiMsg(UIEVENT_FILESUMSTART);
370
371 if ((Flags & CALCFSUM_CURPOS)==0)
372 SrcFile->Seek(0,SEEK_SET);
373
374 const size_t BufSize=0x100000;
375 Array<byte> Data(BufSize);
376
377
378 DataHash HashCRC,HashBlake2;
379 HashCRC.Init(HASH_CRC32,Threads);
380 HashBlake2.Init(HASH_BLAKE2,Threads);
381
382 int64 BlockCount=0;
383 int64 TotalRead=0;
384 while (true)
385 {
386 size_t SizeToRead;
387 if (Size==INT64NDF) // If we process the entire file.
388 SizeToRead=BufSize; // Then always attempt to read the entire buffer.
389 else
390 SizeToRead=(size_t)Min((int64)BufSize,Size);
391 int ReadSize=SrcFile->Read(&Data[0],SizeToRead);
392 if (ReadSize==0)
393 break;
394 TotalRead+=ReadSize;
395
396 if ((++BlockCount & 0xf)==0)
397 {
398#ifndef SILENT
399 if ((Flags & CALCFSUM_SHOWPROGRESS)!=0)
400 uiExtractProgress(TotalRead,FileLength,TotalRead,FileLength);
401 else
402 {
403 if ((Flags & CALCFSUM_SHOWPERCENT)!=0)
404 uiMsg(UIEVENT_FILESUMPROGRESS,ToPercent(TotalRead,FileLength));
405 }
406#endif
407 Wait();
408 }
409
410 if (CRC32!=NULL)
411 HashCRC.Update(&Data[0],ReadSize);
412 if (Blake2!=NULL)
413 HashBlake2.Update(&Data[0],ReadSize);
414
415 if (Size!=INT64NDF)
416 Size-=ReadSize;
417 }
418 SrcFile->Seek(SavePos,SEEK_SET);

Callers 4

RestoreMethod · 0.85
TestMethod · 0.85
RestoreMethod · 0.85
TestMethod · 0.85

Calls 12

uiMsgFunction · 0.85
ToPercentFunction · 0.85
WaitFunction · 0.85
FileLengthMethod · 0.80
GetCRC32Method · 0.80
ResultMethod · 0.80
uiExtractProgressFunction · 0.70
TellMethod · 0.45
SeekMethod · 0.45
InitMethod · 0.45
ReadMethod · 0.45
UpdateMethod · 0.45

Tested by 2

TestMethod · 0.68
TestMethod · 0.68