Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
475 views
in Technique[技术] by (71.8m points)

pascalscript - How can I add a check box for optional files during install in Inno Setup?

I'm trying to make a custom checkbox in my custom page (because it's a one page installer), is needed only a checkbox without dialogs or anything, the installer that I'm trying to compile is very linear and simple.

I want to bind FILE3.EXE on a checkbox in this way: if checkbox is checked copy the file (FILE3.EXE) in DestDir, otherwise if checkbox is unchecked skip the file (FILE3.EXE) during installation.

This is the code that I used, obviously the checkbox code is missing because I'm not able to do that

[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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You don't have to manually create checkboxes for that. The standard way to let the user choose what to install is to use the [Types] and [Components] sections of your script file.

Take a look at the Components.iss script located in your Inno Setup install folderexamples.

; -- 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: "readmeen"; Description: "English"; Flags: exclusive
Name: "readmede"; 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: readmeen; Flags: isreadme
Source: "Readme-German.txt"; DestName: "Liesmich.txt"; DestDir: "{app}"; Components: readmede; Flags: isreadme

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

At runtime, the installer presents this dialog within the wizard:

Components dialog


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...