NSIS uninstall page custom function already defined - nsis

When I use script like this it's ok:
...
!define MUI_PAGE_CUSTOMFUNCTION_PRE onlymodeA
!insertmacro MUI_UNPAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!define MUI_PAGE_CUSTOMFUNCTION_PRE onlymodeA
!insertmacro MUI_UNPAGE_INSTFILES
...
But when I use this one script I've got error - !define: "MUI_UNPAGE_CUSTOMFUNCTION_PRE" already defined!
...
!define MUI_UNPAGE_CUSTOMFUNCTION_PRE un.onlymodeA
!insertmacro MUI_UNPAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!define MUI_UNPAGE_CUSTOMFUNCTION_PRE un.onlymodeA
!insertmacro MUI_UNPAGE_INSTFILES
...
What's the difference?

The MUI_PAGE_CUSTOMFUNCTION_* defines are per-page and the !insertmacro call that creates the page will undefine MUI_PAGE_CUSTOMFUNCTION_* after using their contents. MUI_UNPAGE_CUSTOMFUNCTION_PRE is not a MUI define and will remain after the macro and when you try to define it again you get a normal compiler error...

Related

default unwelcome page with electron builder nsis can't be changed or removed

Electron-Builder Version:
22.14.5
Node Version:
16.15.1
Electron Version:
18.3.0
Electron Type (current, beta, nightly):
current
Target:
win nsis ia32
based on this PR #1173
Hi, based on this feature, it seems there is an issue to interact with the unwelcome page.
by default when we use electron builder with nsis, we have now during the uninstallation , the unwelcome page and the unfinish page like you described bellow. And it's cool
but we didn't interact with them like this
!define MUI_PAGE_CUSTOMFUNCTION_PRE un.custom_pre_page
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.custom_leave_page
!define MUI_WELCOMEPAGE_TITLE_3LINES
!define MUI_WELCOMEPAGE_TITLE 'unwelcome_title'
!define MUI_WELCOMEPAGE_TEXT 'unwelcome_text'
!insertmacro MUI_UNPAGE_WELCOME
so when we have are in a language where the default text is too long we don't have the 3 lines.
and we can't change the text. see the screenshot.
I've test many ways to solve it, manage anothe unpage welcome and it works for the othe page but the default page that you added is never removed.
I tried to manipulate the window item to hide it, try to click on the next button with a command to navigate
but it doesn't work. And I verified that handles are correct.
so what it the solution in this context to interact with your unwelcome page or to remove it?
thanks in advance
Electron-Builder Version:
22.14.5
Node Version:
16.15.1
Electron Version:
18.3.0
Electron Type (current, beta, nightly):
current
Target:
win nsis ia32
based on this PR #1173
Hi, based on this feature, it seems there is an issue to interact with the unwelcome page.
by default when we use electron builder with nsis, we have now during the uninstallation , the unwelcome page and the unfinish page like you described bellow. And it's cool
but we didn't interact with them like this
!define MUI_PAGE_CUSTOMFUNCTION_PRE un.custom_pre_page
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.custom_leave_page
!define MUI_WELCOMEPAGE_TITLE_3LINES
!define MUI_WELCOMEPAGE_TITLE 'unwelcome_title'
!define MUI_WELCOMEPAGE_TEXT 'unwelcome_text'
!insertmacro MUI_UNPAGE_WELCOME
so when we have are in a language where the default text is too long we don't have the 3 lines.
and we can't change the text. see the screenshot.
I've test many ways to solve it, manage anothe unpage welcome and it works for the othe page but the default page that you added is never removed.
I tried to manipulate the window item to hide it, try to click on the next button with a command to navigate
but it doesn't work. And I verified that handles are correct.
so what it the solution in this context to interact with your unwelcome page or to remove it?
thanks in advance
https://github.com/electron-userland/electron-builder/issues/6987
screenshot
after searched deeper,
I can see in the electron-builder code (after cloning the repo) that the assistedInstaller.nsh
managed the uninstaller as is
...
!else
!insertmacro MUI_UNPAGE_WELCOME
!ifndef INSTALL_MODE_PER_ALL_USERS
!insertmacro PAGE_INSTALL_MODE
!endif
!insertmacro MUI_UNPAGE_INSTFILES
!ifmacrodef customUninstallPage
!insertmacro customUninstallPage
!endif
!insertmacro MUI_UNPAGE_FINISH
!endif
the !insertmacro MUI_UNPAGE_WELCOME is added without condition whereas the customWelcomePage is added with a condition.
I guess it's the root cause of my problem.
If I try to add a custom unwelcome page like this
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ModifyUnWelcome
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.LeaveUnWelcome
!insertmacro MUI_UNPAGE_WELCOME
Var mycheckbox ;
Function un.ModifyUnWelcome
${NSD_CreateCheckbox} 120u -18u 50% 12u "Clean Configuration"
Pop $mycheckbox
SetCtlColors {MUI_BGCOLOR}
${NSD_Check} $mycheckbox ; Check it by default
FunctionEnd
Function un.LeaveUnWelcome
${NSD_GetState} $mycheckbox $0
${If} $0 <> 0
MessageBox MB_TOPMOST 'We remove configuration'
${EndIf}
FunctionEnd
I have my custom unwelcomePage, but when click on next I go to the second unwelcome page placed in the assistedInstaller.nsh
And I have no ways to change this file.
if someone knows how to manage this file. I guess that I must rebuild electron-builder with a change for that but It will be better that electron-builder team fix the problem isn't it?
Finally I Proposed a fix, and the fix was accepted and pushed to the version 23.0.6
Now you have just to update your nsis part in your package.json adding the field removeDefaultUninstallWelcomePage to true as bellow:
"nsis": {
...
"removeDefaultUninstallWelcomePage": true
},
And add the macros on your nsh file:
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ModifyUnWelcome
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.LeaveUnWelcome
!define MUI_WELCOMEPAGE_TITLE_3LINES
!insertmacro MUI_UNPAGE_WELCOME
And you have just to add your custom code on the show and leave part.

Detect setup cancel on NSIS license page

I am trying to detect user canceling setup at the license page. I have tried Function .onInstFailed but it is only invoked when installation is aborted further down the chain. It is not triggered when user cancels on the license page. Is this doable? Here is the top of my script. licleave function is called only upon hitting I Agree.
!include nsdialogs.nsh
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_SHOW licshow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE licleave
!insertmacro MUI_PAGE_LICENSE "license.txt"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
You can define your own MUI_CUSTOMFUNCTION_ABORT function to process the page cancel.
As suggested in that NSIS forum thread, you could set a flag to 1 when entering the license page, and set it to 0 when leaving the page.
In the abort callback, test the flag: if set then you just canceling the license page.

MUI_PAGE_HEADER_TEXT usage in nsis

Using MUI2.nsh. The MUI_PAGE_HEADER_TEXT definition is ignored:
!define MUI_PAGE_HEADER_TEXT "Page title"
!define MUI_WELCOMEPAGE_TEXT "Welcome to the installer. \
\
Begin by clicking Install \
Depending on computer you may need to be \
very patient. \
Watch the hard drive light!"
;-------------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
The welcome page displays with "Name Setup" as the page title. What am I doing wrong?
The page header is not visible on the Welcome and Finish pages, you need to use MUI_WELCOMEPAGE_TITLE.
See the "Page settings > Welcome page settings" section in the MUI readme.

nsis custom page sizes

I am trying to create a page that is showing my website (nsWeb::ShowWebInPage).
The problem is, it can't show the whole page.
How can I define new sizes (height x width) to this page?
This is a big task. Here are the steps for making it work, in a somewhat flexible way.
Download Resource Hacker: http://www.angusj.com/resourcehacker/
Then decide if you want to edit the Unicode or the ANSI version of NSIS. You could do both, but why bother. Find your Program Files\NSIS folder first. This will be the BASE folder for the following directories in the next step if you are compiling for ANSI. If you are compiling for unicode, then step into the Program Files\NSIS\Unicode folder, and THIS is now your base folder for the next steps.
Look inside the \Contrib\UIs folder. This folder stores a bunch of executable files. Depending on which configuration of MUI2 you are using you need to edit the respective file AND modern.exe. The version of the file depends on if ou have a header image, if it's adjusted right or not, etc.
For example, in my case, I had these definitions in my installer script
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_RIGHT
Now, when I look in \Contrib\Modern UI 2\Interface.nsh, I can figure out fairly easily which file I need to edit. Here is what I look at:
!insertmacro MUI_DEFAULT MUI_UI "${NSISDIR}\Contrib\UIs\modern.exe"
!insertmacro MUI_DEFAULT MUI_UI_HEADERIMAGE "${NSISDIR}\Contrib\UIs\modern_headerbmp.exe"
!insertmacro MUI_DEFAULT MUI_UI_HEADERIMAGE_RIGHT "${NSISDIR}\Contrib\UIs\modern_headerbmpr.exe"
!insertmacro MUI_DEFAULT MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!insertmacro MUI_DEFAULT MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!insertmacro MUI_DEFAULT MUI_BGCOLOR "FFFFFF"
Since I'm using the MUI_HEADERIMAGE_RIGHT, I will be editing the modern_headerbmpr.exe file.
Now, open Resource Hacker and load the file you want to edit. Resource Hacker has a GUI, so as you step through each dialog and each control on the dialog, you can see the GUI change side after you press 'recompile'. This part is pretty straight forward. Step through ALL the dialogs (why not) and edit the controls and sizes, including that of the main installer. In this file, there is only one, so you ALSO need to open up modern.exe, which contains the sub-controls that goes into the installer pages. Again, step through all the dialogs and change all the sizes so each control looks good. Compile, and save the files back in to this folder.
Bonus points: For testing, just overwrite the original files. You did take a backup, right? For deployment, name the new files something like "modern-wide.exe", for each file you edit. Later, we can dynamically switch between these with a little magic.
Recompile your installer, and now you should see a new size installer.
If you don't, check that you are in fact in the right ANSI versus UNICODE folder, or your changes won't work.
SOME of the screens, however, add controls dynamically. As an example, look at \Contrib\Modern UI 2\Pages\Welcome.nsh.
This file adds the title label and welcome text in code, and NOT via the exe files. Argh, I know! So locate the Macro:
!macro MUI_FUNCTION_WELCOMEPAGE PRE LEAVE
And these lines of code:
${NSD_CreateBitmap} 0u 0u 109u 193u ""
...
${NSD_CreateLabel} 120u 10u 195u ${MUI_WELCOMEPAGE_TITLE_HEIGHT}u "${MUI_WELCOMEPAGE_TITLE}"
...
${NSD_CreateLabel} 120u ${MUI_WELCOMEPAGE_TEXT_TOP}u 195u 130u "${MUI_WELCOMEPAGE_TEXT}"
As you can see, the units here are X Y WIDTH HEIGHT, so now you get to modify these controls. Of course, if you don't use the welcome page, don't bother. But you may need to edit the pages that doesn't work for you in this manner.
You can overwrite the original, or again, save the file with "-wide" appended to the filename.
Now, your basically done !
Now, to make this MUCH easier to switch, I will assume you saved:
welcome.nsh as welcome-wide.nsh
modern.exe as modern-wide.exe
and let's say modern_headerbmpr.exe as modern_headerbmpr-wide.exe
Now, in your installer, add this !define BEFORE including MUI2.nsh:
!define MUI_ALTERNATE_SIZE_EXT "-wide"
in interface.nsh, change the code to this:
!ifdef MUI_ALTERNATE_SIZE_EXT
!insertmacro MUI_DEFAULT MUI_UI "${NSISDIR}\Contrib\UIs\modern${MUI_ALTERNATE_SIZE_EXT}.exe"
!insertmacro MUI_DEFAULT MUI_UI_HEADERIMAGE "${NSISDIR}\Contrib\UIs\modern_headerbmp.exe"
!insertmacro MUI_DEFAULT MUI_UI_HEADERIMAGE_RIGHT "${NSISDIR}\Contrib\UIs\modern_headerbmpr${MUI_ALTERNATE_SIZE_EXT}.exe"
!insertmacro MUI_DEFAULT MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!insertmacro MUI_DEFAULT MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!insertmacro MUI_DEFAULT MUI_BGCOLOR "FFFFFF"
!else
!insertmacro MUI_DEFAULT MUI_UI "${NSISDIR}\Contrib\UIs\modern.exe"
!insertmacro MUI_DEFAULT MUI_UI_HEADERIMAGE "${NSISDIR}\Contrib\UIs\modern_headerbmp.exe"
!insertmacro MUI_DEFAULT MUI_UI_HEADERIMAGE_RIGHT "${NSISDIR}\Contrib\UIs\modern_headerbmpr.exe"
!insertmacro MUI_DEFAULT MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!insertmacro MUI_DEFAULT MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"
!insertmacro MUI_DEFAULT MUI_BGCOLOR "FFFFFF"
!endif
This essentially switches your installer from regular to "-wide" when you define MUI_ALTERNATE_SIZE_EXT as "-wide". Note how I added the ${MUI_ALTERNATE_SIZE_EXT} directly to the file name include of the files I changed, and you should of course do this for the files YOU ended up changing when you started.
Now, you will also need to do this in the MUI2.NSH file, like so:
!ifdef MUI_ALTERNATE_SIZE_EXT
!include "Pages\Components.nsh"
!include "Pages\Directory.nsh"
!include "Pages\Finish.nsh"
!include "Pages\InstallFiles.nsh"
!include "Pages\License.nsh"
!include "Pages\StartMenu.nsh"
!include "Pages\UninstallConfirm.nsh"
!include "Pages\Welcome${MUI_ALTERNATE_SIZE_EXT}.nsh"
!else
!include "Pages\Components.nsh"
!include "Pages\Directory.nsh"
!include "Pages\Finish.nsh"
!include "Pages\InstallFiles.nsh"
!include "Pages\License.nsh"
!include "Pages\StartMenu.nsh"
!include "Pages\UninstallConfirm.nsh"
!include "Pages\Welcome.nsh"
!endif
As you edit more files, you simply keep a version of each new UI you create in separate filenames, and now you can switch the UI style of your installer with just the one definition. You can name files as you wish, and expand this scheme to other areas where you may run into trouble.
Not an easy task to do this, but it can be done.
You have two options:
Use the ChangeUI instruction along with a custom/resized UI created by Resource Hacker (NSIS ships with the default and modern ui's in the contrib folder, you can just modify those)
Resize the dialog at runtime with the system plugin (call user::SetWindowPos) in the show callback for the page
You have to resize all dialogs using the Resource Hacker.
Standard dialog (inner) size is 300*140 units, increase it as you wish.
Do not forget to increase all dialogs (License page, Installation page, Directory page, etc) also on this new size.

NSIS - retrieving the start menu folder not working as expected

In my NSIS script, the MUI_STARTMENU_GETFOLDER macro is not working as expected - instead of giving me the folder that the user actually entered, it gives me the default that I set earlier. Near the beginning of my script I have:
Var StartMenuFolder ; Define variable to hold start menu folder
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "${PRODUCT_PUBLISHER}\${PRODUCT_NAME}" ; Set default start menu folder
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder
I can access $StartMenuFolder in installer (but NOT uninstaller) Sections by use of !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder. In uninstaller sections and macros, instead of returning the actual start menu folder, it returns the default folder I specified above.
The MUI_STARTMENU_GETFOLDER macro assumes that you used the MUI_STARTMENUPAGE_REGISTRY_* defines and the MUI_STARTMENU_WRITE_* macros during install (All MUI_STARTMENU_GETFOLDER does is read the registry entry written by the installer (The entry is written in MUI_STARTMENU_WRITE_END if the MUI_STARTMENUPAGE_REGISTRY_* defines are set correctly))

Resources