NSIS 版本号比较函数
(2011-07-15 10:31:53)
标签:
nsis版本号比较it |
分类: NSIS |
原文:http://nsis.sourceforge.net/Comparing_Two_Version_Numbers
- ;
From:http://nsis.sourceforge.net/Comparing_Two_Version_Numbers - ;
Created by Comperio - ;
- ;
Usage: - ;
${VersionCheck} "Version2" "outputVar" - ;
Version1 = version number - ;
Version2 = version number - ;
outputVar = Variable used to store the ouput - ;
- ;
Return values: - ;
= both versions are equal - ;
= 1Version is NEWER 2than version - ;
= isVersion1 OLDER 2than version - ;
Rules Version Numbers: - ;
Version numbers must always be a string of numbers only. (A dot - ;
the isname optional). - ;
- ;
[Variables] - var
P1 "remember"; file pointer, used to the inposition the Version1 string - var
P2 "remember"; file pointer, used to the inposition the Version2 string - var
V1 from;version number Version1 - var
V2 from;version number Version2 - Var
Reslt return; holds the flag - ;
[Macros] - !macro
VersionCheck Ver1 Ver2 OutVar -
; To make this work, one character must be added to the version string: -
Push -
Push -
Call VersionCheckF -
Pop ${OutVar} - !macroend
- ;
[Defines] - !define
VersionCheck "!insertmacroVersionCheck" - ;
[Functions] - Function
VersionCheckF -
Exch $ ; 1$ contains 1Version -
Exch -
Exch $ ; 2$ contains 2Version -
Exch -
Push $R0 -
; initialize Variables -
StrCpy $V1 "" -
StrCpy $V2 "" -
StrCpy $P1 "" -
StrCpy $P2 "" -
StrCpy $Reslt "" -
; Set the file pointers: -
IntOp $P1 $P1 + -
IntOp $P2 $P2 + -
; ******************* Get version fornumber Ver1 ********************** -
V11: -
; I use $ and $ 2to "Ver1"help keep identify vs. "Ver2" -
StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
IntOp $P1 $P1 + ;increments the file pointer the next read -
StrCmp $R0 "" V11end ;check empty string -
strCmp $R0 v11end 0 -
strCpy $V1 -
Goto V11 -
V11End: -
StrCmp $V1 "" + 2 -
StrCpy $V1 -
; ******************* Get version fornumber Ver2 ********************** -
V12: -
StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
IntOp $P2 $P2 + ;increments the file pointer the next read -
StrCmp $R0 "" V12end ;check empty string -
strCmp $R0 v12end 0 -
strCpy $V2 -
Goto V12 -
V12End: -
StrCmp $V2 "" + 2 -
StrCpy $V2 -
; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont1 older1 newer1 -
older1: ; Version is older 2(less than) than version -
StrCpy $Reslt -
Goto ExitFunction -
newer1: ; Version is newer 2(greater than) Version -
StrCpy $Reslt -
Goto ExitFunction -
Cont1: ;Versions are the same. Continue searching differences -
; Reset $V1 $V2 -
StrCpy $V1 "" -
StrCpy $V2 "" -
; ******************* Get version fornumber Ver1 ********************** -
V21: -
StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
IntOp $P1 $P1 + ;increments the file pointer the next read -
StrCmp $R0 "" V21end ;check empty string -
strCmp $R0 v21end 0 -
strCpy $V1 -
Goto V21 -
V21End: -
StrCmp $V1 "" + 2 -
StrCpy $V1 -
; ******************* Get version fornumber Ver2 ********************** -
V22: -
StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
IntOp $P2 $P2 + ;increments the file pointer the next read -
StrCmp $R0 "" V22end ;check empty string -
strCmp $R0 V22end 0 -
strCpy $V2 -
Goto V22 -
V22End: -
StrCmp $V2 "" + 2 -
StrCpy $V2 -
; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont2 older2 newer2 -
older2: ; Version is older 2(less than) than version -
StrCpy $Reslt -
Goto ExitFunction -
newer2: ; Version is newer 2(greater than) Version -
StrCpy $Reslt -
Goto ExitFunction -
Cont2: ;Versions are the same. Continue searching differences -
; Reset $V1 $V2 -
StrCpy $V1 "" -
StrCpy $V2 "" -
; ******************* Get version fornumber Ver1 ********************** -
V31: -
StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
IntOp $P1 $P1 + ;increments the file pointer the next read -
StrCmp $R0 "" V31end ;check empty string -
strCmp $R0 v31end 0 -
strCpy $V1 -
Goto V31 -
V31End: -
StrCmp $V1 "" + 2 -
StrCpy $V1 -
; ******************* Get version fornumber Ver2 ********************** -
V32: -
StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
IntOp $P2 $P2 + ;increments the file pointer the next read -
StrCmp $R0 "" V32end ;check empty string -
strCmp $R0 V32end 0 -
strCpy $V2 -
Goto V32 -
V32End: -
StrCmp $V2 "" + 2 -
StrCpy $V2 -
; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont3 older3 newer3 -
older3: ; Version is older 2(less than) than version -
StrCpy $Reslt -
Goto ExitFunction -
newer3: ; Version is newer 2(greater than) Version -
StrCpy $Reslt -
Goto ExitFunction -
Cont3: ;Versions are the same. Continue searching differences -
; Reset $V1 $V2 -
StrCpy $V1 "" -
StrCpy $V2 "" -
; ******************* Get version fornumber Ver1 ********************** -
V41: -
StrCpy $R0 $ 1 $P1 ;$R0 contains the character at position $P1 -
IntOp $P1 $P1 + ;increments the file pointer the next read -
StrCmp $R0 "" V41end ;check empty string -
strCmp $R0 v41end 0 -
strCpy $V1 -
Goto V41 -
V41End: -
StrCmp $V1 "" + 2 -
StrCpy $V1 -
; ******************* Get version fornumber Ver2 ********************** -
V42: -
StrCpy $R0 $ 1 $P2 ;$R0 contains the character at position $P1 -
IntOp $P2 $P2 + ;increments the file pointer the next read -
StrCmp $R0 "" V42end ;check empty string -
strCmp $R0 V42end 0 -
strCpy $V2 -
Goto V42 -
V42End: -
StrCmp $V2 "" + 2 -
StrCpy $V2 -
; At this point, we can compare the results. If the numbers are -
; equal, then we can exit -
IntCmp $V1 $V2 cont4 older4 newer4 -
older4: ; Version is older 2(less than) than version -
StrCpy $Reslt -
Goto ExitFunction -
newer4: ; Version is newer 2(greater than) Version -
StrCpy $Reslt -
Goto ExitFunction -
Cont4: -
;Versions are the same. We've reached the end of the version -
; strings, so set the function to (equal) andexit -
StrCpy $Reslt -
ExitFunction: -
Pop $R0 -
Pop $ -
Pop $ -
Push $Reslt - FunctionEnd