Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   VersionCompare fails (http://forums.winamp.com/showthread.php?t=320729)

dbach 12th July 2010 13:27

VersionCompare fails
 
Hi Community.

I wrote a macro named GetMostRecentFile. It compares two files and delivers the winner back.

Example call of Macro:
PHP Code:

${GetMostRecentFile"$PLUGINSDIR\${DLL}" "${_platformpath}\${_applicationpath}\${DLL}" $


The "GetVersion" Macro:
PHP Code:

; --- Requirements
!ifndef LOGICLIB
    
!include "LogicLib.nsh"
!endif

; -- 
GetVersion
!define MACRO_GETVERSION_INCLUDED
!define GetVersion "!insertmacro GetVersion"
!macro GetVersion _GetVersionFile _GetVersionVar
    ClearErrors
    
    StrCpy $R0 
""
    
StrCpy $R1 ""
    
StrCpy $R2 ""
    
StrCpy $R3 ""
    
StrCpy $R4 ""
    
StrCpy $R5 ""
    
    
GetDLLVersion "${_GetVersionFile}$R0 $R1
    
${If} ${Errors}
        
DetailPrint "Could not get version info from '${_GetVersionFile}'"
    
${EndIf}
        
    
IntOp $R2 $R0 0x00010000 $R2 now contains major version
    IntOp $R3 $R0 
0x0000FFFF $R3 now contains minor version
    IntOp $R4 $R1 
0x00010000 $R4 now contains release
    IntOp $R5 $R1 
0x0000FFFF $R5 now contains build
    
    StrCpy 
${_GetVersionVar"$R2.$R3.$R4.$R5"
!macroend 


The GetMostRecentFile macro:
PHP Code:

; --- Requirements
!ifndef LOGICLIB
    
!include "LogicLib.nsh"
!endif

!
ifndef WORDFUNC_INCLUDED
    
!include "WordFunc.nsh"
!endif

!
ifndef MACRO_GETVERSION_INCLUDED
    
!include "macro.getversion.nsh"
!endif

!
insertmacro VersionCompare
Var _VersionCompareFile1
Var _VersionCompareFile2
Var _VersionCompareResult


; --- GetMostRecentFile
!define GetMostRecentFile '!insertmacro GetMostRecentFile'
!define MACRO_GETMOSTRECENTFILE_INCLUDED

!macro GetMostRecentFile _file1 _file2 _var
ClearErrors
${If}      ${FileExists"${_file1}"
${AndIf} ${FileExists"${_file2}"
    
    
LogText "${_file1}: Getting version"
    
${GetVersion"${_file1}$_VersionCompareFile1
    LogText 
"${_file1}: Version - $_VersionCompareFile1"
    
    
${IfNot} ${Errors}
        
        
LogText "${_file2}: Getting version"
        
${GetVersion"${_file2}$_VersionCompareFile2
        LogText 
"${_file2}: Version - $_VersionCompareFile2"
        
        
${IfNot} ${Errors}
            
            
LogText "Comparing: '${_file1}' vs. '${_file2}'"
            
${VersionCompare"${_file1}" "${_file2}$_VersionCompareResult
            LogText 
"Result: $_VersionCompareResult"
            
            
${If} $_VersionCompareResult == "0" equal
                LogText 
"Result mean: Equal"
                
StrCpy ${_var"${_file1}copy back the first value
                
            
${ElseIf} $_VersionCompareResult == "1" file 1 newer
                LogText 
"Result mean: ${_file1} is newer"
                
StrCpy ${_var"${_file1}copy back the first value
                
            
${ElseIf} $_VersionCompareResult == "2" file 2 newer
                LogText 
"Result mean: ${_file2} is newer"
                
StrCpy ${_var"${_file2}copy back the second value
                
            
${EndIf}

        ${Else}
            
DetailPrint "GetMostRecentFile failed on '${_file2}'. Returning ${_file1} as result."
            
StrCpy ${_var"${_file2}
            
        
${EndIf}
            
    ${Else}
        
DetailPrint "GetMostRecentFile failed on '${_file1}'. Returning ${_file1} as result."
        
StrCpy ${_var"${_file1}

    
${EndIf}
    

${Else}
    ${
IfNot} ${FileExists"${_file1}"
        
DetailPrint "GetMostRecentFile Error: '${_file1}' does not exists."
        
StrCpy ${_var"${_file2}
        
    
${EndIf}
    
    ${
IfNot} ${FileExists"${_file2}"
        
DetailPrint "GetMostRecentFile Error: '${_file2}' does not exists."
        
StrCpy ${_var"${_file1}
        
    
${EndIf}
${EndIf}
!
macroend 

And the (frustrating) result:
PHP Code:

IfFileExistsfile "C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll" existsjumping 0
IfFileExists
file "C:\Program Files\product\NAMEOF.dll" existsjumping 0
C
:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dllGetting version
C
:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dllVersion 4.2.0.33
C
:\Program Files\product\NAMEOF.dllGetting version
C
:\Program Files\product\NAMEOF.dllVersion 4.4.0.22
Comparing
'C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll' vs'C:\Program Files\product\NAMEOF.dll'
Call859
Jump
915
Jump
926
Result
1
Result mean
C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll is newer
Jump
939
Jump
942
Jump
945
Jump
952
Most recent version 
'C:\DOCUME~1\VIRTUA~1\LOCALS~1\Temp\nssF.tmp\NAMEOF.dll' is copied to 'C:\Program Files\product\' 

The older version is detected as newer version? Am I doing something wrong which I don't see here? :|

thnx

dbach 12th July 2010 14:35

Changed: ${VersionCompare} "${_file1}" "${_file2}" $_VersionCompareResult
To: ${VersionCompare} "$_VersionCompareFile1" "$_VersionCompareFile2" $_VersionCompareResult

Now its working. ;)


All times are GMT. The time now is 17:25.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.