如何使用多个单选按钮在Inno设置中执行文件?

时间:2013-08-06 01:33:23

标签: inno-setup

如何使用Inno将file1.exe,file2.exe和file3.exe包装在单个安装文件中,以便在用户选择相关的单选按钮时启动选择文件?

请查看我正在努力完成的完整脚本。由于[文件]或任何类型的过程和监听器上没有检查标志,因此单击“下一步” - 所有3个文件将一个接一个地启动。

===

[Setup]   
CreateAppDir=no   
OutputDir=C:\Single-Exe   
OutputBaseFilename=setup   
Compression=lzma   
SolidCompression=yes   
DisableWelcomePage=True   
DisableReadyPage=True   
DisableFinishedPage=True   
Uninstallable=no

[Languages]
Name: english; MessagesFile: compiler:Default.isl

[Files]
Source: file1.exe; DestDir: {app};
Source: file2.exe; DestDir: {app};
Source: file3.exe; DestDir: {app};

[Run]
Filename: {app}\file1.exe; Flags: hidewizard runhidden 32bit; WorkingDir: {localappdata}
Filename: {app}\file2.exe; Flags: hidewizard runhidden 32bit; WorkingDir: {localappdata}
Filename: {app}\file3.exe; Flags: hidewizard runhidden 64bit; WorkingDir: {localappdata}

[Code]
const
  FileOneDesc =
    'Select if you want to run File1.exe';
  FileTwoDesc =
    'Select if you want to run File2.exe';
  FileThreeDesc =
    'Select if you want to run File3.exe';

var
  FileOneButton: TNewRadioButton;
  FileTwoButton: TNewRadioButton;
  FileThreeButton: TNewRadioButton;

procedure InitializeWizard;
var                                                 
  CustomPage: TWizardPage;
  FileOneDesclabel: TLabel;
  FileTwoDesclabel: TLabel;
  FileThreeDesclabel: TLabel;

begin
  CustomPage := CreateCustomPage(wpWelcome, 'Multiple executable pre-launch wizard', '');
  FileOneButton := TNewRadioButton.Create(WizardForm);
  FileOneButton.Parent := CustomPage.Surface;
  FileOneButton.Top := 16;     
  FileOneButton.Width := CustomPage.SurfaceWidth;
  FileOneButton.Font.Style := [fsBold];
  FileOneButton.Font.Size := 9;
  FileOneButton.Caption := 'Run File #1'
  FileOneDescLabel := TLabel.Create(WizardForm);
  FileOneDescLabel.Parent := CustomPage.Surface;
  FileOneDescLabel.Left := 8;
  FileOneDescLabel.Top := FileOneButton.Top + FileOneButton.Height + 8;
  FileOneDescLabel.Width := CustomPage.SurfaceWidth;
  FileOneDescLabel.Height := 40;
  FileOneDescLabel.AutoSize := False;
  FileOneDescLabel.Wordwrap := True;
  FileOneDescLabel.Caption := FileOneDesc;

  FileTwoButton := TNewRadioButton.Create(WizardForm);
  FileTwoButton.Parent := CustomPage.Surface;
  FileTwoButton.Top := FileOneDesclabel.Top + FileOneDesclabel.Height + 8;
  FileTwoButton.Width := CustomPage.SurfaceWidth;
  FileTwoButton.Font.Style := [fsBold];
  FileTwoButton.Font.Size := 9;
  FileTwoButton.Caption := 'Run File #2'
  FileTwoDescLabel := TLabel.Create(WizardForm);
  FileTwoDescLabel.Parent := CustomPage.Surface;
  FileTwoDescLabel.Left := 8;
  FileTwoDescLabel.Top := FileTwoButton.Top + FileTwoButton.Height + 8;
  FileTwoDescLabel.Width := CustomPage.SurfaceWidth;
  FileTwoDescLabel.Height := 40;
  FileTwoDescLabel.AutoSize := False;
  FileTwoDescLabel.Wordwrap := True;
  FileTwoDescLabel.Caption := FileTwoDesc;

  FileThreeButton := TNewRadioButton.Create(WizardForm);
  FileThreeButton.Parent := CustomPage.Surface;
  FileThreeButton.Top := FileTwoDesclabel.Top + FileTwoDesclabel.Height + 10;
  FileThreeButton.Width := CustomPage.SurfaceWidth;
  FileThreeButton.Font.Style := [fsBold];
  FileThreeButton.Font.Size := 9;
  FileThreeButton.Caption := 'Run File #3'
  FileThreeDescLabel := TLabel.Create(WizardForm);
  FileThreeDescLabel.Parent := CustomPage.Surface;
  FileThreeDescLabel.Left := 8;
  FileThreeDescLabel.Top := FileThreeButton.Top + FileThreeButton.Height + 8;
  FileThreeDescLabel.Width := CustomPage.SurfaceWidth;
  FileThreeDescLabel.Height := 40;
  FileThreeDescLabel.AutoSize := False;
  FileThreeDescLabel.Wordwrap := True;
  FileThreeDescLabel.Caption := FileThreeDesc;
  end;

1 个答案:

答案 0 :(得分:3)

[Run]部分具有Check参数,就像其条目分为参数的所有其他部分一样。在你的情况下,我会写一个像这样的常用检查函数:

[Run]
Filename: {app}\file1.exe; Flags: hidewizard runhidden 32bit; WorkingDir: {localappdata}; Check: ShouldRunItem(1)
Filename: {app}\file2.exe; Flags: hidewizard runhidden 32bit; WorkingDir: {localappdata}; Check: ShouldRunItem(2)
Filename: {app}\file3.exe; Flags: hidewizard runhidden 64bit; WorkingDir: {localappdata}; Check: ShouldRunItem(3)
...

[Code]
function ShouldRunItem(Value: Integer): Boolean;
begin
  Result := False;
  case Value of
    1: Result := FileOneButton.Checked;
    2: Result := FileTwoButton.Checked;
    3: Result := FileThreeButton.Checked;
  end;
end;