简体   繁体   English

InnoSetup:在[Code]部分获取AppName

[英]InnoSetup: Getting AppName in [Code] section

I'm creating an installer using InnoSetup , and writing some custom handlers in a [Code] section. 我正在使用InnoSetup创建一个安装程序,并在[Code]部分编写一些自定义处理程序。 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. 在其中一个处理程序中,我希望能够检索[Setup]部分中定义的AppName的值(或者,可能是其他参数的值)。 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. 我们的InnoSetup文件实际上是由我们的构建过程生成的,它将所有程序和程序特定的片段拼接在一起,因此必须在代码中为每个程序定义常量是不方便的。 Is there any convenient way to do this? 有没有方便的方法呢?

I'm looking for something like 我正在寻找类似的东西

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

Except {AppName} is not a defined constant. 除了{AppName}不是定义的常量。 Is there some way to query for parameters defined in the [Setup] section? 有没有办法查询[Setup]部分中定义的参数?

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. 受Craig的回答启发,我正在查看Inno Setup预处理器文档(在ISTool中,据我所见,在线无法使用),并且在预处理器中遇到了SetupSetting函数。

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. 只要[Setup]部分出现在使用它的地方之前(ISPP似乎只有一次通过),并包含AppName的定义,这将给出我想要的结果,而不必为其定义额外的宏我们想要提取的每个设置。

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. 因此,您可以使用Inno Setup Preprocessor附件来定义此类常量。 (You can install it easily via the QuickStart pack ). (您可以通过QuickStart包轻松安装)。

Define the constant: 定义常量:

#define AppName "Excellent Foo App"

Use the constant in [Setup] : [Setup]使用常量:

AppName={#AppName}

And in Pascal code, I'm not totally sure of the syntax, but something like: 在Pascal代码中,我不完全确定语法,但是类似于:

MyString := {#AppName}

Update: I realised one of my scripts uses {#emit SetupSetting("AppId")} which is easier. 更新:我意识到我的一个脚本使用{#emit SetupSetting("AppId")}这更容易。 Brian's solution also discovered this method, and is better. Brian的解决方案也发现了这种方法,并且更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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