Old 4th December 2015, 10:49   #1
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
Question Redefine only if empty

Hi,

i have the following scenario: our build server calls makensis.exe with (among others) a parameter that contains Service Pack information. In case the current release is a Service Pack, the parameter has a value. In case it is not, it is empty.

The following code calls makensis.exe:
code:
makensis.exe /DINSTALLER_VERSION_STRING=%v% /DINSTALLER_BUILD_NUMBER=%b% /DINSTALLER_SERVICEPACK_STRING=%sp%


I then use this information to set the product information in the setup.exe as such:
code:
VIProductVersion "${INSTALLER_VERSION_STRING}.${INSTALLER_SERVICEPACK_STRING}.0.${INSTALLER_BUILD_NUMBER}"


My problem occurs when the build server sends an empty string as INSTALLER_SERVICEPACK_STRING. in this case, the VIProductVersion returns the following error:
code:
Error: invalid VIProductVersion format, should be X.X.X.X
.

What I would like to do is assign to INSTALLER_SERVICEPACK_STRING the value "0" in case it is empty. I tried using this:
code:
${If} ${INSTALLER_SERVICEPACK_STRING} ""
!define /redef INSTALLER_SERVICEPACK_STRING "0"
${EndIf}


This returns the following error:
code:
!insertmacro: macro "_If" requires 4 parameter(s), passed 2!


I also tried using this:
code:
StrCmp ${INSTALLER_SERVICEPACK_STRING} "" 0 +2
!define /redef INSTALLER_SERVICEPACK_STRING "0"


This doesn't return an error but the value is not changed (I still get the original error about the VIProductInfo).

Any help is appreciated!

Mircea
Mircea M is offline   Reply With Quote
Old 4th December 2015, 11:00   #2
Mircea M
Junior Member
 
Join Date: Aug 2014
Posts: 44
And i found my answer thanks to "search" and eccles:

code:
!define EmptySP${INSTALLER_SERVICEPACK_STRING}

!ifdef EmptySP
!define /redef INSTALLER_SERVICEPACK_STRING "0"
!endif

Mircea M is offline   Reply With Quote
Old 4th December 2015, 11:53   #3
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 869
Ah, another case of mixing compile time code with runtime code. You can't use runtime code to change compile time code, it all has to be done with compile time code. ${If} and StrCmp are runtime functions.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 4th December 2015, 12:35   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
!if `${INSTALLER_SERVICEPACK_STRING}` == ``
...

Stu
Afrow UK is offline   Reply With Quote
Old 9th December 2015, 21:40   #5
DarthAndroid
Junior Member
 
Join Date: Dec 2015
Posts: 1
The proper way to do this is with:

!define /ifndef INSTALLER_SERVICEPACK_STRING "0"

This will set the define to "0" if it is not set by your build server. If the build server sets the define when it calls makensis, then the line will be ignored (/ifndef) and whatever the build server specified will prevail.
DarthAndroid is offline   Reply With Quote
Old 9th December 2015, 22:15   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
Quote:
Originally Posted by DarthAndroid View Post
The proper way to do this is with:

!define /ifndef INSTALLER_SERVICEPACK_STRING "0"

This will set the define to "0" if it is not set by your build server. If the build server sets the define when it calls makensis, then the line will be ignored (/ifndef) and whatever the build server specified will prevail.
The OP has a empty define, not a non-existing define.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 9th December 2015, 22:17   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,928
NSIS treats "" as 0 in math operations so you can add 0 to the input:

Quote:
!define /redef /math INSTALLER_SERVICEPACK_STRING "${INSTALLER_SERVICEPACK_STRING}" + 0

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