InnoSetup:在 [Code] 部分获取 AppName
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
受到 Craig 的回答的启发,我正在查看 Inno Setup 预处理器文档(在 ISTool 中,据我所知,在网上无法找到),并在预处理器中遇到了
SetupSetting
函数。它可以这样使用:
并且只要
[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:
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 forAppName
, this will give the results I want, without having to define an extra macro for each setting we want to extract.它是构建时常量,而不是安装时值。因此,您可以使用 Inno Setup Preprocessor 插件来定义此类常量。 (您可以通过快速入门包轻松安装它)。
定义常量:
在
[Setup]
中使用常量:在Pascal代码中,我不完全确定语法,但类似于:
更新:我意识到了一个我的脚本使用
{#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:
Use the constant in
[Setup]
:And in Pascal code, I'm not totally sure of the syntax, but something like:
Update: I realised one of my scripts uses
{#emit SetupSetting("AppId")}
which is easier. Brian's solution also discovered this method, and is better.