我的产品版本为w.x.y.z.我对该产品的升级版本是w.x.y.z + 1。但是要求在升级版本的第四个字段之前,即: z不应该被检查......即;我的产品不应该考虑z领域.....请回答我的答案。显示产品版本?
显示产品版本?
回答
您可以从注册表中读取您的应用程序版本并将其保留为变量,然后将其修剪为特定数量的字符。检查http://nsis.sourceforge.net/TrimText:_Trim_text_e.g._to_fit_in_a_label
下面的脚本将工作为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
在这种情况下,这可以是一个解决方案(基于http://nsis.sourceforge.net/Sort_String_2)。 我已经创建了Test Registry Key,只是为了检查您的{3.1.123 4.0.112 4.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
hey robe得到了解决方案... Strcpy $ 0 $ 0 7 ... $ 0是从卸载注册表中读取的版本该产品安装... strcpy只读取版本的前7个字符...所以第四个字段不读...谢谢你给的支持...如果有其他问题,将得到intouch ... – Prakash
如果我的任何答案都能帮助你,请给他们投票。谢谢。 – RobeN
嗨,@ user1357950,如果它帮助您解决您的问题,请考虑[[接受答案]](http://meta.stackexchange.com/a/5235/179541)。您也可以通过点击帖子左侧的投票数字上方的向上箭头投票选择帖子;-)谢谢! – TLama
- 1. 产品版本
- 2. 产品版本号
- 3. 文件版本比。产品版本
- 4. 比较版本中产品版本
- 5. 产品不显示
- 6. 显示产品default_code
- 7. 显示WooCommerce变量产品的最低价格(版本2.5.5)
- 8. 获得产品在Magento显示版本1.7
- 9. WooCommerce产品 - 显示产品对象
- 10. SVN系列产品版本
- 11. 在前端显示产品成本
- 12. 厨师和产品版本 - 不同产品版本的配置环境
- 13. Magento - 显示个别产品
- 14. Opencart没有显示产品
- 15. 显示产品总数
- 16. 显示产品类别
- 17. DNN-显示产品清单
- 18. Spree:显示产品的品牌名称?
- 19. 针对不同产品版本的不同价格的产品
- 20. 产品和副本产品
- 21. 如何仅显示已批准的产品 - 当前显示所有产品
- 22. MVC路线 - 如何自定义/产品/产品详细/ {显示} /产品/ {ID}
- 23. Drupal 7的商业头版视图不显示产品
- 24. 获取产品的最新版本
- 25. 开发产品的不同版本
- 26. 新产品版本的Git分支
- 27. WiX的复制版本产品安装
- 28. VS2010项目的产品版本
- 29. InstallShield在添加/删除程序中显示产品名称+版本
- 30. 如何显示woocommerce组产品中的儿童产品图像?
请您详细说明您的描述吗?如果我明白你希望你的补丁(产品的更新版本)在它存在时更新旧版本,但它应该只检查产品版本的W.X.Y而不是完整的W.X.Y.Z? – RobeN
是的,这是真的,你让我的权利....你可以请建议我该怎么做,以及如何排除产品版本的Z的检查.... – Prakash