简体   繁体   English

在Inno Setup中使用Define和Constant

[英]Use Define and Constant in Inno Setup

I've a question about the #define in Inno Setup. 我对Inno Setup中的#define有疑问。 I've make a setup who's working well and i'm thinking of the future of app if i have some modification to do. 如果我做了一些修改,我会设置一个运行良好的设置,我正在考虑app的未来。 For example, if i change the version (Major, Minor, Build, Patch,...) i doesn't want to change all the line (like Registry) at each time. 例如,如果我更改版本(Major,Minor,Build,Patch,...),我不想每次都更改所有行(如Registry)。

So i try to make something like that : 所以我试着做出类似的东西:

#define MyAppMajor "5"
#define MyAppMinor "5"
#define MyAppBuild "1"
#define MyAppPatch "1"

...

[Files]    
Source: "D:\ProgramFiles\..."; DestDir: "{app}\Program\{MyAppMajor}.{MyAppMinor}\"; Flags: ignoreversion;

[Registry]
Root: "HKLM32"; Subkey: "Software\program\"; ... ; ValueData: "{MyAppMajor}.{MyAppMinor}.{MyAppBuild}.{MyAppPatch}";

But that doesn't compile and it says : 但这不编译,它说:

"Unknown constant "MyAppMajor".Use two consecutive "{" characters if you are trying to embed a single "{" and not a constant" . “Unknown constant”MyAppMajor“。如果你试图嵌入单个”{“而不是常量,则使用两个连续的”{“字符

Is there a way to do something like that for versionning or another constant ? 有没有办法为版本化或其他常量做类似的事情?

You missed to use the # char (or #emit , which is the longer version of the same), that is used to inline a defined variable into the script, eg: 你错过了使用#字符(或#emit ,这是相同的更长的版本),用来内联定义的变量到脚本,例如:

#define MyAppMajor "5"
#define MyAppMinor "5"
#define MyAppBuild "1"
#define MyAppPatch "1"

[Files]
...; DestDir: "{app}\Program\{#MyAppMajor}.{#MyAppMinor}\"; Flags: ignoreversion;

[Registry]
...; ValueData: "{#MyAppMajor}.{#MyAppMinor}.{#MyAppBuild}.{#MyAppPatch}";

When missing this, the compiler expected (built-in) constants called MyAppMajor , MyAppMinor etc., whose doesn't exist; 当缺少这个时,编译器期望(内置)常量称为MyAppMajorMyAppMinor等,它们不存在; hence the error. 因此错误。

But, what you're trying to replicate is probably built-in in Inno Setup as the AppVersion directive. 但是,您尝试复制的内容可能是Inno Setup中内置的AppVersion指令。 It might be useful eg in conjunction of reading the version of the application binary from its included file version information: 它可能是有用的,例如结合从其包含的文件版本信息中读取应用程序二进制文件的版本:

#define AppVersion GetFileVersion('C:\MyApp.exe')

[Setup]
...
AppVersion={#AppVersion}

Although I haven't found something in Inno's documentation explicitly stating it, there is an example where the + operator is used to concatenate strings. 虽然我没有在Inno的文档中找到明确说明它的东西,但有一个例子,其中+运算符用于连接字符串。 I think you can get by with something like this: 我想你可以用这样的东西:

Source: "D:\ProgramFiles\..."; DestDir: "{app}\Program\" + MyAppMajor + "." + MyAppMinor + "\"; Flags: ignoreversion;

If that doesn't work, there is a StringChange preprocessor macro that should work but will be uglier, especially in strings with multiple substitutions: 如果这不起作用,有一个StringChange预处理器宏应该可以工作,但会更加丑陋,特别是在具有多个替换的字符串中:

#define MyAppMajor "5"
#define MyAppMinor "5"

#define InstallDirectory StringChange(StringChange("{app}\Program\%major%.%minor%", "%major", MyAppMajor), "%minor%", MyAppMinor)

Source: "D:\ProgramFiles\..."; DestDir: InstallDirectory; Flags: ignoreversion;

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

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