Reputation: 39
Im currently try to understand Inno Setup and Delphi.
The setup should only allow specific patches depending on the already installed software.
My setup has three patches:
Patch1: 1.0 - 2.0
Patch2: 1.0
Patch3: 1.1
For example my installed software has version 1.7. Then checkbox for Patch1 should be checked.
For version 1.0 only checkboxes for Patch1 and Patch2 should be checked and the other is unchecked.
I programmed it in the function below. I used the function from How to split a string in Inno Setup.
My question is how to implement it with "check parameter"-function like or how to implement it to with shorter function and more reusability.
Thanks!
[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
DefaultGroupName=My Program
UninstallDisplayIcon={app}\MyProg.exe
OutputDir=userdocs:Inno Setup Examples Output
[Types]
Name: Customized; Description: "Select Installations"; Flags: iscustom
[Components]
Name: "Parts"; Description: "Available Patches"; Types: Customized
Name: "Parts\1"; Description: "Version 1.0 - 2.0"; Types: Customized
Name: "Parts\2"; Description: "Version 1.0 "; Types: Customized
Name: "Parts\3"; Description: "Version 1.1)"; Types: Customized
[code]
procedure CurPageChanged(CurPageID: Integer);
var Value1: String;
i, p: Integer;
Dest: TArrayOfString;
Separator: String;
begin
i := 0;
Separator := '.'
// Change Value for testing
Value1 := '1.9'
repeat
SetArrayLength(Dest, i+1);
p := Pos(Separator,Value1);
if p > 0 then begin
Dest[i] := Copy(Value1, 1, p-1);
Value1 := Copy(Value1, p + Length(Separator), Length(Value1));
i := i + 1;
end else begin
Dest[i] := Value1;
Value1 := '';
end;
until Length(Value1)=0;
// 1.0 - 2.0
if (strtoint(Dest[0]) = 1) or (strtoint(Dest[0]) = 2) and (0 <= strtoint(Dest[1])) and (strtoint(Dest[1]) <= 9) then
begin
WizardForm.ComponentsList.Checked[1] := True;
WizardForm.ComponentsList.ItemEnabled[1] := True;
WizardForm.ComponentsList.Checked[2] := False;
WizardForm.ComponentsList.ItemEnabled[2] := False;
WizardForm.ComponentsList.Checked[3] := False;
WizardForm.ComponentsList.ItemEnabled[3] := False;
end;
// 1.0
if (strtoint(Dest[0]) = 1) and (strtoint(Dest[1]) = 0) then
begin
WizardForm.ComponentsList.Checked[1] := True;
WizardForm.ComponentsList.ItemEnabled[1] := True;
WizardForm.ComponentsList.Checked[2] := True;
WizardForm.ComponentsList.ItemEnabled[2] := True;
WizardForm.ComponentsList.Checked[3] := False;
WizardForm.ComponentsList.ItemEnabled[3] := False;
end;
// 1.1
if (strtoint(Dest[0]) = 1) and (1 = strtoint(Dest[1])) then
begin
WizardForm.ComponentsList.Checked[1] := True;
WizardForm.ComponentsList.ItemEnabled[1] := True;
WizardForm.ComponentsList.Checked[2] := False;
WizardForm.ComponentsList.ItemEnabled[2] := False;
WizardForm.ComponentsList.Checked[3] := True;
WizardForm.ComponentsList.ItemEnabled[3] := True;
end;
end;
procedure TypesCombo_OnChange(Sender: TObject);
begin
CurPageChanged(1);
end;
procedure InitializeWizard();
begin
WizardForm.TypesCombo.OnChange := @TypesCombo_OnChange;
end;
Upvotes: 0
Views: 115
Reputation: 202118
If you do not want to allow the user to select what to install, avoid complicating the installer with components. Use Check
parameter:
[Files]
Source: "Patch10to20.exe"; DestDir: "{app}"; Check: InstallPatch10to20
Source: "Patch10.exe"; DestDir: "{app}"; Check: InstallPatch10
Source: "Patch11.exe"; DestDir: "{app}"; Check: InstallPatch11
[Code]
var
InstalledVersion: string;
function InstallPatch10to20: Boolean;
begin
Result :=
(CompareVersion('1.0', InstalledVersion) <= 0) and
(CompareVersion(InstalledVersion, '2.0') <= 0);
end;
function InstallPatch10: Boolean;
begin
Result := (CompareVersion('1.0', InstalledVersion) = 0);
end;
function InstallPatch11: Boolean;
begin
Result := (CompareVersion('1.1', InstalledVersion) = 0);
end;
function InitializeSetup: Boolean;
begin
InstalledVersion := '1.9';
Result := True;
end;
The CompareVersion
comes from Compare version strings in Inno Setup. Or you can use (new) built-in ComparePackedVersion
function.
Upvotes: 1