[英]Delete (or do not create) Start menu shortcuts in Inno Setup when compiler flag is set
I have an Ant script to compile a Java program (the one I want to distribute), create a few different executables and settings files (to run different configurations), and then launch an Inno Setup script to put it all together into an installer.我有一个 Ant 脚本来编译一个 Java 程序(我想分发的那个),创建几个不同的可执行文件和设置文件(以运行不同的配置),然后启动一个 Inno Setup 脚本以将它们全部放在一个安装程序中。 The Ant script has many properties defined (mostly pathnames and filenames) that get passed to the Inno Setup script as constants. Ant 脚本定义了许多属性(主要是路径名和文件名),它们作为常量传递给 Inno Setup 脚本。
I have one user who needs a special executable.我有一个用户需要一个特殊的可执行文件。 Rather than maintain two different Ant scripts, it was easy to have the Ant script always create the executable.与其维护两个不同的 Ant 脚本,不如让 Ant 脚本始终创建可执行文件。 But I also set a property field ( fullJRE
) to either 0 or 1 depending on if the executable is needed or not needed.但我还将属性字段 ( fullJRE
) 设置为 0 或 1,具体取决于是否需要可执行文件。 The property gets passed to Inno Setup as a constant and is then used in the [code] section to keep/delete the file at the end.该属性作为常量传递给 Inno Setup,然后在 [code] 部分中用于在最后保留/删除文件。 The function to do this is called from the CurStepChanged
procedure, using CurStep=ssPostInstall
:使用CurStep=ssPostInstall
从CurStepChanged
过程调用执行此操作的函数:
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep=ssPostInstall then
begin
updateINI();
end
end;
function updateINI(): boolean;
begin
if ({#fullJRE} = 0) then
begin
DeleteFile(ExpandConstant('{app}\{#launcherName}.exe'));
end;
end;
But a shortcut to the executable is being created in the Icons section of the script, because when [icons] is run the file still exists.但是在脚本的 Icons 部分创建了可执行文件的快捷方式,因为当运行 [icons] 时,该文件仍然存在。 Based on the fullJRE
constant, I either need to keep both the file and the shortcut or delete them both.基于fullJRE
常量,我要么需要同时保留文件和快捷方式,要么同时删除它们。
Is there a way I can either:有没有办法我可以:
Icons
section to prevent certain icons from being created向Icons
部分添加“if”语句以防止创建某些图标Any help would be appreciated.任何帮助,将不胜感激。 Thanks so much!非常感谢!
Your fullJRE
"constant" is actually a preprocessor variable .您的fullJRE
“常量”实际上是一个预处理器变量。
You can use it in any preprocessor directive to preprocess your Inno Setup script to look the way you need.您可以在任何预处理器指令中使用它来预处理您的 Inno Setup 脚本,使其看起来符合您的需要。
In this case, you may use #if
directive :在这种情况下,您可以使用#if
指令:
[Icons]
#if fullJRE == "1"
Name: "{group}\My Program"
#endif
And you should do the same even for your updateINI
code.即使对于updateINI
代码,您也应该这样做。 Your current approach generates an unnecessary code like:您当前的方法会生成不必要的代码,例如:
function updateINI(): boolean;
begin
if (1 = 0) then
begin
DeleteFile(ExpandConstant('{app}\{#launcherName}.exe'));
end;
end;
While you can actually make preprocessor remove that code altogether by doing:虽然您实际上可以通过执行以下操作使预处理器完全删除该代码:
#if fullJRE == "0"
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep=ssPostInstall then
begin
updateINI();
end
end;
function updateINI(): boolean;
begin
DeleteFile(ExpandConstant('{app}\{#launcherName}.exe'));
end;
#endif
Add a SaveToFile
call at the very end of your Inno Setup script too see, what the preprocessor generates:在 Inno Setup 脚本的最后添加一个SaveToFile
调用,看看预处理器生成了什么:
#expr SaveToFile(AddBackslash(SourcePath) + "Preprocessed.iss")
See Inno Setup: How do I see the output (translation) of the Inno Setup Preprocessor?请参阅Inno Setup:如何查看 Inno Setup 预处理器的输出(翻译)?
Btw, in scenarios like this, the convention is to define a "flag", rather then a variable with a value.顺便说一句,在这种情况下,约定是定义一个“标志”,而不是一个带有值的变量。
So instead of /DfullJRE=1
, do /DfullJRE
and use #ifdef
and #ifndef
directives .因此,不要使用/DfullJRE=1
, /DfullJRE
使用/DfullJRE
并使用#ifdef
和#ifndef
指令。
[Icons]
#ifdef fullJRE
Name: "{group}\My Program"
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.