Inno Setup-从外部源(文件或文件夹内容)创建组件/类型的动态列表 [英] Inno Setup - Create a dynamic list of components/types from external source (file or folder contents)

查看:239
本文介绍了Inno Setup-从外部源(文件或文件夹内容)创建组件/类型的动态列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件(设置更改器),该文件使用xcopy列出特定文件夹中的特定文件格式,然后允许我键入其中一个名称,并且脚本使用该名称将该文件复制到另一个位置./p>

首先xcopy创建一个原始副本作为备份(仅滚动备份1个副本),然后进行文件复制(扩展名是批量固定的,仅需要文件名的主体).很乐意尝试在Inno Setup中执行此操作,以获得一个干净的GUI.

我想从特定固定文件夹中的文件列表中填充组件/类型的列表.甚至可以在(额外的步骤,但可能会更好地控制)中使用这些名称创建一个ini文件.可能阻止这种情况发生的主要问题是不知道它将是一个数组有多少个条目.如果只有1个条目或只有1个选项(1或a)(如果有4个),则用户可以选择4个中的1个(a,b,c或d).我将提取文件名以创建名称/描述.

然后完成与我的批处理相同的任务,备份(很容易总是像start.ini这样的名称),然后复制文件,例如example1.ini并覆盖start.ini

ini可能是最灵活的,因为我可以想象以后会添加新的部分来更改执行的操作.

这是可能的,还是该程序扩展得太远了.暂时不要着急,因为我的批处理现在可以正常工作,但是打字和手动操作步骤越少,继续使用的效果就越好.

我找到了一个将内容列出到对话框窗口的示例,但是我不知道如何使用它来填充组件. TLama-列出目录中的所有文件

解决方案

您不能在运行时动态创建组件(可以在编译时动态创建).


但是使用 TNewCheckListBox .

然后在 CurStepChanged(ssInstall) 中处理选定的文件/组件根据您的需要.

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

I have a batch file (setting changer) that uses xcopy to list specific files formats in a specific folder, then allows me to type in one of the names and the script uses that name to copy that file to another location.

First xcopy creates a copy of the original as a backup (rolling backup only 1 copy) then does the file copy (extension is fixed in batch only body of filename needed This works great BUT I would love to try and do this in Inno Setup for a nice clean GUI.

I would like to populate the list of components/types from this list of files found in a specific fixed folder. Or even create an ini file with those names in (extra step but maybe better control). Main problem that might prevent this from being possible is not knowing how many entries it would be an array. If only 1 entry or file only 1 option (1 or a) if 4 then user can select 1 of 4 (a, b, c or d). I would extract the file name to create the name/description.

then on completion the same task as my batch would happen, backup (easy always the same name like start.ini) then copy the file e.g. example1.ini and overwrite start.ini

ini might be most flexible as I can imagine later adding new sections to change the actions performed.

Is this possible or stretching this program too far. No rush as my batch works for now but the less typing and manual steps the better for continued use.

I found an example to list contents to a dialog window but I could not figure how to use this to populate components. TLama - List all files in a directory

解决方案

You cannot create the components dynamically on runtime (you can on compile-time).


But it's not difficult to implement a custom dynamic components-like page using the CreateCustomPage and the TNewCheckListBox.

Then in the CurStepChanged(ssInstall) you process the selected files/components as your need.

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

这篇关于Inno Setup-从外部源(文件或文件夹内容)创建组件/类型的动态列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆