编译器(或者技术上来说预处理器 https://jrsoftware.org/ispphelp/) has /D命令行开关 https://jrsoftware.org/ispphelp/index.php?topic=isppcc,您可以使用它来设置预处理器变量。
例如这个...
ISCC.exe Example1.iss /DBinaryName=MyProg.exe
...具有相同的效果,就像您使用#define指示 https://jrsoftware.org/ispphelp/index.php?topic=define在脚本本身中,如下所示:
#define BinaryName "MyProg.exe"
所以你可以在脚本中以同样的方式使用它:
[Files]
Source: "{#BinaryName}"; DestDir: "{app}"
您甚至可以使用变量状况 https://jrsoftware.org/ispphelp/index.php?topic=if like:
ISCC.exe Example1.iss /DMode=Install
#if Mode == "Install"
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
#elif Mode == "Delete"
[InstallDelete]
Type: files; Name: "{app}\MyProg.exe"
#else
#error Unknown mode
#endif
虽然为了达到同样的效果,你可以只使用变量的存在 https://jrsoftware.org/ispphelp/index.php?topic=if, like:
ISCC.exe Example1.iss /DInstall /DDelete
#ifdef Install
[Files]
Source: "MyProg.exe"; DestDir: "{app}"
#endif
#ifdef Delete
[InstallDelete]
Type: files; Name: "{app}\MyProg.exe"
#endif
这些问题也涵盖了这一点:
- 如何在 Inno Setup 中从同一脚本构建两个不同的安装程序? https://stackoverflow.com/q/3034747/850848
- 仅为特定组件编译 Inno Setup 安装程序 https://stackoverflow.com/q/48500040/850848
您可以在任何地方使用预处理器指令,甚至在[Code]
部分。
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssDone then
begin
#ifdef Delete
DeleteFile(ExpandConstant('{app}')+'\Locale\C4Union.UKR');
DeleteFile(ExpandConstant('{app}')+'\Locale\C4Union.ENU');
#endif
end;
end;
or even:
#ifdef Delete
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssDone then
begin
DeleteFile(ExpandConstant('{app}')+'\Locale\C4Union.UKR');
DeleteFile(ExpandConstant('{app}')+'\Locale\C4Union.ENU');
end;
end;
#endif
预处理器并不关心,它作为第一步启动并处理.iss
文件为纯文本文件。很像C/C++ 预处理器 https://en.wikipedia.org/wiki/C_preprocessor。它不太关心部分或代码结构。您甚至可以执行以下操作:
DeleteFile(
ExpandConstant(
#ifdef DeleteFromUserData
'{userappdata}\MyProg'
#else
'{app}'
#endif
)+'\Locale\C4Union.UKR');
Add SaveToFile到脚本的末尾 https://stackoverflow.com/q/3328375/850848查看生成的代码。