比较 "已安装版本 "与 "待安装版本"。

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

使用NSIS(v3.05)已经有几个星期了。做了它需要做的事情。几天来一直在追问下面的问题,一直不能完全理解。问题说明:两(2)个版本相互比较。有很多方法可以实现。 我选择了以下方式:第1个'版本'(字符串)通过(函数)LineRead(!include TextFunc.nsh)从当前安装的版本.txt文件中检索,像这样。

IfFileExists "C:\$PROGRAMFILES64\...\VERSION.txt" 0 +31 # Open the file and perform N FileRead 
    DetailPrint "VERSION.txt found!"   
    ${LineRead} "C:\$PROGRAMFILES64\...\VERSION.txt" "7" $4  # $4 = '1.x.y.z' (for example)

第2个'版本'用下面的代码检索。

!getdllversion "C:\...\application_name.exe" expversion_
StrCpy $7 ${expversion_}  # pass the define string 'expversion' to $7

作为最后一部分,我使用以下代码来比较$4和$7。

${VersionCompare} $4 $7 $R0

只有当我确定'$4'(版本字符串#1)和'$7'(版本字符串#2)是VersionCompare的正确输入时,这才会有效(输出:$R0)

问题:是否有办法显示(为testcheck)$4的内容(@编译时),以确定var$4包含正确的字符串传递给函数 "VersionCompare"?是否有办法显示(用于testcheck)$4的内容(在编译时),以确定var $4包含正确的字符串,并传递给函数 "VersionCompare"?(试过'DetailPrint $4';没有解析成预期的字符串(由函数'LineRead'检索)。(我知道'DetailPrint'只在执行安装过程中显示'.exe.文件,所以是有意义的,在编译时没有看到。)

Output from MakeNSIS:
IfFileExists: "C:\$PROGRAMFILES64\...\VERSION.txt" ? 0 : +31
DetailPrint: "VERSION.txt found!"
!insertmacro: LineReadCall
!insertmacro: end of LineReadCall
DetailPrint: "The version number of the currently installed app: $4"

如何让4美元解析成版本字符串(用于测试目的)在编译时)?

问题2:我在一个函数中使用预处理器命令'!GetDLLVersion'来检索'app'的待安装版本的版本号(通过NSIS安装程序...)。MakeNSIS会正确显示解析版本。

Function: "VersionRetrievalBinary"
!getdllversion: C:\1_SW_dev\...\app.exe (1.8.47.5)->(expversion_<1..4>)

问题:"expverion_name "到底是什么?'expverion_'到底是什么,是var还是定义?如果是定义(我在这里读到的是=> 参考!getdllversion),我是否需要在我的脚本中定义它,如下所示?

!define expverion_1 " "  # Major; single digit
!define expverion_2 "  "  # Minor; 2-digit
!define expverion_3 "   " # Build; 3-digit
!define expverion_4 "   "# Revision; 3-digit

由于不知道 "expversion_"到底是什么,以及Operationsworks MakeNSIS抛出了以下警告,我认为... ...这显然表明有些地方是不正确的。

warning 6000: unknown variable/constant "{expversion_}" detected, ignoring (C:\1_SW_dev\...\app_client.nsi:295)

令人担忧的部分是''''这个词。无视'在MakeNSIS编译信息中。从上面提到的警告信息中,我是否可以得出这样的结论:从(define?)衍生出的名为 "expversion_"的字符串没有通过命令传递给var $7。

StrCpy $7 ${expversion_}

下面的MakeNSIS消息(@编译时)似乎证实了这一点。

StrCpy $7 "${expversion_}" () ()

它似乎是空的(不确定我是否正确阅读了这个MakeNSIS消息)。

虽然我学了很多关于NSIS的知识(并且很喜欢它),并且查阅了大部分相关的文档,但我还是不明白这个问题。

Thnx in advance for solving this specific piece of the puzzle.

自己已经解决了这个难题。版本对比的解决方案相当 "简单"。必备的部分在此。 (添加到.onInit)

  1. 创建一个函数(例如名称为'VersionComparison')
  2. 从注册表中读取本地版本
  3. 从二进制文件(如.DLL或.exe)中读取安装版本。
  4. 使用VersionCompare(!include WordFunc.nsh)来进行实际比较。
nsis
1个回答
0
投票

我来解决 !getdllversion 先发。它提取了4个16位的数字,从开头的 版本信息块 并将它们存储在4个定义中。它只是在命名定义时使用你传入的名称加上一个数字。

!getdllversion "$%windir%\explorer.exe" foo
!warning ${foo2} ; This prints the minor version

并没有像您所期望的那样有特定的数字。4个数字中的每一个都是从0到65535。

你可以在编译时对这些数字进行基本验证。

!if ${foo1} < 1
!error "Major version must at least be 1, we don't ship beta software :) " 
!endif

第二个问题比较难解决 变量只有在安装程序运行时才能展开。唯一的选择是在你的主.nsi中实际生成并运行一个 "安装程序"。

!makensis vertest.nsi = 0
!execute '"$%temp%\vertest.exe" /S' = 0
!defile "$%temp%\vertest.exe" 

其中vertest.nsi会是这样的:

OutFile "$%temp%\vertest.exe" 
RequestExecutionLevel user
SilentInstall silent

Section
Do version test here and Goto.. 
fail:
Abort
success:
SectionEnd
© www.soinside.com 2019 - 2024. All rights reserved.