Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

InnoSetup: Getting AppName in [Code] section

I'm creating an installer using InnoSetup, and writing some custom handlers in a [Code] section. In one of the handlers, I would like to be able to retrieve the value of the AppName (or, potentially, the value of other parameters) defined in the [Setup] section. Is there a way for me to do this? I've looked though the documentation, but I haven't found anything that would allow me to do this. Our InnoSetup files are actually generated by our build process, which stitches together fragments that are common between all of our programs and that are program specific, so it would be inconvenient to have to define constants in the code for each program. Is there any convenient way to do this?

I'm looking for something like

MyString := ExpandConstant('{AppName}');

Except {AppName} is not a defined constant. Is there some way to query for parameters defined in the [Setup] section?

like image 971
Brian Campbell Avatar asked Dec 18 '09 03:12

Brian Campbell


2 Answers

Inspired by Craig's answer, I was looking at the Inno Setup Preprocessor documentation (in ISTool, not available online as far as I've found), and came across the SetupSetting function in the preprocessor.

It can be used as so:

MyString := '{#SetupSetting("AppName")}';

And as long as the [Setup] section appears before the place where this is used (ISPP seems to be only one pass), and includes a definition for AppName, this will give the results I want, without having to define an extra macro for each setting we want to extract.

like image 197
Brian Campbell Avatar answered Nov 07 '22 15:11

Brian Campbell


It's a build-time constant, not an install-time value. So you can use the Inno Setup Preprocessor add-on to define such constants. (You can install it easily via the QuickStart pack).

Define the constant:

#define AppName "Excellent Foo App"

Use the constant in [Setup]:

AppName={#AppName}

And in Pascal code, I'm not totally sure of the syntax, but something like:

MyString := {#AppName}

Update: I realised one of my scripts uses {#emit SetupSetting("AppId")} which is easier. Brian's solution also discovered this method, and is better.

like image 22
Craig McQueen Avatar answered Nov 07 '22 16:11

Craig McQueen