3

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?

user7134019
  • 207
  • 1
  • 3
  • 13

1 Answers1

2

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"

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

For NewLine predefined preprocessor variable, you need Inno Setup 6. See also Emit new line in Inno Setup preprocessor.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • I had looked at the define directive, but couldn't get the syntax right. Thanks for the insight. The dump to a preprocessed file is very helpful for debugging as well. – user7134019 Nov 09 '16 at 14:14