在Inno Setup创建页面中,用户可以从安装文件中打包的文件夹中选择文件



在Inno Setup中,我想创建一个页面,该页面有一个复选框列表,对应于我在[Files]部分列出的文件夹中的文件。

我如何读取这个文件夹中的文件,然后只复制用户选择的那些文件?现在,我甚至没有得到列表,因为文件夹{tmp}list不存在。

[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;

InitializeWizard发生在最开始,远在文件被提取之前。此外,将(所有)文件提取到{tmp},然后在用户选择要安装的文件后将它们复制到其他地方,这将是低效的。你必须编写实际安装过程的代码。


正确的解决方案是在编译(而不是安装)时生成列表框内容,使用Inno Setup预处理器。

下面的问题显示了类似的东西。它为每个文件创建一个innosetup组件。它甚至可能比自定义页面更好。
Inno Setup:为文件夹及其子文件夹中的所有文件动态添加组件

但是如果你想要定制页面,解决方案不会有太大的不同。您只需为每个文件生成FileListBox.Items.Add调用,而不是[Components]节项。代码有点复杂,因为它递归地工作(您似乎不需要)。对于平面解,可以简化。


还要注意的是,有CreateInputOptionPage,这使得它更容易创建一个自定义页面与复选框。