I would like to check MD5 of a file with this code:
[Code]
var
MD5Comp: string;
procedure ExitProcess(uExitCode:UINT);
external '[email protected] stdcall';
procedure CurStepChanged(CurStep: TSetupStep);
begin
MD5Comp := '32297BCBF4D802298349D06AF5E28059';
if CurStep = ssInstall then
begin
if not MD5Comp=GetMD5OfFile(ExpandConstant('{app}\cg.npa')) then
begin
MsgBox('A patched version detected. Setup will now exit.', mbInformation, MB_OK);
ExitProcess(1);
end;
end;
end;
But I get a "Type Mismatch" error when comparing the two string, so I am assuming that this is not how you compare them.
Edit: I've tried if not CompareText(MD5Comp,GetMD5OfFile(ExpandConstant('{app}\cg.npa')))=0
but it never execute what's inside the if.
This seems to be an exception of the Pascal Script compiler. You were expecting an expression like this (assume S1
and S2
are string
variables):
if not (S1 = S2) then
But the compiler treated it like this instead:
if (not S1) = S2 then
Well, I would personally expect a compiler error instead of runtime one here. At least you have simple way to workaround this issue if you explicitly enclose that comparison into parentheses like:
if not (MD5Comp = GetMD5OfFile(ExpandConstant('{app}\cg.npa'))) then
Or optionally write more literally:
if MD5Comp <> GetMD5OfFile(ExpandConstant('{app}\cg.npa')) then
Do note, that in this case the parentheses are not needed because with the <>
operator it becomes a single boolean expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With