Inno Setup遍历Pascal代码中的[Files]部分 [英] Inno Setup Iterate over [Files] section in Pascal code

查看:241
本文介绍了Inno Setup遍历Pascal代码中的[Files]部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Inno Setup脚本中,我需要将多个文件复制到多个用户定义的位置.为此,我想遍历[Files]部分中的源,并根据用户定义的设置和文件属性多次FileCopy()对其进行遍历.

In an Inno Setup script, I need to copy a number of files to multiple user-defined locations. In order to do this, I'd like to iterate over the sources in the [Files] section, and FileCopy() them multiple times depending on the user-defined settings and properties of the files.

是否可以使用脚本访问[Files]部分中的源?

Is it possible to access the sources in the [Files] section using a script?

推荐答案

否,您无法迭代[Files]部分.

但是您可以使用预处理器从一个文件列表中生成[Files]部分和Pascal脚本.

But you can use preprocessor to generate both the [Files] section and the Pascal Script from one list of files.

您对目标不是很明确,因此我仅显示一个粗略的概念.

You are not very specific about your goals, so I'm showing only a rough concept.

; Define array of files to work with
#dim Files[2]
#define Files[0] "MyProg.exe"
#define Files[1] "MyProg.chm"

#define I

; Iterate the file array, generating one entry in Run section for each file    
[Files]
#sub FileEntry
Source: "{#Files[I]}"; DestDir: "{app}"
#endsub

#for {I = 0; I < DimOf(Files); I++} FileEntry


[Code]

procedure CopyFiles;
begin
  // Iterate the file array, generating two FileCopy calls for each file    
#sub FileCopy
  FileCopy('{#Files[I]}', 'd:\destination1\{#Files[I]}', True);
  FileCopy('{#Files[I]}', 'd:\destination2\{#Files[I]}', True);
#endsub

#for {I = 0; I < DimOf(Files); I++} FileCopy
end;

// Just for debugging purposes, outputs the preprocessed script
// so you can verify if the code generation went right
#expr SaveToFile(AddBackslash(SourcePath) + "Preprocessed.iss")

如果编译脚本,则可以在预处理文件Preprocessed.iss中看到它生成了以下内容:

If you compile the script, you can see in the preprocessed file Preprocessed.iss that it generates this:

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "{app}"

[Code]
procedure CopyFiles;
begin
  FileCopy('MyProg.exe', 'd:\destination1\MyProg.exe', True);
  FileCopy('MyProg.exe', 'd:\destination2\MyProg.exe', True);
  FileCopy('MyProg.chm', 'd:\destination1\MyProg.chm', True);
  FileCopy('MyProg.chm', 'd:\destination2\MyProg.chm', True);
end;


实际上,您可能不需要为此特定用途使用FileCopy.您可以让预处理器为同一文件生成多个[Files]节条目:


Actually you may not need to use the FileCopy for this specific purpose. You can just have the preprocessor generate multiple [Files] section entries for the same file:

; Iterate the file array, generating one entry in Run section for each file    
[Files]
#sub FileEntry
Source: "{#Files[I]}"; DestDir: "{app}"
Source: "{#Files[I]}"; DestDir: "d:\destination1"
Source: "{#Files[I]}"; DestDir: "d:\destination2"
#endsub

生成:

[Files]
Source: "MyProg.exe"; DestDir: "{app}"
Source: "MyProg.exe"; DestDir: "d:\destination1"
Source: "MyProg.exe"; DestDir: "d:\destination2"
Source: "MyProg.chm"; DestDir: "{app}"
Source: "MyProg.chm"; DestDir: "d:\destination1"
Source: "MyProg.chm"; DestDir: "d:\destination2"

Inno Setup将识别相同的源文件,并且只会打包一次.

Inno Setup will identify identical source files and will pack them only once.

您可以使用 Check参数进行一些输入有条件的.

You can use Check parameter to make some entries conditional.

另请参阅此问题,该问题实际上是相似的:
通过InnoSetup中的脚本访问文件列表

See also this question, which is actually similar:
Access file list via script in InnoSetup

这篇关于Inno Setup遍历Pascal代码中的[Files]部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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