Skip to content
⌘ NSIS Forum Archive

Integrate VersionCheckNew with If..Else..Endif

2 posts

Squirre1#

Integrate VersionCheckNew with If..Else..Endif

Is there a way that you can inteagrate VersionCheckNew into LogicLib for easier logic comparison... For Example:


${If} ${VersionCheckNew} "$detectedver" "9.3.0" == 2
//do stuff here
${ElseIf} ${VersionCheckNew} "$detectedver" "9.3.3" == 1
//do stuff here
${ElseIf} ${VersionCheckNew} "$detectedver" "9.3.1" == 0
//do stuff here
${ElseIf} ${VersionCheckNew} "$detectedver" "9.3.2" == 0
//do stuff here
${ElseIf} ${VersionCheckNew} "$detectedver" "9.3.3" == 0
//do stuff here
${EndIf}
I know there are many more ways to write this, I am just asking in general...

Thanks All.

Squirre1
Animaether#
You can extend LogicLib, yes, but not the way you're writing it right now, of course 🙂

Probably the best approach would be to add comparison logic operators, a la (I'm using ${VersionCompare} out of WordFunc.nsh):
/* Version tests */
!insertmacro `_LOGICLIB_TEMP` /* required */
!macro _V= _a _b _t _f
  ${VersionCompare} ${_a} ${_b} $_LOGICLIB_TEMP
  IntCmp $_LOGICLIB_TEMP 0 `${_t}` `${_f}` `${_f}`
!macroend
!macro _V<> _a _b _t _f
  !insertmacro _V= `${_a}` `${_b}` `${_f}` `${_t}`
!macroend
!macro _V< _a _b _t _f
  ${VersionCompare} ${_a} ${_b} $_LOGICLIB_TEMP
  IntCmp $_LOGICLIB_TEMP 2 `${_t}` `${_f}` `${_f}`
!macroend
!macro _V<= _a _b _t _f
  !insertmacro _V> `${_a}` `${_b}` `${_f}` `${_t}`
!macroend
!macro _V> _a _b _t _f
  ${VersionCompare} ${_a} ${_b} $_LOGICLIB_TEMP
  IntCmp $_LOGICLIB_TEMP 1 `${_t}` `${_f}` `${_f}`
!macroend
!macro _V>= _a _b _t _f
  !insertmacro _V< `${_a}` `${_b}` `${_f}` `${_t}`
!macroend 
Usage example for experimenting:
!include "LogicLib.nsh"
!include "WordFunc.nsh"
OutFile "$%temp%\temp.exe"
Section
[version compare code goes here, perhaps in an include, or maybe you put it in LogicLib.nsh directly]
Section
  StrCpy $0 "1.0.0.0"
  StrCpy $1 "1.0.0.1"
  ${If} "$0" V= "$1"
    MessageBox MB_OK "$0 = $1"
  ${EndIf}
  ${If} "$0" V<> "$1"
    MessageBox MB_OK "$0 <> $1"
  ${EndIf}
  ${If} "$0" V< "$1"
    MessageBox MB_OK "$0 < $1"
  ${EndIf}
  ${If} "$0" V<= "$1"
    MessageBox MB_OK "$0 <= $1"
  ${EndIf}
  ${If} "$0" V> "$1"
    MessageBox MB_OK "$0 > $1"
  ${EndIf}
  ${If} "$0" V>= "$1"
    MessageBox MB_OK "$0 >= $1"
  ${EndIf}
SectionEnd