NSIS Installer - Displaying different licences - nsis

I'm trying to modify an existing NSIS install script to allow for different licence files to be presented to the user depending on whether they are a new or existing user. I have pre-existing code which detects an existing install in the .onInit section.
However I'm running into bumps trying to use the NSIS provided licence screen e.g.
!InsertMacro MUI_PAGE_LICENSE Content\Licence.rtf
I would like to be able to choose between Licence and Licence2.rtf (though they'll be renamed something representative in the final version).
I've tried using selectable sections calling functions which nest the !insertmacro but that doesn't work because it needs to be in the base level of the script.
I can't change the parameter to be runtime definable because it needs to know what the file is at compile time to build it into the installer.
I know I can roll my own custom page called from a function and do it that way but I was wondering if anyone had got the NSIS installer working with using the MUI_PAGE_LICENSE and different licences.
Thanks

There are two ways to skin this cat:
Use 2 license pages and skip one of them
Load the license file manually at run-time
Two pages:
!define MUI_PAGE_CUSTOMFUNCTION_PRE skip1
!InsertMacro MUI_PAGE_LICENSE Content\Licence.rtf
!define MUI_PAGE_CUSTOMFUNCTION_PRE skip2
!InsertMacro MUI_PAGE_LICENSE Content\Licence2.rtf
#You need two functions skip1 and skip2, they should call `abort` to skip based on some state you determine at run-time
Manual load:
There is a plugin that does this for you (Not sure if it supports RTF)
I wrote some code that does this using the system plugin, you can find that on the nsis forum. To use that code, you would include your license files with normal File commands and extract the one you want to $pluginsdir and load it in the license page's show callback function.

There is an easier way. I use this code:
!insertmacro MUI_PAGE_LICENSE $(MUILicense)
Also, you have to put in your code lines like this:
LicenseLangString MUILicense ${LANG_POLISH} "SomeDirectory\licencja_pl.txt"
LicenseLangString MUILicense ${LANG_ENGLISH} "SomeDirectory\license_en.txt"
They don't have to appear before inserting license macro. In my code I defined them just below and it works fine.

Related

add a custom page before uninstall in nsis

I want to create a page and ask user for DB information like username, pwd, instance name during uninstallation and use same info for making some queries.
The only issue I am facing here is putting the custom page.IF I just declare the page like
UninstPage Custom un.dbPageEnter un.dbPageLeave
then it comes at the end but with disabled Next button(I can't click on next and run the queries now)
So, below are the steps I am able to do now
Create uninstaller
double click -> Click uninstall
Uninstallation progress bar runs
Custom page appears and i can fill DB info but next button is disabled
Questions:
Is it possible to get this custom page before I click uninstall?
Pages are displayed in the order they appear in your script.
UninstPage Custom un.dbPageEnter un.dbPageLeave
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

write in header section of custom installer page (without MUI)

I used this guide to create custom page in my installer:
nsDialogs
and its working without a problem, this is the code:
!include nsDialogs.nsh
!include LogicLib.nsh
XPStyle on
Var Dialog
Page custom nsDialogsPage nsDialogsPageLeave
Function nsDialogsPage
nsDialogs::Create 1018
Pop $Dialog
${If} $Dialog == error
Abort
${EndIf}
...
nsDialogs::Show
FunctionEnd
Function nsDialogsPageLeave
...
FunctionEnd
Section
SectionEnd
But the only thing missing is this part:
Could someone help me out and show how to add text there, but without this MUI, all the guides i tried to find are refering to the MUI way but i went with Pages instead so i would like to keep it that way, surely there is a way. Thank you in advance!
Your screenshot looks like MUI. Even when using MUI, custom pages still use Page Custom ....
The MUI has a helper macro to set the text on the top for your custom pages:
!include MUI2.nsh
...
Function nsDialogsPage
!insertmacro MUI_HEADER_TEXT "Blah" "Blah blah"
nsDialogs::...
...
FunctionEnd
This macro is documented in the MUI readme. It is not in the nsDialogs documentation because these labels are in the outer dialog, not in the inner page dialog.
In the unlikely event that you are not using MUI (but you are using the MUI dialog layout and ChangeUI) you can copy the MUI_HEADER_TEXT macro from the MUI(v1) source file or write your own custom macro based on the MUI source.

NSIS to check installation location is empty or not

How to add functionality about to display override dialog for the installation location.
If user already installed the software, and he is trying to reinstall the software in the same location then i wanted to show information whether do you need to overwrite or not?
I have used below function but it is invoking before opening the location page.
Function .onVerifyInstDirIfFileExists "$INSTDIR\temp.xls" PathGood
PathGood:
MessageBox MB_OKCANCEL "Do you want to overwrite the location with new installer ?" IDOK lbl_ok IDCANCEL lbl_cancel
lbl_ok:
lbl_cancel:
Quit
FunctionEnd
.onVerifyInstDir is used to disable the Next button, it should not display UI:
This code will be called every time the user changes the install directory, so it shouldn't do anything crazy with MessageBox or the like. If this function calls Abort, the installation path in $INSTDIR is deemed invalid.
If you want to display a message you must use the page leave callback instead:
!include LogicLib.nsh
Function MyDirLeave
${If} ${FileExists} "$INSTDIR\temp.xls"
MessageBox MB_OKCANCEL "Do you want to overwrite the location with new installer?" IDOK +2
Abort ; Stay on the current page
${EndIf}
FunctionEnd
Page Directory "" "" MyDirLeave
Page InstFiles

How can I add a header to the NSIS license page?

The top of my NSIS license page looks rather stark:
I don't see any way to modify the header/subtitle of the page through the normal channels. LicenseText looks close, but it only seems to modify the text at the bottom of the dialog.
Is there any way to add a header to the page?
You must include a language to fully initialize the MUI:
!include "MUI.nsh"
!insertmacro MUI_PAGE_LICENSE "License.rtf"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_...
!insertmacro MUI_LANGUAGE "English"
If you want to use a bitmap in the header and not the .exe icon, then you should look at the defines Seki talks about...
If you are using the Modern UI, define MUI_HEADERIMAGE_BITMAP to the path of an image (you can see in the MUI documentation.
You have an example in the script HeaderBitmap.nsi that comes with MUI2.

Calling PRE functions of MUI in NSIS installer, skipping pages/dialogs in NSIS installer

Can PRE function of a MUI dialog be called only when required?
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipComponentsPage
!insertmacro MUI_PAGE_COMPONENTS
Function SkipComponentsPage
Abort
MessageBox MB_OK "You chose to UPDATE your current version"
FunctionEnd
//This section will be checked by default, that is , user will not be able to select or unselect this section , this has to be executed..........how to do this?To hide it , i have included a - sign in its name. its name is "mandatory"
Section "-mandatory" SEC_UPDATE
#Do update............
SectionEnd
I have two RadioButtons (Demo & Update) on my custom dialog page in the NSIS installer.
I want that when the user choses to install the UPDATE (choses the UPDATE RadioButton), then the Components Page is skipped , and a specified Section is auto CHECKED and executed.
But if the user choses to install the DEM (choses the DEMO RadioButton) , then the Components page is not skipped & the user can Check or Uncheck Sections on that Component page.
A page callback is always called, but you can put logic inside the function:
...
section "" SEC_UPDATE
sectionend
Function SkipComponentsPage
!insertmacro UnSelectSection ${SEC_UPDATE} ; Don't include update with demo by default?
${If} $InstallType == UPDATE
!insertmacro SelectSection ${SEC_UPDATE}
Abort
${EndIf}
Functionend
It is not really clear to me if you want the user to be able to choose update in the demo mode, but if you want to force the update you can make the section read only:
section "Update" SEC_UPDATE
SectionIn RO
sectionend
(And remove the UnSelectSection call from the pre function)
...or just make the section invisible with the -name prefix like you suggested.

Resources