使用Inno Setup的单选按钮:定义将要安装的文件

时间:2012-09-08 01:18:20

标签: installation inno-setup

使用InnoSetup生成的单个可执行文件(带有“IconMain.ico”)和单个卸载(带有不同的图标“IconUninst.ico”),我想在驱动器“C”和“K”中安装一些文件”。不允许用户更改驱动器路径/名称,如:

STANDART RADIOBUTTON - 
Full installation. Files that will be installed in drive "C:" AND "K:"

- Game.exe     --> DRIVE C:\games
- Mapping.exe  --> DRIVE C:\Mapping
- Pics.dll     --> DRIVE C:\Pics 
- AAA.dll      --> DRIVE K:\Sounds
- BBB.obj      --> DRIVE K:\Sounds

ADVANCED RADIONBUTTON -
Partial installation. 
The only files that will be installed. (IF user agrees to continue)

- AAA.dll      --> DRIVE K:\Sounds
- BBB.obj      --> DRIVE K:\Sounds

我该如何实现? 谢谢!

2 个答案:

答案 0 :(得分:8)

要有条件地安装某个文件,您需要使用Check参数。您需要将True返回到表达式或函数以安装项目,返回False以跳过。您之前作业的示例显示在我在上一句中链接的参考页面中。

因此,要将它与您提到的custom installation type radio buttons结合使用,您只需要创建一个将分配给支票的功能,并根据所选的单选按钮返回其结果。

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Files]
; these two items will be installed always
Source: "AAA.dll"; DestDir: "K:\Sounds"
Source: "BBB.obj"; DestDir: "K:\Sounds"
; these three items will be installed only when the IsFullInstallation
; function returns True, what will depend on the selected radio button
Source: "Game.exe"; DestDir: "C:\Games"; Check: IsFullInstallation;
Source: "Mapping.exe"; DestDir: "C:\Mapping"; Check: IsFullInstallation;
Source: "Pics.dll"; DestDir: "C:\Pics"; Check: IsFullInstallation;

[Code]    
const
  FullDescText =
    'Full installation. Files will be installed on drives "C:" and "K:"';
  PartDescText =
    'Partial installation. Files will be installed on drives "C:" and "K:"';

var
  FullRadioButton: TNewRadioButton;
  PartRadioButton: TNewRadioButton;

procedure InitializeWizard;
var
  CustomPage: TWizardPage;
  FullDescLabel: TLabel;
  PartDescLabel: TLabel;
begin
  CustomPage := CreateCustomPage(wpWelcome, 'Installation type', '');
  FullRadioButton := TNewRadioButton.Create(WizardForm);
  FullRadioButton.Parent := CustomPage.Surface;
  FullRadioButton.Checked := True;
  FullRadioButton.Top := 16;
  FullRadioButton.Width := CustomPage.SurfaceWidth;
  FullRadioButton.Font.Style := [fsBold];
  FullRadioButton.Font.Size := 9;
  FullRadioButton.Caption := 'Full Installation'
  FullDescLabel := TLabel.Create(WizardForm);
  FullDescLabel.Parent := CustomPage.Surface;
  FullDescLabel.Left := 8;
  FullDescLabel.Top := FullRadioButton.Top + FullRadioButton.Height + 8;
  FullDescLabel.Width := CustomPage.SurfaceWidth; 
  FullDescLabel.Height := 40;
  FullDescLabel.AutoSize := False;
  FullDescLabel.Wordwrap := True;
  FullDescLabel.Caption := FullDescText;
  PartRadioButton := TNewRadioButton.Create(WizardForm);
  PartRadioButton.Parent := CustomPage.Surface;
  PartRadioButton.Top := FullDescLabel.Top + FullDescLabel.Height + 16;
  PartRadioButton.Width := CustomPage.SurfaceWidth;
  PartRadioButton.Font.Style := [fsBold];
  PartRadioButton.Font.Size := 9;
  PartRadioButton.Caption := 'Partial Installation'
  PartDescLabel := TLabel.Create(WizardForm);
  PartDescLabel.Parent := CustomPage.Surface;
  PartDescLabel.Left := 8;
  PartDescLabel.Top := PartRadioButton.Top + PartRadioButton.Height + 8;
  PartDescLabel.Width := CustomPage.SurfaceWidth;
  PartDescLabel.Height := 40;
  PartDescLabel.AutoSize := False;
  PartDescLabel.Wordwrap := True;
  PartDescLabel.Caption := PartDescText;
end;

function IsFullInstallation: Boolean;
begin
  Result := FullRadioButton.Checked;
end;

答案 1 :(得分:4)

进行条件安装的最简单方法是使用[Types][Components]

[Types]
Name: standard; Description: Standard
Name: partial; Description: Partial

[Components]
Name: game; Description: Full game install; Types: standard
Name: sounds; Description: Sound files; Types: standard partial

[Files]
...; Components: game
...; Components: sounds