Created
March 11, 2011 17:00
-
-
Save chetmancini/866194 to your computer and use it in GitHub Desktop.
Compare the MD5 hashes of two files and return if their data is equal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses SysUtils, Classes, IdHashMessageDigest, idHash; | |
function TTesterApp.CompareHashes(const File1: string; const File2: string): Boolean; | |
function MD5(const FileName: string): string; | |
var | |
IDMD5: TIdHashMessageDigest5; | |
FileStream: TFileStream; | |
begin | |
idmd5 := TIdHashMessageDigest5.Create; | |
FileStream := TFileStream.Create(FileName, fmOpenRead OR fmShareDenyWrite); | |
try | |
Result := IDMD5.HashStreamAsHex(FileStream); | |
finally | |
FileStream.Free; | |
IDMD5.Free; | |
end; | |
end; | |
var | |
Hash1, Hash2: string; | |
File1, File2: string; | |
begin | |
if FileExists(File1) and FileExists(File2) then begin | |
HashDev := MD5(File1); | |
HashRelease := MD5(File2); | |
Result := SameText(Hash1, Hash2); | |
end else | |
raise Exception.Create('Files do not exist.'); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment