Old 6th January 2008, 15:31   #1
dllmain
Senior Member
 
dllmain's Avatar
 
Join Date: Sep 2005
Location: Berlin, Germany
Posts: 207
Can I make a script require a minimum NSIS version?

Hello!


I'd like to make sure that a certain script throws an error if compiled with a version prior to X like I can do in Autoconf:

code:
AC_PREREQ(2.60)


Is there a way to achieve this with NSIS? I didn't find anything about this.

Thanks in advance,



Sebastian
dllmain is offline   Reply With Quote
Old 6th January 2008, 15:48   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
!if `${NSIS_VERSION}` < 2.34
!error `NSIS version 2.34 or greater required.`
!endif

Stu
Afrow UK is offline   Reply With Quote
Old 6th January 2008, 16:11   #3
dllmain
Senior Member
 
dllmain's Avatar
 
Join Date: Sep 2005
Location: Berlin, Germany
Posts: 207
Thanks for the hint about ${NSIS_VERSION} but your code doesn't work, for two reasons:
  • ${NSIS_VERSION} starts with "v" as in "v2.34"
  • < seems to only compare numbers, not strings.
Still a good start, I think I can make something of that.
dllmain is offline   Reply With Quote
Old 6th January 2008, 16:12   #4
fabian.rap.more
Senior Member
 
Join Date: Dec 2007
Posts: 111
Send a message via Yahoo to fabian.rap.more
the code should still work

!if `${NSIS_VERSION}` < v2.34
!error `NSIS version 2.34 or greater required.`
!endif
fabian.rap.more is offline   Reply With Quote
Old 6th January 2008, 16:31   #5
dllmain
Senior Member
 
dllmain's Avatar
 
Join Date: Sep 2005
Location: Berlin, Germany
Posts: 207
If I try that exact code with the string 2.35 it doesn't fail for my local NSIS 2.34. So it seems it's always false.
dllmain is offline   Reply With Quote
Old 6th January 2008, 16:54   #6
fabian.rap.more
Senior Member
 
Join Date: Dec 2007
Posts: 111
Send a message via Yahoo to fabian.rap.more
did you try enclosing v2.35 within quotes?
fabian.rap.more is offline   Reply With Quote
Old 6th January 2008, 17:23   #7
dllmain
Senior Member
 
dllmain's Avatar
 
Join Date: Sep 2005
Location: Berlin, Germany
Posts: 207
yes, no luck.
dllmain is offline   Reply With Quote
Old 6th January 2008, 17:35   #8
fabian.rap.more
Senior Member
 
Join Date: Dec 2007
Posts: 111
Send a message via Yahoo to fabian.rap.more
try this

!define NO "v2.35"

!if `${NSIS_VERSION}` < '${NO}'
!error `NSIS version 2.34 or greater required.`
!endif

What some invent the rest enlarge
fabian.rap.more is offline   Reply With Quote
Old 6th January 2008, 17:37   #9
dllmain
Senior Member
 
dllmain's Avatar
 
Join Date: Sep 2005
Location: Berlin, Germany
Posts: 207
I did some research in between. I found out the following:
  • The ${NSIS_VERSION} constant was first introduced in 2.0b4
  • 2.15 is the only release in [2.0b4, 2.34] without the "v" prefix in ${NSIS_VERSION}
With that and an idea from here I was able to construct this code for detecting NSIS >=2.34:

Quote:
!ifndef NSIS_VERSION
; Anything before 2.0b4
!error "NSIS 2.34 or later required."
!endif
!define "X${NSIS_VERSION}"
!ifdef Xv2.33 | Xv2.32 | Xv2.31 | Xv2.30 | Xv2.29 | Xv2.28 | Xv2.27 | Xv2.26 | Xv2.25 | Xv2.24 | Xv2.23 | Xv2.22 | Xv2.21 | Xv2.20 | Xv2.19 | Xv2.18 | Xv2.17 | Xv2.16 | X2.15 | Xv2.14 | Xv2.13 | Xv2.12 | Xv2.11 | Xv2.10 | Xv2.09 | Xv2.08 | Xv2.07 | Xv2.06 | Xv2.05 | Xv2.04 | Xv2.03 | Xv2.02 | Xv2.01 | Xv2.0
; Stable releases, 2.15 without "v" prefix
!error "NSIS 2.34 or later required."
!endif
!ifdef Xv2.0b4 | Xv2.0rc1 | Xv2.0rc2 | Xv2.0rc3 | Xv2.0rc4 | Xv2.07b0
; Pre-releases
!error "NSIS 2.34 or later required."
!endif
!undef "X${NSIS_VERSION}"
Please report any bugs you find.
dllmain is offline   Reply With Quote
Old 6th January 2008, 17:43   #10
dllmain
Senior Member
 
dllmain's Avatar
 
Join Date: Sep 2005
Location: Berlin, Germany
Posts: 207
Quote:
Originally posted by fabian.rap.more
try this

!define NO "v2.35"

!if `${NSIS_VERSION}` < '${NO}'
!error `NSIS version 2.34 or greater required.`
!endif
Just saw this. I tried that and with other quote chars as well - still doesn't work for me. It makes me wonder if you actually try the code you paste here.
dllmain is offline   Reply With Quote
Old 6th January 2008, 17:46   #11
zeeh3
Senior Member
 
Join Date: Aug 2005
Posts: 121
I think none of these commands allow use of variables.
zeeh3 is offline   Reply With Quote
Old 6th January 2008, 17:47   #12
fabian.rap.more
Senior Member
 
Join Date: Dec 2007
Posts: 111
Send a message via Yahoo to fabian.rap.more
i always try my scripts before posting them...............

What some invent the rest enlarge
fabian.rap.more is offline   Reply With Quote
Old 6th January 2008, 18:31   #13
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You're right, that doesn't work.
This does though. Used a bit of a hack to strip the v from the front using /date:
code:

!define VERSION_A 2.34
!define /date VERSION_B %${NSIS_VERSION}
!if `${VERSION_B}` < `${VERSION_A}`
!error `NSIS version ${VERSION_A} or greater required. You are using ${NSIS_VERSION}.`
!endif



Stu
Afrow UK is offline   Reply With Quote
Old 6th January 2008, 19:47   #14
dllmain
Senior Member
 
dllmain's Avatar
 
Join Date: Sep 2005
Location: Berlin, Germany
Posts: 207
The only problem I can think of is that it accepts Xrc1 if X is required. Other than that very smart solution.

I made a macro/file of that, see attachment. Usage is

Quote:
!include "RequireVersion.nsh"
!insertmacro REQUIRE_VERSION "2.34"
Attached Files
File Type: nsh requireversion.nsh (358 Bytes, 282 views)
dllmain is offline   Reply With Quote
Old 6th January 2008, 20:11   #15
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
That's good. Should make a Wiki page.

Stu
Afrow UK is offline   Reply With Quote
Old 12th November 2014, 18:35   #16
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,275
The !define /date trick is broken in 3.0, I don't exactly know why but %v is a undocumented format specifier. New code should only use the /date trick to strip the "v" prefix when NSIS_PACKEDVERSION is not defined...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump