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

Inno setup 使用Inno Setup提取应用程序版本号(但不包括第四个版本号),inno-setup,Inno Setup,我一直在感兴趣地阅读有关在编译安装文件期间使用API调用从可执行文件中提取信息的内容。例如: 在我的脚本中,我有以下内容: [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 "{co

我一直在感兴趣地阅读有关在编译安装文件期间使用API调用从可执行文件中提取信息的内容。例如:

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

[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
#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}
我已经删掉了很多。我只是想让你看看我在做什么。现在,我的可执行文件具有以下版本信息:

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

我不想让我的脚本过于复杂。只需更改
AppVerText
I will的
ISPP
值就会更容易。但如果我能使它自动化,它将减少一个维护问题

更新 根据答案,我添加了以下代码:

#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
,如下所示:

[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
#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}
但它抱怨说:

以任何方式使用并组装版本字符串:

#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.exe
。。。但它失败了

是一个预处理器函数,您在预处理器表达式中使用它,就像
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])
虽然我个人会使用这样的预处理程序定义:

[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
#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}

最后,请注意,这些代码示例使用了一个名为的数组。这就是为什么
AppVerText
被声明为一个无参数宏(请注意
AppVerText
后面的空括号),而不仅仅是一个变量。变量声明没有
Local
数组,而宏声明有