向Inno File部分添加多个源代码行的功能 [英] Function to add multiple source lines to Inno File section
问题描述
是否有一个函数或预处理器指令可用于向Inno Setup中的文件"部分添加多行?例如,我多次出现类似于以下内容的模式:
Is there a function or preprocessor directive that can be used to add multiple lines to the Files section in Inno Setup? For example, I have numerous occurrences of a pattern similar to the following:
[Files]
Source: "{#SrcPath}\Dir1\FileName.*"; DestDir: {#DstPath}\Dir1;
Source: "{#SrcPath}\Dir2\FileName.*"; DestDir: {#DstPath}\Dir2;
Source: "{#SrcPath}\Dir3\FileName\*"; DestDir: {#DstPath}\Dir3\FileName; Flags: recursesubdirs
虽然我只能复制并粘贴每一行,但我想知道是否可以做这样的事情?
And while I can just copy and paste the lines for each one, I was wondering if instead I could do something like this?
[Files]
AddFiles(FileName)
不幸的是,我在文档或在线中找不到任何说明如何执行此操作的示例.这可能吗?
Unfortunately, I can't find any examples in the docs or online that illustrates how to do this. Is this possible?
推荐答案
使用 #define
指令是这样的:
Define a preprocessor macro (template) using the #define
directive like this:
#define FileTemplate(str FileName) \
"Source: """ + SrcPath + "\Dir1\" + FileName + ".*""; DestDir: " + DstPath + "\Dir1;" + NewLine + \
"Source: """ + SrcPath + "\Dir2\" + FileName + ".*""; DestDir: " + DstPath + "\Dir2;" + NewLine + \
"Source: """ + SrcPath + "\Dir3\" + FileName + ".*""; DestDir: " + DstPath + "\Dir3; Flags: recursesubdirs"
并使用 #emit
指令扩展模板,如下所示:
And expand the template using the #emit
directive like this:
#define SrcPath "C:\srcpath"
#define DstPath "{app}"
[Files]
#emit FileTemplate("FileName1")
#emit FileTemplate("FileName2")
如果您获得预处理器以转储经过预处理的文件,您将看到代码产生了以下内容:
If you get the preprocessor to dump a preprocessed file, you will see that the code produces this:
[Files]
Source: "C:\srcpath\Dir1\FileName1.*"; DestDir: {app}\Dir1;
Source: "C:\srcpath\Dir2\FileName1.*"; DestDir: {app}\Dir2;
Source: "C:\srcpath\Dir3\FileName1.*"; DestDir: {app}\Dir3; Flags: recursesubdirs
Source: "C:\srcpath\Dir1\FileName2.*"; DestDir: {app}\Dir1;
Source: "C:\srcpath\Dir2\FileName2.*"; DestDir: {app}\Dir2;
Source: "C:\srcpath\Dir3\FileName2.*"; DestDir: {app}\Dir3; Flags: recursesubdirs
对于NewLine
预定义的预处理器变量,您需要Inno Setup6.另请参见在Inno Setup预处理器中发出新行 .
For NewLine
predefined preprocessor variable, you need Inno Setup 6. See also Emit new line in Inno Setup preprocessor.
这篇关于向Inno File部分添加多个源代码行的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!