简体   繁体   中英

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. The Ant script has many properties defined (mostly pathnames and filenames) that get passed to the Inno Setup script as constants.

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. But I also set a property field ( fullJRE ) to either 0 or 1 depending on if the executable is needed or not needed. 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. The function to do this is called from the CurStepChanged procedure, using CurStep=ssPostInstall :

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. Based on the fullJRE constant, I either need to keep both the file and the shortcut or delete them both.

Is there a way I can either:

  1. add an 'if' statement to the Icons section to prevent certain icons from being created
  2. delete the extra shortcuts at the end of the install, when I delete the files

Any help would be appreciated. Thanks so much!

Your fullJRE "constant" is actually a preprocessor variable .

You can use it in any preprocessor directive to preprocess your Inno Setup script to look the way you need.

In this case, you may use #if directive :

[Icons]
#if fullJRE == "1"
Name: "{group}\My Program"
#endif

And you should do the same even for your updateINI code. 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:

#expr SaveToFile(AddBackslash(SourcePath) + "Preprocessed.iss")

See Inno Setup: How do I see the output (translation) of the Inno Setup Preprocessor?


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 .

[Icons]
#ifdef fullJRE
Name: "{group}\My Program"
#endif

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM