Using NSIS command line to globally define product definitions - command-line-arguments

I'd like to control the branding for my NSIS installer by passing a parameter to makensis:
makensis.exe /DCOMPANY_X=1 installer.nsi
The following are the first few lines listed in my NSI file:
!ifdef ${COMPANY_X}
!define PRODUCT_NAME "Widget Pro"
!define PRODUCT_VERSION "v2.0"
!define PRODUCT_PUBLISHER "ACE Company"
!define PRODUCT_WEB_SITE "www.ace.com"
!define PRODUCT_COPYRIGHT "Copyright 2013 Ace"
!else
!define PRODUCT_NAME "Widget Maker"
!define PRODUCT_VERSION "v12.3"
!define PRODUCT_PUBLISHER "ACME CO"
!define PRODUCT_WEB_SITE "www.acme.com"
!define PRODUCT_COPYRIGHT "Copyright 2013 ACME"
!endif
I use these defines throughout my script.
The problem I'm encountering is that even with COMPANY_X defined on the command line, execution is passing through to the second block of defines (ACME).
Being new to NSIS, I'm sure there's a better way to handle this. I'd also like to use a switch statement to define multiple companies. If I do this, the compiler warns me that I need to place this code in a section or function.
One thing that might complicate a solution for this is that I'm signing my uinstaller with a two pass process:
http://nsis.sourceforge.net/Signing_an_Uninstaller
Kudos to the NSIS team and all the contributors. No way I'd ever go back to InstallShield.
Thanks in advance for any help.

!ifdef ${COMPANY_X} is actually going to check if 1 is defined!
The syntax is !ifdef name_of_define: !ifdef COMPANY_X
...or if the content of the define matters: !if ${COMPANY_X} = 1

Related

How to change default NSIS logo and also add an shortcut to desktop?

I tried changing my logo but the following error occurs:!define: "MUI_INSERT_NSISCONF" already defined!
I'm very new to NSIS.Sorry if this is a silly question for you.
To create a shortcut on a Desktop for the current user:
CreateShortCut "$DESKTOP\Filename.lnk" "$INSTDIR\SomeFile.exe" "<Optional Command Line>"
To change the icon and logo:
!include "MUI2.nsh"
!define MUI_ICON "MyApp.ico"
!define MUI_UNICON "MyApp.ico"
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "InstallerLogo.bmp"

Getting folder name in NSIS at compile time

I would like to dynamically name my EXE files based on the folder in which they're being built. So, in other words, if my NSIS script is located in C:\[blah]\MyProjectDir\Nullsoft\ and my project is located in C:\[blah]\MyProjectDir\MyProject\ the output NSIS executable should be MyProjectDir.exe. I'm obviously obfuscating the names for simplicity, the structure of the folders has actual meaning to our team.
Basically the our (already written, ages ago) NSIS scripts look something like this:
!define APP_NAME "OurGUI"
!define PROJ_NAME "OurGUI"
!define PATH_TO_FILES ..\${PROJ_NAME}\bin\Debug
!define EXEC_NAME "OurGUI.exe"
OutFile "GUI_Setup.exe"
There's a whole bunch more that handle things like registry keys, installation, etc... this is the important part as it pertains to my question (because I don't want to modify the rest of the script).
I'd like to change it to something like this
!define M_NUMBER !system "for %I in (..) do echo %~nxI"
!define APP_NAME "${M_NUMBER}/ Demo GUI"
!define PROJ_NAME "OurGUI"
!define PATH_TO_FILES ..\${PROJ_NAME}\bin\Debug
!define EXEC_NAME "M_Number.exe"
OutFile "${M_NUMBER}_GUI_Setup.exe"
I know my syntax is totally off, but that's the idea.
Running the command for %I in (..) do echo %~nxI returns to me the name of the grandparent directory, which is exactly what I want. Now I need to figure out how to store it in some sort of variable so that it can be used in the !define's. I need to somehow capture the output to the console (not the return value of for, which is always zero, within my NSIS script. Ideally I wouldn't have to use external plugins because that'll be a nightmare to manage across the team.
As a nice bonus, I'd also love to be able to manipulate the string (again, at compile time so it can be used in the !define's.
The strings follow the format: SWD1234-567, but I would like to store it as D1234567 in another variable for other renaming purposes. So, drop the "SW" and the "-" from the original string.
I'm open to other suggestions, but as a newbie to NSIS, this is what I've come up with.
You need to use the !system+!include idiom to read the output of external commands:
!tempfile MYINCFILE
!system 'for %I in (..) do echo !define MYDIR "%~nxI" > "${MYINCFILE}"'
!include "${MYINCFILE}"
!delfile "${MYINCFILE}"
!echo "${MYDIR}"
The pre-processor has limited string handling but removing known sub-strings is possible:
!define MYDIR "SWD1234-567"
!searchreplace MYDIR2 "${MYDIR}" "SW" ""
!searchreplace MYDIR2 "${MYDIR2}" "-" ""
!echo "${MYDIR2}" ; D1234567

NSIS MUI_PAGE_HEADER_TEXT not showing

NSIS newbie here. Using nsis v2.51 with MUI2 (Modern UI 2)
As stated, my problem is that even though I set the MUI_PAGE_HEADER_TEXT define, the resulting installer does not show any text at all where it should be. The same happens for MUI_PAGE_HEADER_SUBTEXT. However, page specific text defines show correctly.
This is the minimal NSIS script that demonstrates the issue:
Name "Just for show"
OutFile "MuiText.exe"
!include "MUI2.nsh"
!define MUI_PAGE_HEADER_TEXT "AAAAAAA"
!define MUI_PAGE_HEADER_SUBTEXT "CHANGE MEEEEEEE! CHANGE MEEEEEEE!!!!"
!define MUI_DIRECTORYPAGE_TEXT_TOP "Please select the directory where you want this fine program installed."
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Enter Directory"
!insertmacro MUI_PAGE_DIRECTORY
Section
SectionEnd
And this is the screenshot of the resulting installer:
Any ideas on how can I make the text show up? Thank you.
You must specify at least one language with MUI_LANGUAGE otherwise the UI does not work correctly:
!include "MUI2.nsh"
!define MUI_PAGE_HEADER_TEXT "AAAAAAA"
!define MUI_PAGE_HEADER_SUBTEXT "CHANGE MEEEEEEE! CHANGE MEEEEEEE!!!!"
!define MUI_DIRECTORYPAGE_TEXT_TOP "Please select the directory where you want this fine program installed."
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Enter Directory"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"

Change the text of install folder page in NSIS

I need to change the text on the "Choose Install Location" page of an NSIS installer to say that my program can not be installed in a directory containing spaces in the name.
What is the best way to change this text?
!include MUI2.nsh
!define MUI_PAGE_HEADER_TEXT Foo
!define MUI_PAGE_HEADER_SUBTEXT Bar
!define MUI_DIRECTORYPAGE_TEXT_TOP Baz
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION Bob
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
You might also want to check the path when the user is about to leave the page (In the page leave callback)...

How can I modify the text in the MUI_WELCOME_PAGE when using MUI2 for NSIS?

I want to add a label displaying the full version-string in the welcome screen in the installer I am creating using NSIS with MUI2.
I have searched for info on how to do this, but only found references to using MUI_INSTALLOPTIONS* which I found ws deprecated for MUI2. Another one referred to the newer versions using INSTALLOPTIONS* with the same options, but I could not get it working. I finally also found a reference to using nsDialogs for this - which is what I am using for my custom pages. However - I found no reference or samples on how to change any of the existing pages that comes with MUI2.nsh.
I found a way to change the MUI_HEADERTEXT, but that doesn't affect the welcome-screen. I wish there was a way to also change the welcometext. Maybe using MUI_WELCOMETITLE and MUI_WELCOMEBODY or similar.
There is MUI_WELCOMEPAGE_TEXT but it is only useful if you want to change all of the text and not just append something.
During the show function for the page, you can change the text of any control:
outfile test.exe
requestexecutionlevel user
!include MUI2.nsh
#!define MUI_WELCOMEPAGE_TEXT "New text goes here"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyWelcomeShowCallback
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function MyWelcomeShowCallback
SendMessage $mui.WelcomePage.Text ${WM_SETTEXT} 0 "STR:$(MUI_TEXT_WELCOME_INFO_TEXT)$\n$\nVersion: foo.bar"
FunctionEnd
Section
SectionEnd
..or add a new control:
outfile test.exe
requestexecutionlevel user
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyWelcomeShowCallback
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function MyWelcomeShowCallback
${NSD_CreateLabel} 120u 150u 50% 12u "Version: foo.bar"
Pop $0
SetCtlColors $0 "" "${MUI_BGCOLOR}"
FunctionEnd
Section
SectionEnd
I also had the issue with NSIS. In my case it worked to define MUI_WELCOMEPAGE_TITLE before inserting the macro MUI_PAGE_WELCOME.
It should look like:
!define MUI_WELCOMEPAGE_TITLE "CUSTOM TITLE HERE"
!insertmacro MUI_PAGE_WELCOME

Resources