2012-05-16 34 views
1

我的产品版本为w.x.y.z.我对该产品的升级版本是w.x.y.z + 1。但是要求在升级版本的第四个字段之前,即: z不应该被检查......即;我的产品不应该考虑z领域.....请回答我的答案。显示产品版本?

+1

请您详细说明您的描述吗?如果我明白你希望你的补丁(产品的更新版本)在它存在时更新旧版本,但它应该只检查产品版本的W.X.Y而不是完整的W.X.Y.Z? – RobeN

+0

是的,这是真的,你让我的权利....你可以请建议我该怎么做,以及如何排除产品版本的Z的检查.... – Prakash

回答

1

您可以从注册表中读取您的应用程序版本并将其保留为变量,然后将其修剪为特定数量的字符。检查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 
+1

谢谢罗宾,其工作......另一个问题是产品版本号4.1.119和4.01.0119之间是否有区别? – Prakash

+0

这是他们如何比较?安装者是否认为两者是相同的? – Prakash

+1

命令$ strstr是什么...这是如何工作的?例如 – Prakash

1

在这种情况下,这可以是一个解决方案(基于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 
+1

hey robe得到了解决方案... Strcpy $ 0 $ 0 7 ... $ 0是从卸载注册表中读取的版本该产品安装... strcpy只读取版本的前7个字符...所以第四个字段不读...谢谢你给的支持...如果有其他问题,将得到intouch ... – Prakash

+0

如果我的任何答案都能帮助你,请给他们投票。谢谢。 – RobeN

+0

嗨,@ user1357950,如果它帮助您解决您的问题,请考虑[[接受答案]](http://meta.stackexchange.com/a/5235/179541)。您也可以通过点击帖子左侧的投票数字上方的向上箭头投票选择帖子;-)谢谢! – TLama