Search code examples
inno-setuppascalscript

In Inno Setup create page where the user may select files from a folder that is packaged in the setup file


In Inno Setup I want to create a page that has a list of checkboxes that correspond to the files in a folder I have listed in the [Files] section.

How can I read the files in this folder and then copy only those files, that the user selected? Right now, I don't even get the list, because the folder {tmp}\list doesn't exist.

[Files]
Source: "list\*"; DestDir:"{tmp}"; Flags: recursesubdirs

[Code]

var
  karten : TNewCheckListBox;
  FileListBox : TNewListBox;
  KartenFormular: TWizardPage;

procedure KartenEinlesen(const Directory: string; Files: TStrings);
var
  FindRec: TFindRec;
begin
  Files.Clear;
  if FindFirst(ExpandConstant(Directory + '*'), FindRec) then
  try
    repeat
      if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY = 1 then
        Files.Add(FindRec.Name);
    until
      not FindNext(FindRec);
  finally
    FindClose(FindRec);
  end;  
end;

procedure InitializeWizard;
var 
  AfterID: Integer;
begin
  AfterID := wpSelectTasks;
  KartenFormular := 
    CreateCustomPage(
      AfterID, 'Kartendaten', 'Ort für den Ordner Kartendaten auswählen');
  FileListBox := TNewListBox.Create(WizardForm);
  FileListBox.Parent := KartenFormular.Surface;
  FileListBox.Align := alClient;
  AfterID := KartenFormular.ID;
    
  KartenEinlesen('{tmp}\maptiles\*',FileListBox.Items)
end;

Solution

  • The InitializeWizard happens at the very beginning, long before the files are extracted. Moreover it would be inefficient to extract (all) files to {tmp} and then copy them somewhere else after users selects the files to install. And you would have to code the actual installation process.


    The right solution is to generate the list box contents on compile (not install) time, using Inno Setup preprocessor.

    The following question shows something similar. It creates a Inno Setup component for each file. It might even be better than a custom page.
    Dynamically add an Inno Setup component for all files in a folder and its subfolders

    But if you want the custom page, the solution won't be too different. You just would generate FileListBox.Items.Add call for each file, instead of [Components] section entry. The code is somewhat complicated as it works recursively (what you do not seem to need). For flat solution, it can be simplified.


    Also note that there's CreateInputOptionPage, what makes it easier to create a custom page with check list box.