1
votes

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!

1
Both is possible. But to give you an answer, you have to tell us more about the condition on which you are going to decide what to do. It that based on "Tasks"? Or something else?Martin Prikryl
Why not just create only the icons you need, rather than deleting unneeded icons afterwards?Bill_Stewart
I've updated the question with a few more details, to make it a little clearer what I'm doing.Michael
You didn't really explain anything. "flag" can mean dozen different things. It might help, if you show us your CurStepChanged code, so that we can see how you treat that "flag", whatever it is.Martin Prikryl
the flag is a constant being passed to the Inno Setup script from the Ant script. I've added more detail to explain how this is doneMichael

1 Answers

1
votes

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