[Setup]
AppName=My Application
AppVersion=1.5
DefaultDirName={pf}\My Application
[_Code]
function CompareVersion(s1, s2: string): integer;
var
iVer1, iVer2, iVer3, iVer4, cVer1, cVer2, cVer3, cVer4, tmp: string;
begin
Result := -1;
iVer1 := Copy(s1, 0, Pos('.', s1)-1);
tmp := Copy(s1, Pos(iVer1, s1)+Length(iVer1)+1, Length(s1));
iVer2 := Copy(tmp, 0, Pos('.', tmp)-1);
tmp := Copy(s1, Pos(iVer2, s1)+Length(iVer2)+1, Length(s1));
iVer3 := Copy(tmp, 0, Pos('.', tmp)-1);
iVer4 := Copy(s1, Pos(iVer3, s1)+Length(iVer3)+1, Length(s1));
cVer1 := Copy(s2, 0, Pos('.', s2)-1);
tmp := Copy(s2, Pos(cVer1, s2)+Length(cVer1)+1, Length(s2));
cVer2 := Copy(tmp, 0, Pos('.', tmp)-1);
tmp := Copy(s2, Pos(cVer2, s2)+Length(cVer2)+1, Length(s2));
cVer3 := Copy(tmp, 0, Pos('.', tmp)-1);
cVer4 := Copy(s2, Pos(cVer3, s2)+Length(cVer3)+1, Length(s2));
if (StrToInt(iVer1) > StrToInt(cVer1)) then Result := 1 else
if (StrToInt(iVer1) = StrToInt(cVer1)) then
if (StrToInt(iVer2) > StrToInt(cVer2)) then Result := 1 else
if (StrToInt(iVer2) = StrToInt(cVer2)) then
if (StrToInt(iVer3) > StrToInt(cVer3)) then Result := 1 else
if (StrToInt(iVer3) = StrToInt(cVer3)) then
if (StrToInt(iVer4) > StrToInt(cVer4)) then Result := 1 else
if (StrToInt(iVer1) = StrToInt(cVer1)) then
if (StrToInt(iVer2) = StrToInt(cVer2)) then
if (StrToInt(iVer3) = StrToInt(cVer3)) then
if (StrToInt(iVer4) = StrToInt(cVer4)) then Result := 0;
end;
function InitializeSetup(): Boolean;
var
sFile, sVer: string;
begin
sFile := ExpandConstant('{reg:HKLM\SOFTWARE\Test,PATH_APPLICATION}\Test.exe');
Result := FileExists(sFile);
if not result then MsgBox('Установка прекращена, Test.ехе не найден', mbCriticalError, MB_OK) else
begin
GetVersionNumbersString(sFile, sVer);
if CompareVersion(sVer, '1.3.0.0') > 0 then Result := True else
begin
MsgBox('Установка прекращена, не соответствует версия', mbCriticalError, MB_OK);
Result := False;
end;
end;
end;