如何根据默认的 Inno Setup 变量设置 ISPP 定义?

发布于 2024-10-18 02:40:01 字数 206 浏览 2 评论 0原文

我试图:

#define CommonAppData {commonappdata}

但它产生:

编译器错误

[ISPP] 需要表达式,但找到左大括号 (“{”)。

如何使用 Inno Setup PreProcessor 来实现这一点?

I was trying to:

#define CommonAppData {commonappdata}

but it yields:

Compiler Error

[ISPP] Expression expected but opening brace ("{") found.

How to achieve this with Inno Setup PreProcessor?

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

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

发布评论

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

评论(3

醉生梦死 2024-10-25 02:40:01

{commonappdata} 无法在编译时扩展,即当预处理器运行时,因为它仅在运行时已知:它标识编译安装程序所在计算机上的公共应用程序数据目录运行。

也许如果您能澄清您打算如何使用该定义,我们也许可以提供帮助。例如,如果您真正感兴趣的不是目标计算机上的公共应用程序数据目录,而是开发人员计算机上的公共应用程序数据目录,那么您可能可以使用此:

#define CommonAppData GetEnv("COMMONAPPDATA")

但是,如果您打算使用该定义来填充 Inno 属性,它们本身能够在运行时扩展常量,那么您应该使用它:

#define CommonAppData "{commonappdata}"

希望这会有所帮助。

{commonappdata} cannot be expanded at compile time, i.e. when the pre-processor runs because it is only known at runtime: It identifies the common application data directory on the machine where the compiled installer is run.

Maybe if you could clarify how you intend to use that define we might be able to help. If for example what you're really interested in is not the common app data directory on the target machine but the one on the developer machine, then you can probably use this:

#define CommonAppData GetEnv("COMMONAPPDATA")

If however you intend to use that define for populating Inno properties that are themselves capable of expanding the constant at runtime then you should use this:

#define CommonAppData "{commonappdata}"

Hope this helps.

白馒头 2024-10-25 02:40:01

#define 是一个 inno setup 预处理器指令,处于预编译阶段。它的工作方式很像 C 预处理器。

通过定义预处理器变量,我们强制编译器在 ispp 定义解析后查看脚本:

Inno Setup Preprocessor (ISPP) 是 Jordan Russell 的 Inno Setup 编译器的附加组件。从技术上讲,它是 GUI(您的 Inno Setup 脚本)和编译器之间的附加层,在传递文本之前,它会通过在脚本文本中使用特殊指令来拦截并修改它。

也就是说,我无法在文档中找到源代码,也没有时间深入研究源代码,但我很确定 inno 设置变量在预​​编译期间不可用。

如果您只希望定义的变量包含字符串 {commonappdata},请直接在源中使用它...如果您希望定义的变量具有 commonappdata 的运行时值,则不需要对我来说这似乎是可能的,因为该值是在运行时确定的,因为它的当前值取决于目标机器(Windows 版本、语言等)。

如果您三思而后行,那么尝试在预编译或编译时使用该值是没有意义的...这就是带来像 {commonappdata} 这样的 inno 设置常量的全部事实、 {destdir} 等存在...您可以在编译时以标准方式表达未知但有意义的值,该值将在运行时已知并评估。

#define is a inno setup pre-processor directive, in a pre-compile phase. It works much like a C pre-processor.

By defining a pre-processor variable, we force the compiler to see a script after the ispp defines are resolved:

Inno Setup Preprocessor (ISPP) is an add-on for Jordan Russell's Inno Setup compiler. More technically speaking, it is an additional layer between GUI (your Inno Setup script) and the compiler, which before passing the text intercepts and modifies it in a way it is told by using special directives in the script text.

That said, I can't find a source in documentation nor have time to digg into the source code, but I'm pretty sure inno setup variables are not available during this pre-compile time.

If you just want the defined variable to contain the string {commonappdata}, use it directly in your source... if you want the defined variable to have the run-time value of commonappdata, it doesn't seem possible to me, because that value is determined at runtime as its current value depends on the target machine (windows version, language, etc.).

If you think it twice, it doesn't make sense to try to use that value at pre-compile or compile time... this is just the whole fact that brings inno setup constants like {commonappdata}, {destdir} and the like to existence... that you can express in a standard way at compile time a unknown but meaningful value, which will be known and evaluated at runtime.

影子是时光的心 2024-10-25 02:40:01

您可能需要摆脱支架。像这样的东西:

#define CommonAppData {{commonappdata}

You'll probably need to escape the brace. Something like:

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