Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare two strings inno setup

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.

like image 319
Cypert Avatar asked Dec 25 '22 16:12

Cypert


1 Answers

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.

like image 103
TLama Avatar answered Jan 13 '23 10:01

TLama