Inno Setup - 从外部源(文件或文件夹内容)创建 components/types 的动态列表
Inno Setup - Create a dynamic list of components/types from external source (file or folder contents)
我有一个批处理文件(设置更改器),它使用 xcopy 列出特定文件夹中的特定文件格式,然后允许我输入其中一个名称,脚本使用该名称将该文件复制到另一个位置.
首先 xcopy 创建原始副本作为备份(只滚动备份 1 个副本)然后复制文件(扩展名在批处理中固定,只需要文件名的主体这效果很好,但我很想尝试在 Inno Setup 中执行此操作以获得漂亮干净的 GUI。
我想从在特定固定文件夹中找到的文件列表填充 components/types 列表。或者甚至创建一个包含这些名称的 ini 文件( 额外的步骤,但可能更好地控制 )。可能阻止这成为可能的主要问题是不知道有多少条目将是一个数组。如果只有 1 个条目或文件只有 1 个选项(1 或 a),如果有 4 个,则用户可以 select 4 个中的 1 个(a、b、c 或 d)。我将提取文件名以创建 name/description.
然后完成与我的批处理相同的任务,备份(容易总是同名,如 start.ini)然后复制文件,例如example1.ini 并覆盖 start.ini
ini 可能是最灵活的,因为我可以想象以后添加新的部分来更改执行的操作。
这是否可能或将此程序扩展得太远。不用着急,因为我的批次现在可以使用,但输入和手动步骤越少,继续使用越好。
我找到了一个将内容列到对话框的示例 window,但我不知道如何使用它来填充组件。 TLama - List all files in a directory
您不能在运行时动态创建组件(您可以在编译时)。
但是使用 CreateCustomPage
and the TNewCheckListBox
.
实现一个自定义的类动态组件页面并不难
然后在 CurStepChanged(ssInstall)
中根据需要处理所选的 files/components。
[Code]
const
SourcePath = 'C:\somepath';
var
CustomSelectTasksPage: TWizardPage;
ComponentsList: TNewCheckListBox;
procedure InitializeWizard();
var
FindRec: TFindRec;
SelectComponentsLabel: TNewStaticText;
begin
CustomSelectTasksPage :=
CreateCustomPage(
wpSelectComponents, SetupMessage(msgWizardSelectComponents),
SetupMessage(msgSelectComponentsDesc));
SelectComponentsLabel := TNewStaticText.Create(WizardForm);
SelectComponentsLabel.Parent := CustomSelectTasksPage.Surface;
SelectComponentsLabel.Top := 0;
SelectComponentsLabel.Left := 0;
SelectComponentsLabel.Width := CustomSelectTasksPage.Surface.Width;
SelectComponentsLabel.AutoSize := False;
SelectComponentsLabel.ShowAccelChar := False;
SelectComponentsLabel.WordWrap := True;
SelectComponentsLabel.Caption := SetupMessage(msgSelectComponentsLabel2);
WizardForm.AdjustLabelHeight(SelectComponentsLabel);
ComponentsList := TNewCheckListBox.Create(WizardForm);
ComponentsList.Parent := CustomSelectTasksPage.Surface;
ComponentsList.Top :=
SelectComponentsLabel.Top + SelectComponentsLabel.Height + ScaleY(8);
ComponentsList.Left := 0;
ComponentsList.Width := CustomSelectTasksPage.Surface.Width;
ComponentsList.Height := CustomSelectTasksPage.Surface.Height - ComponentsList.Top;
if FindFirst(ExpandConstant(AddBackslash(SourcePath) + '*.dat'), FindRec) then
begin
try
repeat
ComponentsList.AddCheckBox(FindRec.Name, '', 0, False, True, False, False, nil);
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
I: Integer;
FileName: string;
SourceFilePath: string;
TargetFilePath: string;
begin
if CurStep = ssInstall then
begin
for I := 0 to ComponentsList.Items.Count - 1 do
begin
if ComponentsList.Checked[I] then
begin
FileName := ComponentsList.Items[I];
SourceFilePath := AddBackslash(SourcePath) + FileName;
TargetFilePath := AddBackslash(ExpandConstant('{app}')) + FileName;
if FileCopy(SourceFilePath, TargetFilePath, False) then
begin
Log(Format('Installed "%s".', [FileName]));
end
else
begin
Log(Format('Failed to install "%s".', [FileName]));
end;
end;
end;
end;
end;
我有一个批处理文件(设置更改器),它使用 xcopy 列出特定文件夹中的特定文件格式,然后允许我输入其中一个名称,脚本使用该名称将该文件复制到另一个位置.
首先 xcopy 创建原始副本作为备份(只滚动备份 1 个副本)然后复制文件(扩展名在批处理中固定,只需要文件名的主体这效果很好,但我很想尝试在 Inno Setup 中执行此操作以获得漂亮干净的 GUI。
我想从在特定固定文件夹中找到的文件列表填充 components/types 列表。或者甚至创建一个包含这些名称的 ini 文件( 额外的步骤,但可能更好地控制 )。可能阻止这成为可能的主要问题是不知道有多少条目将是一个数组。如果只有 1 个条目或文件只有 1 个选项(1 或 a),如果有 4 个,则用户可以 select 4 个中的 1 个(a、b、c 或 d)。我将提取文件名以创建 name/description.
然后完成与我的批处理相同的任务,备份(容易总是同名,如 start.ini)然后复制文件,例如example1.ini 并覆盖 start.ini
ini 可能是最灵活的,因为我可以想象以后添加新的部分来更改执行的操作。
这是否可能或将此程序扩展得太远。不用着急,因为我的批次现在可以使用,但输入和手动步骤越少,继续使用越好。
我找到了一个将内容列到对话框的示例 window,但我不知道如何使用它来填充组件。 TLama - List all files in a directory
您不能在运行时动态创建组件(您可以在编译时)。
但是使用 CreateCustomPage
and the TNewCheckListBox
.
然后在 CurStepChanged(ssInstall)
中根据需要处理所选的 files/components。
[Code]
const
SourcePath = 'C:\somepath';
var
CustomSelectTasksPage: TWizardPage;
ComponentsList: TNewCheckListBox;
procedure InitializeWizard();
var
FindRec: TFindRec;
SelectComponentsLabel: TNewStaticText;
begin
CustomSelectTasksPage :=
CreateCustomPage(
wpSelectComponents, SetupMessage(msgWizardSelectComponents),
SetupMessage(msgSelectComponentsDesc));
SelectComponentsLabel := TNewStaticText.Create(WizardForm);
SelectComponentsLabel.Parent := CustomSelectTasksPage.Surface;
SelectComponentsLabel.Top := 0;
SelectComponentsLabel.Left := 0;
SelectComponentsLabel.Width := CustomSelectTasksPage.Surface.Width;
SelectComponentsLabel.AutoSize := False;
SelectComponentsLabel.ShowAccelChar := False;
SelectComponentsLabel.WordWrap := True;
SelectComponentsLabel.Caption := SetupMessage(msgSelectComponentsLabel2);
WizardForm.AdjustLabelHeight(SelectComponentsLabel);
ComponentsList := TNewCheckListBox.Create(WizardForm);
ComponentsList.Parent := CustomSelectTasksPage.Surface;
ComponentsList.Top :=
SelectComponentsLabel.Top + SelectComponentsLabel.Height + ScaleY(8);
ComponentsList.Left := 0;
ComponentsList.Width := CustomSelectTasksPage.Surface.Width;
ComponentsList.Height := CustomSelectTasksPage.Surface.Height - ComponentsList.Top;
if FindFirst(ExpandConstant(AddBackslash(SourcePath) + '*.dat'), FindRec) then
begin
try
repeat
ComponentsList.AddCheckBox(FindRec.Name, '', 0, False, True, False, False, nil);
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
var
I: Integer;
FileName: string;
SourceFilePath: string;
TargetFilePath: string;
begin
if CurStep = ssInstall then
begin
for I := 0 to ComponentsList.Items.Count - 1 do
begin
if ComponentsList.Checked[I] then
begin
FileName := ComponentsList.Items[I];
SourceFilePath := AddBackslash(SourcePath) + FileName;
TargetFilePath := AddBackslash(ExpandConstant('{app}')) + FileName;
if FileCopy(SourceFilePath, TargetFilePath, False) then
begin
Log(Format('Installed "%s".', [FileName]));
end
else
begin
Log(Format('Failed to install "%s".', [FileName]));
end;
end;
end;
end;
end;