InnoSetup:在 [Code] 部分获取 AppName

发布于 2024-08-16 04:16:57 字数 616 浏览 4 评论 0原文

我正在使用 InnoSetup 创建安装程序,并在 [Code 中编写一些自定义处理程序] 部分。在其中一个处理程序中,我希望能够检索 [Setup] 中定义的 AppName 的值(或者可能是其他参数的值)部分。我有办法做到这一点吗?我已经查看了 文档,但没有找到任何可以让我执行此操作的内容。我们的 InnoSetup 文件实际上是由我们的构建过程生成的,它将所有程序之间通用的片段和特定于程序的片段缝合在一起,因此必须在每个程序的代码中定义常量会很不方便。有什么方便的方法可以做到这一点吗?

我正在寻找类似的东西

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

except {AppName} is not a Defined Constant.有没有办法查询 [Setup] 部分中定义的参数?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三寸金莲 2024-08-23 04:16:57

受到 Craig 的回答的启发,我正在查看 Inno Setup 预处理器文档(在 ISTool 中,据我所知,在网上无法找到),并在预处理器中遇到了 SetupSetting 函数。

它可以这样使用:

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

并且只要 [Setup] 部分出现在使用它的地方之前(ISPP 似乎只有一步),并且包含 AppName 的定义,这将给出我想要的结果,而不必为我们想要提取的每个设置定义额外的宏。

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.

江湖彼岸 2024-08-23 04:16:57

它是构建时常量,而不是安装时值。因此,您可以使用 Inno Setup Preprocessor 插件来定义此类常量。 (您可以通过快速入门包轻松安装它)。

定义常量:

#define AppName "Excellent Foo App"

[Setup]中使用常量:

AppName={#AppName}

在Pascal代码中,我不完全确定语法,但类似于:

MyString := {#AppName}

更新:我意识到了一个我的脚本使用 {#emit SetupSetting("AppId")} 这更容易。 Brian的解决方案也发现了这个方法,而且更好。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文