VersionConvert: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
No edit summary
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{|align=right
{{PageAuthor|Instructor}}
|<small>Author: [[{{ns:2}}:Instructor|Instructor]] ([[{{ns:3}}:Instructor|talk]], [[{{ns:-1}}:Contributions/Instructor|contrib]])</small>
|}
<br style="clear:both;">
== Links ==
; Latest version of headers "nsh.zip" (not in those yet):
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost


== The Function ==
{{User:Instructor/Headers/Template}}
<highlight-nsis>/*
 
== Function Description ==
 
<highlight-nsis>
____________________________________________________________________________
____________________________________________________________________________


Line 34: Line 31:
-Converted letters are separated with dot
-Converted letters are separated with dot
-If character is non-digit and not in list then it will be converted to dot
-If character is non-digit and not in list then it will be converted to dot
</highlight-nsis>






Example1:
<b>Example1:</b>
Section
<highlight-nsis>Section
${VersionConvert} "9.0a" "" $R0
${VersionConvert} "9.0a" "" $R0
; $R0="9.0.01"
; $R0="9.0.01"
Line 48: Line 46:
; $R2="2"  version2 is newer
; $R2="2"  version2 is newer
SectionEnd
SectionEnd
</highlight-nsis>


Example2:
<b>Example2:</b>
Section
<highlight-nsis>Section
${VersionConvert} "0.15c-9m" "" $R0
${VersionConvert} "0.15c-9m" "" $R0
; $R0="0.15.03.9.13"
; $R0="0.15.03.9.13"
Line 60: Line 59:
; $R2="1"  version1 is newer
; $R2="1"  version1 is newer
SectionEnd
SectionEnd
</highlight-nsis>


Example3:
<b>Example3:</b>
Section
<highlight-nsis>Section
${VersionConvert} "0.15c+" "abcdefghijklmnopqrstuvwxyz+" $R0
${VersionConvert} "0.15c+" "abcdefghijklmnopqrstuvwxyz+" $R0
; $R0="0.15.0327"
; $R0="0.15.0327"
Line 71: Line 71:
${VersionCompare} "$R0" "$R1" $R2
${VersionCompare} "$R0" "$R1" $R2
; $R2="1"  version1 is newer
; $R2="1"  version1 is newer
SectionEnd*/
SectionEnd
 
</highlight-nsis>


;---------------------------------------------------------------------------
== Function Code ==


<highlight-nsis>
Function VersionConvert
Function VersionConvert
!define VersionConvert `!insertmacro VersionConvertCall`
!define VersionConvert `!insertmacro VersionConvertCall`
Line 190: Line 191:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
[[Category:Version Manipulation Functions]]

Latest revision as of 11:27, 30 November 2005

Author: Instructor (talk, contrib)


Page for NSIS 2.07 and below users

You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it)

Function Description

____________________________________________________________________________
 
                            VersionConvert v1.0
____________________________________________________________________________
 
Thanks Afrow UK (Based on his idea of Function "CharIndexReplace")
 
 
Convert version in the numerical format which can be compared.
 
 
Syntax:
${VersionConvert} "[Version]" "[CharList]" $var
 
"[Version]"         ; Version
                    ;
"[CharList]"        ; List of characters, which will be replaced by numbers
                    ; "abcdefghijklmnopqrstuvwxyz" (default)
                    ;
$var                ; Result: converted version
 
 
Note:
-Converted letters are separated with dot
-If character is non-digit and not in list then it will be converted to dot


Example1:

Section
	${VersionConvert} "9.0a" "" $R0
	; $R0="9.0.01"
 
	${VersionConvert} "9.0c" "" $R1
	; $R1="9.0.03"
 
	${VersionCompare} "$R0" "$R1" $R2
	; $R2="2"   version2 is newer
SectionEnd

Example2:

Section
	${VersionConvert} "0.15c-9m" "" $R0
	; $R0="0.15.03.9.13"
 
	${VersionConvert} "0.15c-1n" "" $R1
	; $R1="0.15.03.1.14"
 
	${VersionCompare} "$R0" "$R1" $R2
	; $R2="1"   version1 is newer
SectionEnd

Example3:

Section
	${VersionConvert} "0.15c+" "abcdefghijklmnopqrstuvwxyz+" $R0
	; $R0="0.15.0327"
 
	${VersionConvert} "0.15c" "abcdefghijklmnopqrstuvwxyz+" $R1
	; $R1="0.15.03"
 
	${VersionCompare} "$R0" "$R1" $R2
	; $R2="1"   version1 is newer
SectionEnd

Function Code

Function VersionConvert
	!define VersionConvert `!insertmacro VersionConvertCall`
 
	!macro VersionConvertCall _VERSION _CHARLIST _RESULT
		Push `${_VERSION}`
		Push `${_CHARLIST}`
		Call VersionConvert
		Pop ${_RESULT}
	!macroend
 
	Exch $1
	Exch
	Exch $0
	Exch
	Push $2
	Push $3
	Push $4
	Push $5
	Push $6
	Push $7
 
	StrCmp $1 '' 0 +2
	StrCpy $1 'abcdefghijklmnopqrstuvwxyz'
	StrCpy $1 $1 99
 
	StrCpy $2 0
	StrCpy $7 'dot'
	goto loop
 
	preloop:
	IntOp $2 $2 + 1
 
	loop:
	StrCpy $3 $0 1 $2
	StrCmp $3 '' endcheck
	StrCmp $3 '.' dot
	StrCmp $3 '0' digit
	IntCmp $3 '0' letter letter digit
 
	dot:
	StrCmp $7 'dot' replacespecial
	StrCpy $7 'dot'
	goto preloop
 
	digit:
	StrCmp $7 'letter' insertdot
	StrCpy $7 'digit'
	goto preloop
 
	letter:
	StrCpy $5 0
	StrCpy $4 $1 1 $5
	IntOp $5 $5 + 1
	StrCmp $4 '' replacespecial
	StrCmp $4 $3 0 -3
	IntCmp $5 9 0 0 +2
	StrCpy $5 '0$5'
 
	StrCmp $7 'letter' +2
	StrCmp $7 'dot' 0 +3
	StrCpy $6 ''
	goto +2
	StrCpy $6 '.'
 
	StrCpy $4 $0 $2
	IntOp $2 $2 + 1
	StrCpy $0 $0 '' $2
	StrCpy $0 '$4$6$5$0'
	StrLen $4 '$6$5'
	IntOp $2 $2 + $4
	IntOp $2 $2 - 1
	StrCpy $7 'letter'
	goto loop
 
	replacespecial:
	StrCmp $7 'dot' 0 +3
	StrCpy $6 ''
	goto +2
	StrCpy $6 '.'
 
	StrCpy $4 $0 $2
	IntOp $2 $2 + 1
	StrCpy $0 $0 '' $2
	StrCpy $0 '$4$6$0'
	StrLen $4 $6
	IntOp $2 $2 + $4
	IntOp $2 $2 - 1
	StrCpy $7 'dot'
	goto loop
 
	insertdot:
	StrCpy $4 $0 $2
	StrCpy $0 $0 '' $2
	StrCpy $0 '$4.$0'
	StrCpy $7 'dot'
	goto preloop
 
	endcheck:
	StrCpy $4 $0 1 -1
	StrCmp $4 '.' 0 end
	StrCpy $0 $0 -1
	goto -3
 
	end:
	Pop $7
	Pop $6
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Exch $0
FunctionEnd