Prakash
Prakash

Reputation: 533

Display of product versions?

My product has version w.x.y.z. My upgrade of that product has w.x.y.z+1. But the requirement is that before upgrade the fourth field of the version i.e; z should not be checked...i.e; myproduct should not take into consideration the z field.....Please do reply me with an answer.

Upvotes: 1

Views: 933

Answers (2)

RobeN
RobeN

Reputation: 5456

In this case this can be a solution (based on http://nsis.sourceforge.net/Sort_String_2). I have created Test Registry Key just for check with your {3.1.123 4.0.112 4.1.119}. Please replace with the one your application uses.

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

Upvotes: 1

RobeN
RobeN

Reputation: 5456

You can read you App Version from registry and keep it as Variable, then trim it to specific number of chars. Check http://nsis.sourceforge.net/TrimText:_Trim_text_e.g._to_fit_in_a_label

Script below is will work for ANSI NSIS if you have such version installed if not, please change ReadRegStr accordingly.

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

Upvotes: 1

Related Questions