在Inno Setup脚本中,我需要将多个文件复制到多个用户定义的位置。为了做到这一点,我想迭代[Files]
部分中的源代码,并根据用户定义的设置和文件属性多次FileCopy()
。
是否可以使用脚本访问[Files]
部分中的来源?
答案 0 :(得分:3)
不,你不能迭代<%= f.collection_select :movie_id, Movie.all, :id, :title %>
部分。
但您可以使用预处理器从一个文件列表生成[Files]
部分和Pascal脚本。
您对目标并不十分具体,所以我只展示了一个粗略的概念。
[Files]
如果编译脚本,您可以在预处理文件; 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
实际上,您可能不需要为此特定目的使用[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]
生成:
; 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
Inno Setup会识别相同的源文件,并且只打包一次。
您可以使用Check
parameter使某些条目成为条件。
另见这个问题,实际上是相似的:
Access file list via script in InnoSetup