Nsis 产品版本的显示?
我的产品版本为w.x.y.z。我对该产品的升级版本为w.x.y.z+1。但要求在升级版本的第四个字段之前,即:;不应检查z…即;myproduct不应考虑z字段……请回答我。您可以从注册表读取应用程序版本并将其作为变量保留,然后将其修剪为特定字符数。检查 下面的脚本适用于Nsis 产品版本的显示?,nsis,Nsis,我的产品版本为w.x.y.z。我对该产品的升级版本为w.x.y.z+1。但要求在升级版本的第四个字段之前,即:;不应检查z…即;myproduct不应考虑z字段……请回答我。您可以从注册表读取应用程序版本并将其作为变量保留,然后将其修剪为特定字符数。检查 下面的脚本适用于ANSI NSIS,如果您安装了此类版本,请相应更改ReadRegStr Name "TrimTest" OutFile "TrimTest.exe" !include "TextFunc.nsh" !include "nsD
ANSI NSIS
,如果您安装了此类版本,请相应更改ReadRegStr
Name "TrimTest"
OutFile "TrimTest.exe"
!include "TextFunc.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "WordFunc.nsh"
!insertmacro VersionCompare
Function TrimText
Exch $R0 ; char
Exch
Exch $R1 ; length
Exch 2
Exch $R2 ; text
Push $R3
Push $R4
StrLen $R3 $R2
IntCmp $R3 $R1 Done Done
StrCpy $R2 $R2 $R1
StrCpy $R3 0
IntOp $R3 $R3 + 1
StrCpy $R4 $R2 1 -$R3
StrCmp $R4 "" Done
StrCmp $R4 $R0 0 -3
IntOp $R3 $R3 + 1
StrCpy $R4 $R2 1 -$R3
StrCmp $R4 "" Done
StrCmp $R4 $R0 -3
IntOp $R3 $R3 - 1
StrCpy $R2 $R2 -$R3
StrCpy $R2 $R2
Done:
StrCpy $R0 $R2
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Exch $R0 ; output
FunctionEnd
!macro TrimText Text Length Char Var
Push "${Text}"
Push "${Length}"
Push "${Char}"
Call TrimText
Pop "${Var}"
!macroend
!define TrimText "!insertmacro TrimText"
Section
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\NSIS ANSI" "DisplayVersion"
${TrimText} $0 7 "-" $R0
;set max lenght to 7, where only 6 chars are needed, as trimmer will stop on - char
;in your case you will probably want to trim to first . from right side
;${TrimText} "string" "max_length" "up_to_char" "$out_var"
MessageBox MB_ICONEXCLAMATION "Line: $R0"
;Input $0 from registry should be "2.46.4-ANSI" if the latest ANSI NSIS is installed
;$R0 after trimm will be "Line: 2.46.4"
${VersionCompare} $R0 "2.46.6" $R2
${If} $R2 == 1 ;if 2.46.6 is lower that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is newer than this version of update"
${EndIf}
${If} $R2 == 0 ;versions are equal
MessageBox MB_ICONEXCLAMATION "Your App Version is equal to this version of update"
${EndIf}
${If} $R2 == 2 ;if 2.46.6 is higher that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is older and will be updated"
;here you can write your update section
${EndIf}
SectionEnd
在这种情况下,这可以是一个解决方案(基于)。 我创建了测试注册表项,只是为了检查您的
{3.1.1234.0.1124.1.119}
。请替换为应用程序使用的
Name "TrimTest2"
OutFile "TrimTest2.exe"
!include "TextFunc.nsh"
!include "nsDialogs.nsh"
!include "LogicLib.nsh"
!include "WinMessages.nsh"
!include "WordFunc.nsh"
!insertmacro VersionCompare
Function AdvStrSort
Exch $0 ; input string
Exch
Exch $1 ; count to get part
Exch
Exch 2
Exch $2 ; get ammount of chunks from end
Exch 2
Push $3
Push $4
Push $5
Push $6
Push $7
StrCpy $0 " $0"
StrCpy $3 0
StrCpy $4 0
loop:
IntOp $3 $3 - 1
StrCpy $6 $0 1 $3
StrCmp $6 "" skip
StrCmp $6 " " roger ; to change chunk seperators, edit this (" ")
Goto loop
roger:
StrCpy $7 $0 "" $3
IntOp $4 $4 + 1
StrCmp $4 $2 0 loop
StrCmp $1 $2 0 +3
StrCpy $0 $7
Goto end
skip:
StrCpy $4 0
StrLen $5 $7
top:
IntOp $4 $4 + 1
loop2:
IntOp $5 $5 - 1
StrCpy $3 $7 1 -$5
StrCmp $3 "" end
StrCmp $3 " " 0 loop2 ; to change chunk seperators, edit this too (" ")
StrCmp $4 $1 0 top
StrCpy $0 $7 -$5
end:
StrLen $1 $0
IntOp $1 $1 - 1
StrCpy $0 $0 $1 -$1
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0 ; output string
FunctionEnd
Section
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\UserApplicationName" "Version"
Push 1 ; get text after 1st chunk from string end
Push 1 ; get 1 chunk before the 1st
Push "$R1" ; input string (string that has spaces)
Call AdvStrSort
Pop $R0
MessageBox MB_ICONEXCLAMATION "Result: $R0"
${VersionCompare} $R0 "5.0.114" $R2
;MessageBox MB_ICONEXCLAMATION "Result: $R2"
${If} $R2 == 1 ;if 5.0.114 is lower that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is newer than this version of update"
${EndIf}
${If} $R2 == 0 ;versions are equal
MessageBox MB_ICONEXCLAMATION "Your App Version is equal to this version of update"
${EndIf}
${If} $R2 == 2 ;if 5.0.114 is higher that $R0
MessageBox MB_ICONEXCLAMATION "Your App Version is older and will be updated"
;here you can write your update section
${EndIf}
SectionEnd
你能描述一下吗?如果我知道你希望你的补丁(产品的更新版本)在存在时更新旧版本,但它应该只检查产品版本的W.X.Y而不是完整的W.X.Y.Z?是的,这是真的,你说得对。。。。你能建议我怎么做,以及如何排除产品版本Z的检查…谢谢Roben,它的工作。。。另一个问题是,产品版本号4.1.119和4.01.0119之间是否有任何差异?这就是它们的比较方式?安装程序是否都考虑相同?命令$STRSTR是什么?这是怎么回事?例如${strstrstr}$1“$UPGRADEVERS”“$0”是命令。。此命令背后的工作流程是什么?假设我的upgradevers数组是{3.1.1234.0.1124.1.119}。。。。0美元的版本是5.0.114。。。。罗伯可能是我在打扰你。。。谢谢你的帮助。。。我是新来nsis的,必须寻求像你这样的人的帮助…你能更准确地描述一下那件长袍吗。。。。因为我的产品在注册表中的版本是4.01.0119,如果我在$upgradevers中指定了4.1.119,升级就可以了。。。这怎么可能呢?正如您之前所说,4.01.0119和4.1.119中存在差异。。。。。除了连接子字符串和字符串的其余部分之外,${strstrstr}还有其他的功能吗?我真的很麻烦你。。。抱歉之前…嘿,罗伯有个解决办法。。。Strcpy$0$0$7$0是从已安装产品的卸载注册表读取的版本。。。Strcpy只读取版本的前7个字符。。。所以第四个字段没有被读取。。。谢谢你给我的支持。。。如果有任何其他问题,将获得intouch…如果我的任何答案对您有帮助,请投票表决。谢谢。嗨,USER 135950,考虑一下它是否帮助你解决问题。您也可以通过单击帖子左侧投票编号上方的向上箭头为帖子投票;-)谢谢因为你有16分。你应该可以投票(据我所知,至少15分)。