- NSIS Discussion
- any way too do a '!if ${FOO} == 1'?
Archive: any way too do a '!if ${FOO} == 1'?
PhracturedBlue
15th February 2003 23:17 UTC
any way too do a '!if ${FOO} == 1'?
I am using NSIS to write an installer for the upcoming release of The Ur-Quan Masters
http://sc2.sf.net
And I'm pretty much done. However, I'd like the installer to be very easy to configure, and as such would really like to be able to do something like:
!define FOO 1 ;Set FOO to 2, 1, or 0 depending on option
!if ${FOO} == 2
!define BAR "SOME_REALLY_CONVOLUTED_STRING"
!elseif ${FOO} == 1
!define BAR "SOME_OTHER_REALLY_CONVOLUTED_STRING"
!else
!define BAR "SOME_THIRD_REALLY_CONVOLUTED_STRING"
!endif
I realize that for 2 options, I could do:
!define FOO 1 ;Comment this line if you don't want FOO
!ifdef ${FOO}
!define BAR "SOME_REALLY_CONVOLUTED_STRING"
!else
!define BAR "SOME_OTHER_REALLY_CONVOLUTED_STRING"
!define FOO 0
!endif
(Note that I need to define FOO, since I use it later in the installer)
Which works (and is how I'm doinng it now), but is somewhat confusing for the users, and doesn't allow for more than 2 options
Is there any more elegant way to do what I need?
(We are usiing 2.0b1)
(BTW: Thank you for NSIS! It is a wonderful project)
PhracturedBlue
15th February 2003 23:20 UTC
I should also mention that I've tried using IntCmp in a .onInit, but that requires thatI set the variable as $0-$9 (or $R0-$R9), or push it onto the stack, neither of which is really a viable option, since I have lots of variabbles I need to do this for.
Joel
15th February 2003 23:45 UTC
well, your using the same "BAR" to define diferent strings...
.... try use the other "cmp" like StrCmp... for example:
Function GetWinVer
Push $R0
Push $R1
ReadRegStr $R0 HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
StrCmp $R0 '4.00.950' Win95 NotWin95/NT3
StrCmp $R1 '3.51.1057' WinNT3 NotWin95/NT3
Win95:
SectionSetFlags ${descSQ} 16
WinNT3:
SectionSetFlags ${descSQ} 16
NotWin95/NT3:
FunctionEnd
Function GetIEVer
Push $R0
Push $R1
Push $1
GetDllVersion "$SYSDIR\mshtml.dll" $R0 $R1
IntOp $1 $R0 / 0x00010000 ;Necesitas el primer dígito/We only need the first digit
IntCmp $1 ${IEver} SameVer BadVer GoodVer ;Debe ser 5 o superior la versión
BadVer:
MessageBox MB_YESNO|MB_ICONSTOP "No version support" IDYES GoodVer
Abort
SameVer:
GoodVer:
FunctionEnd
Hope this help you! :D
virtlink
16th February 2003 10:28 UTC
I think that many people would like it to see !elseif added to NSIS. And it would take NSIS again one step closer to a 'real' scriptiong or programming language.
PhracturedBlue
16th February 2003 12:13 UTC
Using StrCmp doesn't buy me anything over an IntCmp in this case, and isn't very conveneient since this check is done in several places (this indicates that I'd need to do the compare in a function call, which I thought about, but it seems kinda silly to do a compare in the installer, when the actual string can be defined at compile-time instead).
Anyhow, I have a workable solution for now, and I really do appreciate all the nifty features in NSIS.
Thanks!
Joost Verburg
16th February 2003 13:43 UTC
Originally posted by virtlink
I think that many people would like it to see !elseif added to NSIS. And it would take NSIS again one step closer to a 'real' scriptiong or programming language.
Use "!else ifdef"
PhracturedBlue
16th February 2003 21:18 UTC
Originally posted by Joost Verburg
Use "!else ifdef"
That isn't quite the same as
!if
!elif
!endif
Which is what I'd like to see (and I imagine what virtlink was talking about)
kichik
16th February 2003 21:28 UTC
!if something = somethingelse is not supported. You'll have to do with !ifdef, !else ifdef, and !endif for now. Instead of giving a value for your define make use of two different define names.
eccles
17th February 2003 23:56 UTC
This just occured to me but I've not tried it...
!define FOO 1 ;Set FOO to 2, 1, or 0 depending on option
...
!define FOO${FOO}
!ifdef ${FOO2}
!define BAR "SOME_REALLY_CONVOLUTED_STRING"
!else ifdef ${FOO1}
!define BAR "SOME_OTHER_REALLY_CONVOLUTED_STRING"
!else
!define BAR "SOME_THIRD_REALLY_CONVOLUTED_STRING"
!endif
hth!
Dave.
PhracturedBlue
18th February 2003 03:44 UTC
Very cool! i just tried this, and it works great. (of course you shouldn't have the '${' and '}' on the !ifdef lines (I screwed up the original proto code too)), so it looks more like:
!define FOO 1 ;Set FOO to 2, 1, or 0 depending on option
...
!define FOO${FOO}
!ifdef FOO2
!define BAR "SOME_REALLY_CONVOLUTED_STRING"
!else ifdef FOO1
!define BAR "SOME_OTHER_REALLY_CONVOLUTED_STRING"
!else
!define BAR "SOME_THIRD_REALLY_CONVOLUTED_STRING"
!endif
But it does exactly what I need!
Thanks!
eccles
18th February 2003 08:18 UTC
Ar yes you're right. Like I said, I hadn't tried it :)
Glad I could help.
kichik
18th February 2003 15:54 UTC
Good idea eccles! :D
Joel
18th February 2003 21:17 UTC
works for me too :p