From a2bfc5e9f4c66db6a29810c064b981d772aefb2a Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sun, 9 Nov 2008 16:06:45 +0100 Subject: Port CRC32 and MD5 functions to standard FreePascal RTL Added compat dir for Kylix compatibility --- UChecksumDruid.pas | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'UChecksumDruid.pas') diff --git a/UChecksumDruid.pas b/UChecksumDruid.pas index 18e4243..bbe0b73 100644 --- a/UChecksumDruid.pas +++ b/UChecksumDruid.pas @@ -76,7 +76,7 @@ var implementation -uses ULocale, UCoreUtils, ULibc, UCore, DateUtils, UConfig, StrUtils; +uses ULocale, UCoreUtils, ULibc, UCore, DateUtils, UConfig, StrUtils, md5, crc; procedure TFChecksumDruid.FormCreate(Sender: TObject); @@ -483,7 +483,8 @@ var FD: TEngineFileDes; Error, Count: integer; Buffer: Pointer; CRC: LongWord; - MD5Hash: THash_MD5; + MDContext: TMDContext; + MDDigest: TMDDigest; begin HashString := ''; Result := False; @@ -494,9 +495,8 @@ begin ErrorLabel.Caption := ErrorLabel.Caption + LANGAnErrorOccuredWhileInitializingMemoryBlock + #10; Exit; end; - CRC := $FFFFFFFF; - MD5Hash := nil; - if not IsItSFV then MD5Hash := THash_MD5.Create; + CRC := 0; + if not IsItSFV then MDInit(MDContext, MD_VERSION_5); FD := Engine.OpenFile(FName, omRead, Error); if Error <> 0 then begin @@ -511,7 +511,7 @@ begin Exit; end; if IsItSFV then CRC := CRC32(CRC, Buffer, Count) - else MD5Hash.Calc(Buffer^, Count); + else MDUpdate(MDContext, Buffer^, Count); Progress.Value := Progress.Value + Count; Progress.Text := Format('%d %%', [Trunc(Progress.Fraction * 100)]); Application.ProcessMessages; @@ -520,11 +520,10 @@ begin Engine.CloseFile(FD); libc_free(Buffer); - if IsItSFV then HashString := IntToHex(not CRC, 8) else + if IsItSFV then HashString := IntToHex(CRC, 8) else begin - MD5Hash.Done; - HashString := MD5Hash.GetKeyStrH; - MD5Hash.Free; + MDFinal(MDContext, MDDigest); + HashString := MDPrint(MDDigest); end; Result := True; end; -- cgit v1.2.3