add a custom page before uninstall in nsis - 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

Related

Simulate next click on INSTFILES page to take user to a Custom Page (NSIS)

This is my use case:
I'm creating an uninstaller using NSIS.
I'm in the "MUI_UNPAGE_INSTFILES" page during the uninstallation flow.
Files got removed in the "Section Uninstall" code.
Now I need the user to be taken to a custom page, by simulating the next button click in "MUI_UNPAGE_INSTFILES".
I did check for "MUI_UNFINISHPAGE_NOAUTOCLOSE", but I don't have it defined in my code. Still it is not automatically moving to the next page.
This is the code where the pages are defined for the uninstaller:
UninstPage custom un.UninstConfirm_Show ;1st page (custom page)
!insertmacro MUI_UNPAGE_INSTFILES ;2nd page
UninstPage custom un.UninstFinish_Show ;3rd & final page (custom page)
I need to move from 2nd page to 3rd page without user clicking on the next button in the 2nd page.
Any ideas ?
Use the following code to simulate clicking the Next button:
GetDlgItem $0 $HWNDPARENT 1
SendMessage $HWNDPARENT ${WM_COMMAND} 1 $0
FYI: http://forums.winamp.com/showthread.php?t=187143
MUI calls SetAutoClose true in un.onGUIInit when the MUI finish page is used but you can just call SetAutoClose true in a uninstaller section to achieve the same effect.

Unable to hide back button in NSIS Uninstaller

I have an uninstaller created in NSIS.
It has 3 pages (1 custom page (Confirm), the macro MUI_UNPAGE_INSTFILES and another custom page (Finish)).
My problem is that I'm unable to hide the 'Back' button in the "INSTFILES" page.
I have tried various things to hide it, but it simply stays there in disabled state.
This is the code that I'm using to hide the Back button:
GetDlgItem $1 $HWNDPARENT 3
ShowWindow $1 ${SW_HIDE}
Above code works fine for Next and Cancel button when used with ID 1 and 2.
I have tried the above code in various places
un.OnInit
myGuiInit (custom)
Page LEAVE callback of confirm page
Page PRE callback of INSTFILES page
Page SHOW callback of INSTFILES page
Code:
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.InstShow
UninstPage custom un.UninstConfirm_Show
!define MUI_PAGE_CUSTOMFUNCTION_PRE un.InstShow
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.InstShow
!insertmacro MUI_UNPAGE_INSTFILES
UninstPage custom un.UninstFinish_Show
un.InstShow has the logic to hide the button.
Any help would be appreciated. I have spent close to 4-5 hours on this with no luck.
This is how the screen looks now (Note that I have hidden Next and Cancel buttons in the image, to illustrate that hiding those buttons are working fine for me) :
The internal page flag PF_BACK_SHOW in NSIS is set for all pages except the first page, you have to hack your way around it.
If the InstFiles page is the last page or if you don't want the back button on the pages after then you can move the button:
Section -un.Main
GetDlgItem $1 $hwndParent 3
System::Call USER32::MoveWindow(pr1,i-9,i-9,i1,i1,i1)
SectionEnd
If you only want to hide it on the InstFiles page but not on the pages after then you must use a timer and call ShowWindow in the timer callback.
GetDlgItem $1 $HWNDPARENT 3
ShowWindow $1 ${SW_HIDE}
This code is perfectly correct and working fine (tested).
I think there is some other code which shows the button again.
E.g. in scenario when you hide the button in LEAVE function of page X, the following page may show the button again. This happens often in regular UI.
The solution is to check all your custom pages and also the standard pages for any operations regarding this button.

How to set the form title

The form displays with "Name Setup" as the form caption. I understand how to set the titles of the individual installer pages (Welcome, Finish etc), but how do you set the form caption of the installer interface?
Usually setting Name is enough for the title and all pages.
To customize the default title use Caption or to customize the subtitle on a per page basis use SubCaption, or Caption inside a PageEx block (If you are using the Modern UI, it has defines for most of these)
For pages based on nsDialogs use macro MUI_HEADER_TEXT
Example:
Function nsDialogsPage
!insertmacro MUI_HEADER_TEXT "${LICENSE_TITLE}" "${LICENSE_SUBTITLE}"
nsDialogs::Create /NOUNLOAD 1018
...
nsDialogs::Show
FunctionEnd

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.

NSIS Installer - Displaying different licences

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.

Resources