【问题标题】:How can I add a check box for optional files during install in Inno Setup?如何在 Inno Setup 中安装期间为可选文件添加复选框?
【发布时间】:2012-11-21 21:29:48
【问题描述】:

我正在尝试在我的自定义页面中创建一个自定义复选框(因为它是单页安装程序),只需要一个没有对话框或任何内容的复选框,我尝试编译的安装程序非常线性和简单。

我想以这种方式在复选框上绑定FILE3.EXE:如果选中复选框,则将文件 (FILE3.EXE) 复制到 DestDir,否则如果未选中复选框,则在安装过程中跳过文件 (FILE3.EXE)。

这是我使用的代码,显然复选框代码丢失了,因为我无法做到这一点

[Files]
Source: FILE1.EXE; DestDir: {app};
Source: FILE2.EXE; DestDir: {app};
Source: FILE3.EXE; DestDir: {app}; //OPTIONAL
[Code]
procedure ExitProcess(uExitCode: UINT);
external 'ExitProcess@kernel32.dll stdcall';

var
  MainPage : TWizardPage;
  FolderToInstall : TEdit;
  InstallLocation : String;

procedure CancelClick(Sender: TObject);
begin
  if ExitSetupMsgBox then
  begin
    ExitProcess(0);
  end;
end;

procedure BrowseClick(Sender : TObject);
var
  Dir : String;

begin
  Dir := FolderToInstall.Text;
  if BrowseForFolder('Browse',Dir,false) then
    FolderToInstall.Text := Dir;
  WizardForm.DirEdit.Text := Dir;
end;

procedure InitializeWizard();
var
  LabelFolder : TLabel;
begin
  MainPage := CreateCustomPage(wpWelcome,'','');
  LabelFolder := TLabel.Create(MainPage);
  LabelFolder.Parent := WizardForm;
  LabelFolder.Top := 164;
  LabelFolder.Left := 6;
  LabelFolder.Caption := 'Directory:'

  FolderToInstall := TEdit.Create(MainPage);
  FolderToInstall.Parent := WizardForm;
  FolderToInstall.Top := 182;
  FolderToInstall.Left := 85;
  FolderToInstall.Width := 380;
  FolderToInstall.Text :=  WizardDirValue;
  FolderToInstall.ReadOnly := True;
end;

【问题讨论】:

  • 您想要一个完整的自定义解决方案,还是想要为该方法使用已经内置的功能?
  • 我正在尝试在我的自定义页面中创建一个自定义复选框(因为是单页安装程序),只需要一个没有对话框或任何内容的复选框,我正在尝试编译的安装程序是非常线性和简单
  • 然后在Files 部分使用Check 参数创建一个复选框并创建一个自定义函数。你想把那个复选框放在哪里?
  • 非常感谢 TLama,如果你能发布一个例子,我会非常高兴(当然还有像我这样的自学者),这样我就能更好地理解 inno 的工作原理

标签: inno-setup pascalscript


【解决方案1】:

您不必为此手动创建复选框。让用户选择安装内容的标准方法是使用脚本文件的 [Types][Components] 部分。

查看位于 Inno Setup 安装文件夹\examples 中的 Components.iss 脚本。

; -- Components.iss --
; Demonstrates a components-based installation.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING .ISS SCRIPT FILES!

[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: "full"; Description: "Full installation"
Name: "compact"; Description: "Compact installation"
Name: "custom"; Description: "Custom installation"; Flags: iscustom

[Components]
Name: "program"; Description: "Program Files"; Types: full compact custom; Flags: fixed
Name: "help"; Description: "Help File"; Types: full
Name: "readme"; Description: "Readme File"; Types: full
Name: "readme\en"; Description: "English"; Flags: exclusive
Name: "readme\de"; Description: "German"; Flags: exclusive

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Components: program
Source: "MyProg.chm"; DestDir: "{app}"; Components: help
Source: "Readme.txt"; DestDir: "{app}"; Components: readme\en; Flags: isreadme
Source: "Readme-German.txt"; DestName: "Liesmich.txt"; DestDir: "{app}"; Components: readme\de; Flags: isreadme

[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"

在运行时,安装程​​序会在向导中显示此对话框:

【讨论】:

  • @Globulorozzo 您应该在问题中说明重要信息,希望每个人都“在代码中看到”对于试图帮助您的人来说不是很好!
  • @Globulorozzo 为什么不编辑您的问题?我们应该为你这样做吗? :(
【解决方案2】:

您需要创建一个Check 函数,该函数将从脚本的[Code] 部分返回复选框的状态。像这样的东西可能会做你想做的事,但在代码脚本之前,我会在以下内容中更正你:

  • 尽可能使用 TNew... 类,因此在您的情况下使用 TNewEdit 而不是 TEdit
  • 如果您想在页面上有某个组件,请使用TWizardPage.Surface 作为Parent(这里我不确定这是否是您的意图,只是指出这一点:-)
  • 格式化你的代码,它不需要那么扁平

在以下示例中,我使用了名为InstallHelpFileCheck 函数来有条件地安装某个文件,在本例中为MyProg.chmCheck 函数工作简单;当你给函数返回 True 时,文件被处理,当你返回 False 时被跳过。

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"; Check: InstallHelpFile;
[Code]
var
  InstallHelpCheckBox: TNewCheckBox;  

procedure InitializeWizard;
var  
  LabelFolder: TLabel;  
  MainPage: TWizardPage;  
  FolderToInstall: TNewEdit;  
begin
  MainPage := CreateCustomPage(wpWelcome, '', '');
  LabelFolder := TLabel.Create(MainPage);
  LabelFolder.Parent := WizardForm;
  LabelFolder.Top := 164;
  LabelFolder.Left := 6;
  LabelFolder.Caption := 'Directory:'

  FolderToInstall := TNewEdit.Create(MainPage);
  FolderToInstall.Parent := MainPage.Surface;
  FolderToInstall.Top := 182;
  FolderToInstall.Left := 85;
  FolderToInstall.Width := 380;
  FolderToInstall.Text :=  WizardDirValue;
  FolderToInstall.ReadOnly := True;

  InstallHelpCheckBox := TNewCheckBox.Create(MainPage);
  InstallHelpCheckBox.Parent := MainPage.Surface;
  InstallHelpCheckBox.Top := FolderToInstall.Top + FolderToInstall.Height + 8;
  InstallHelpCheckBox.Left := FolderToInstall.Left;
  InstallHelpCheckBox.Width := FolderToInstall.Width;
  InstallHelpCheckBox.Caption := 'Install help file';
end;

function InstallHelpFile: Boolean;
begin
  { here is the Check function used above; if you return True to this }
  { function, the file will be installed, when False, the file won't }
  { be installed }
  Result := InstallHelpCheckBox.Checked;
end;

【讨论】:

    【解决方案3】:

    您可以使用 CreateInputOptionPage() 更轻松地完成此操作。请参阅 Inno Setup 帮助中的详细信息。 http://www.jrsoftware.org/ishelp/index.php?topic=scriptpages

    【讨论】:

      【解决方案4】:
      // Create:
      for i := 0 to g_SetupX_Count do begin
          WizardForm.ComponentsList.AddCheckBox(g_SetupX_Name[i], '', 0, g_SetupX_Active[i], true, false, false, nil);
          g_SetupX_CompListIndex[i] := nextPosi;
          nextPosi := nextPosi + 1;
      end;
      
      // Evaluate:
      for i := 0 to g_SetupX_Count do begin
          g_SetupX_Active[i] := WizardForm.ComponentsList.Checked[g_SetupX_CompListIndex[i]];
      end;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多