我一直在阅读有兴趣阅读使用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
我已经砍掉了很多。我只想告诉你我在做什么。现在,我的可执行文件具有以下版本信息:
鉴于上述设置,我是否可以提取版本号,但只有 18.1.5 位(我没有显示第四个值)因为它通常用于内部的β增量。)
我不想让我的脚本过于复杂。更改ISPP
我AppVerText
的{{1}}值会更容易。但如果我可以自动化它,它将减少一个维护问题。
根据答案,我添加了以下代码:
#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])
但它抱怨道:
答案 0 :(得分:1)
使用ParseVersion
preprocessor function,然后按照您喜欢的方式组装版本字符串:
#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
...但它失败了。
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
的数组。这就是为什么AppVerText
被声明为无参数宏(注意AppVerText
之后的空括号),而不仅仅是变量。变量声明没有Local
数组,而宏声明则没有。