How to set ISPP defines based on default Inno Setup variables?

℡╲_俬逩灬. 提交于 2019-12-24 01:03:55

问题


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?


回答1:


{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.




回答2:


#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.




回答3:


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

#define CommonAppData {{commonappdata}


来源:https://stackoverflow.com/questions/5043960/how-to-set-ispp-defines-based-on-default-inno-setup-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!