Skip to content

Instantly share code, notes, and snippets.

@chetmancini
Created March 11, 2011 17:00
Show Gist options
  • Save chetmancini/866194 to your computer and use it in GitHub Desktop.
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.
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