使用Inno Setup提取应用程序版本号(但不包括第四个数字)

问题描述 投票:2回答:1

我一直在阅读有关在安装文件编译期间使用API​​调用从可执行文件中提取信息的兴趣。例如:Using GetStringFileInfo in Setup section of Inno Setup

在我的脚本中,我有以下内容:

[ISPP]
; Please, don't edit this section manually if you don't know what are you doing.
#define DataDir "{userappdata}\Meeting Schedule Assistant"
#define CommonDataDir "{commonappdata}\Meeting Schedule Assistant"
#define AppVerText "18.1.5"
#define AppURL "http://www.publictalksoftware.co.uk"
#define AppPublisher "Andrew Truckle"

此刻,我像这样使用上面的内容:

[Setup]
AppName=Meeting Schedule Assistant
AppPublisher={#AppPublisher}
AppPublisherURL={#AppURL}
AppSupportURL={#AppURL}
AppUpdatesURL={#AppURL}
DefaultDirName={pf}\Meeting Schedule Assistant
DefaultGroupName=Meeting Schedule Assistant
SourceDir=..\Meeting Schedule Assistant\Release
; NOTE: Paths are now RELATIVE to ..\Release
; NOTE: But NOT for #includes
OutputDir=..\..\inno\Output
OutputBaseFilename=MeetSchedAssistSetup
AppCopyright=Andrew Truckle © 2003 - 2018
AppVersion={#AppVerText}
VersionInfoVersion={#AppVerText}
VersionInfoCompany={#AppPublisher}
VersionInfoDescription=Meeting Schedule Assistant
VersionInfoTextVersion={#AppVerText}
VersionInfoCopyright=Andrew Truckle © 2003 - 2018

我已经把它剪掉了。我只是想告诉你我在做什么。现在,我的可执行文件具有以下版本信息:

Version Info

鉴于上述设置,我是否可以提取版本号,但是,仅18.1.5位(我不显示第四个值,因为它通常用于beta内部递增)。

我不想使我的脚本过于复杂。只需将我的ISPP值更改为AppVerText,将会变得更加容易。但是,如果我可以使它自动化,它将减少一个维护问题。

更新

基于答案,我添加了此代码:

#define AppVerText() \
   ParseVersion('..\Meeting Schedule Assistant\Release\Meeting Schedule Assistant.exe', Local[0], Local[1], Local[2], Local[3]), \
   Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2])

我尝试将其更改为使用{#SetupSetting('SourceDir')}\Meeting Schedule Assistant.exe,如下所示:

#define AppVerText() \
   ParseVersion('{#SetupSetting('SourceDir')}\Meeting Schedule Assistant.exe', Local[0], Local[1], Local[2], Local[3]), \
   Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2])

但它抱怨:

Error

inno-setup
1个回答
2
投票

使用ParseVersion preprocessor function,然后以任何您喜欢的方式组合一个版本字符串:

ParseVersion

我尝试将其更改为使用#define AppVerText() \ ParseVersion('MyProg.exe', Local[0], Local[1], Local[2], Local[3]), \ Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2]) [Setup] AppVersion={#AppVerText} ...,但失败。

{#SetupSetting('SourceDir')}\Meeting Schedule Assistant.exepreprocessor函数,您可以在预处理器表达式中使用它,就像SetupSetting一样。因此,不要再使用SetupSetting跳到预处理器了,因为您已经在那里。这是正确的语法:

ParseVersion

尽管我个人会使用这样的前处理器定义:

{# ... }

最后,请注意,这些代码示例使用名为#define AppVerText() \ ParseVersion(SetupSetting('SourceDir') + '\Meeting Schedule Assistant.exe', \ Local[0], Local[1], Local[2], Local[3]), \ Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2]) 的数组。这就是将#define SourceDir "..\Meeting Schedule Assistant\Release" #define AppVerText() \ ParseVersion(SourceDir + '\Meeting Schedule Assistant.exe', \ Local[0], Local[1], Local[2], Local[3]), \ Str(Local[0]) + "." + Str(Local[1]) + "." + Str(Local[2]) [Setup] SourceDir={#SourceDir} AppVersion={#AppVerText} 声明为无参数宏的原因(请注意Local之后的空括号),而不是仅仅将其声明为变量。变量声明不具有Local数组,而宏声明具有。

© www.soinside.com 2019 - 2024. All rights reserved.