RelGotoPage function goes to next page instead of going back - nsis

My current defined order of pages in the Installer are:
!insertmacro MUI_PAGE_WELCOME ; Welcome page
!insertmacro MUI_PAGE_DIRECTORY ; Select a directory
!define MUI_PAGE_CUSTOMFUNCTION_PRE CheckInstallDirectory ; Check selected directory
!insertmacro MUI_PAGE_COMPONENTS ; Choose install components
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicense ; Component1's check before license page
!insertmacro MUI_PAGE_LICENSE "license.txt" ; Component1's license
!define MUI_PAGE_CUSTOMFUNCTION_PRE SkipLicenseForComp2 ; Component2's check before license page
!insertmacro MUI_PAGE_LICENSE "License2.txt" ; Component2's license
!insertmacro CUSTOM_PAGES ; Custom install pages
!insertmacro MUI_PAGE_INSTFILES ; Install components' files
!insertmacro MUI_PAGE_FINISH ; Finish page
In the CheckInstallDirectory function, which is defined below, it checks if the end-user selected a directory that already houses an .exe that would otherwise be installed by the installer.
If the directory exists, the user is presented a pop-up message box with the "OK" and "CANCEL" buttons.
"OK" selection should simply skip the next few pages and go to MUI_PAGE_INSTFILES page.
"CANCEL" selection should return the user to the MUI_PAGE_DIRECTORY page.
Function CheckInstallDirectory
IfFileExists "$INSTDIR\Component1.exe" file_found end_of_check
file_found:
Var /GLOBAL ver_
${GetFileVersion} "$INSTDIR\Component1.exe" $ver_
StrCpy $0 $ver_ 1 ; Determine the major version of the installed exe (1st char of the returned string)
StrCpy $1 $ver_1 1 ; Determine the major version of the exe we are installing (1st char of the returned string)
${If} $0 == $1
; The major version between .exe's is the same
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "A copy of this software is already installed in the selected directory.$\nSelect $\"OK$\" if you would like to update the software to the latest version.$\nOtherwise select $\"Cancel$\" to go back and select a different installation directory." IDOK OK IDCANCEL CANCEL
OK:
; User selected to update this software - continue with the installation like normal
StrCpy $R9 "7" ; Skip to the installation page
Call RelGotoPage
goto end_of_check
CANCEL:
StrCpy $R9 "-1" ; Go back to directory selection page
Call RelGotoPage
goto end_of_check
${Else}
; The major version between the .exe's is NOT the same - cannot update
MessageBox MB_OK "A copy of this software is already installed in the selected directory.$\nIt is not part of the latest major-version group and cannot be updated. To update this installation, uninstall and use the installer to install the latest version.$\nOtherwise, select$\"OK$\" to go back and select a different installation directory."
StrCpy $R9 "-1" ; Go back to directory selection page
Call RelGotoPage
goto end_of_check
${EndIf}
end_of_check:
FunctionEnd
I have found NSIS's description for how to move across installer pages here.
Function RelGotoPage
IntCmp $R9 0 0 Move Move
StrCmp $R9 "X" 0 Move
StrCpy $R9 "120"
Move:
SendMessage $HWNDPARENT "0x408" "$R9" ""
FunctionEnd
The problem that is occurring is that StrCpy $R9 "7" does successfully skip to the MUI_PAGE_INSTFILES page. Yet, StrCpy $R9 "-1" does not return to the previous page (which should be MUI_PAGE_DIRECTORY). Instead, if "CANCEL" is selected in that pop-up message, the installer goes to the next page, MUI_PAGE_COMPONENTS.
What is incorrect here?
Is there a better way to achieve the desired result?
Any help is sincerely appreciated! Thank you!

In the page pre-callback the page is not fully loaded and I assume that is why -1 does not work correctly. -1 does work if you use MUI_PAGE_CUSTOMFUNCTION_SHOW but the proper way to do this is to block the page change:
!include MUI2.nsh
!insertmacro MUI_PAGE_WELCOME ; Welcome page
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckInstallDirectory
!insertmacro MUI_PAGE_DIRECTORY
...
Function CheckInstallDirectory
;Snipped
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "A copy of this software is already installed in the selected directory.$\nSelect $\"OK$\" if you would like to update the software to the latest version.$\nOtherwise select $\"Cancel$\" to go back and select a different installation directory." IDOK OK IDCANCEL CANCEL
OK:
; User selected to update this software - continue with the installation like normal
StrCpy $R9 "7" ; Skip to the installation page
Call RelGotoPage
goto end_of_check
CANCEL:
Abort
;Snipped
end_of_check:
FunctionEnd

Related

Customizing the NSIS Uninstaller Confirm Page

I've done some research on customizing NSIS uninstaller pages and had some success with the Welcome and Finish pages.
However I'm having trouble using the same template as I did on the Welcome page with the Confirm page. If I add any control using nsDialogs with a non-zero height value, all of the existing controls (apart from the header and the buttons) on the Confirm page disappear.
Here is my code (it successfully updates the button name but will remove all other controls on that page)
!include MUI2.nsh
OutFile "CustomUninstaller.exe"
InstallDir "C:\Program Files (x86)\NSIS\Examples\CustomFinish"
!define APPNAME "Testing"
Name "${APPNAME}"
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_WELCOME
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ModifyUnConfirm ; My custom function for the Confirm page
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Function un.ModifyUnConfirm
# Change "Uninstall" button to say "Continue" on uninstaller confirmation page
GetDlgItem $0 $HWNDPARENT 1
SendMessage $0 ${WM_SETTEXT} 0 "STR:Continue"
# Add new label. If these three lines are commented out, I see the regular controls of this page show up.
# The position, color and background of the label don't seem to matter
${NSD_CreateLabel} 50% 50% 100% 10u "Testing!!!"
Pop $0
SetCtlColors $0 "" ${MUI_BGCOLOR}
FunctionEnd
Section TestUninstaller
WriteUninstaller "$INSTDIR\unCustomUninstaller.exe"
ExecWait "$INSTDIR\unCustomUninstaller.exe"
Sectionend
Questions:
Does anyone know why the controls disappear?
What do I need to do to successfully add a control to this page?
MUI_UNPAGE_CONFIRM is not a nsDialogs page!
To change this dialog you can use the ChangeUI command.
You can also add controls at runtime but only by using the system plugin:
Function un.ModifyUnConfirm
FindWindow $1 "#32770" "" $HWNDPARENT ; Find inner dialog
System::Call 'USER32::CreateWindowEx(i${__NSD_Label_EXSTYLE},t"${__NSD_Label_CLASS}",t "Testing!!!",i${__NSD_Label_STYLE},i 50,i 100,i 400, i 25,i$1,i0,i0,i0)i.s'
Pop $0
SendMessage $HWNDPARENT ${WM_GETFONT} 0 0 $1
SendMessage $0 ${WM_SETFONT} $1 1
SetCtlColors $0 "" ${MUI_BGCOLOR} ; This is the wrong color to use...
FunctionEnd

Adding a checkbox to the NSIS Uninstaller Welcome Page

I'm trying to add a checkbox to the welcome screen of my NSIS uninstaller, but I'm having trouble finding an example. From the documentation for MUI2 I can't find any custom functions that can be run on the welcome page.
It looks like the finish page is more easy to customize based on the documentation and other answers I've found.
Is there a way to customize the Welcome Page? If not, what are the other options for accomplishing the intent?
The MUI(1) documentation you linked to has a note about how you can customize the welcome page in the pre/show callbacks. With MUI2 you can add controls in the show callback. See the nsDialogs documentation for more information about these custom controls...
!include MUI2.nsh
!insertmacro MUI_PAGE_INSTFILES
!define MUI_PAGE_CUSTOMFUNCTION_SHOW un.ModifyUnWelcome
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE un.LeaveUnWelcome
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Var mycheckbox ; You could just store the HWND in $1 etc if you don't want this extra variable
Function un.ModifyUnWelcome
${NSD_CreateCheckbox} 120u -18u 50% 12u "Do something special"
Pop $mycheckbox
SetCtlColors $mycheckbox "" ${MUI_BGCOLOR}
${NSD_Check} $mycheckbox ; Check it by default
FunctionEnd
Function un.LeaveUnWelcome
${NSD_GetState} $mycheckbox $0
${If} $0 <> 0
MessageBox mb_ok "I'm special"
${EndIf}
FunctionEnd
Section testuninstaller
Initpluginsdir
WriteUninstaller "$pluginsdir\u.exe"
ExecWait '"$pluginsdir\u.exe" _?=$pluginsdir'
Sectionend

How to call directory page inside the function in NSIS?

I have created Exe file for my app using NSIS script.In my script i have checked free space for selected directory.
1.If selected directory dont have required space then user wants to change the directory.
2.After changing directory in directory page again wants to check free space.so when the required space is available for the selected directory then only proceed to next page.
So it will come under looping statement.I have tried following script
page custom checking
Function checking
Push "\"
push $InstallDir
Call SplitFirstStrPart
pop $R0
${DriveSpace} $R0 "/D=F /S=G" $R0
${While} $R0 <= 2
MessageBox MB_OK "Expected free space is not availble"
call directory
${EndWhile}
Function directory
--Here i want to define directory page--
[page directory] we cant use this here
call checking
FunctionEnd
1.How to create user defined directory page?
2.Is possible to call page directory or MUI_PAGE_DIRECTORY multiple times?
Thanks
You cannot call a page from a function but you can skip a page by calling Abort in the page PRE callback and you can also jump to any page.
You can have multiple pages of all page types:
!include MUI.nsh
Var dir1
Var dir2
Function .onInit
StrCpy $dir1 c:\default1
StrCpy $dir2 c:\default2
FunctionEnd
!define MUI_DIRECTORYPAGE_VARIABLE $dir1
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_DIRECTORYPAGE_VARIABLE $dir2
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Section
DetailPrint $dir1
DetailPrint $dir2
SectionEnd

Changing the selection in the components page of NSIS based on the OS on which we are installing

I am finding it difficult to change the selection in the components page of nsis.
The requirement is during installation i get a license agreement page ,if the user agrees then he/she will click on I AGREE ,after the user clicks on I AGREE ,i want to know on which OS the
setup is being installed that is it can be either on a Windows Embedded OS or WinXp/Win7.
So if it is Windows Embedded OS i want to change the installation package and if it is not Windows Embedded OS then the installation package will be different.
I am using MUI ver1 not MUI2 in my project.
Please let me know how this can be achieved.
To test for the OS where the setup is running, you can use macros defined Winver.nsh with those provided with LogicLib.nsh to make elegant tests like this
;Dont't forget to include
!include "LogicLib.nsh" # use of various logic statements
!include "WinVer.nsh" # LogicLib extension for OS tests
A platform test example:
${if} ${AtLeastWin95}
${AndIf} ${AtMostWinME}
;here we are on a pre-win2k
;do something
${elseIf} ${isWin2008}
${orIf} ${AtLeastWin2008R2}
;this is post-win7
;do other thing
${endif}
To change at runtime the components to install, you can use the macros from Sections.nsh:
;if you have
Section "Sample Database" SecApplicationDB
;...
SectionEnd
;you can select or un select by code:
!insertmacro SelectSection ${SecApplicationDB}
;or
!insertmacro UnselectSection ${SecApplicationDB}
WinVer.nsh does not support checking for Embedded NT but you can perform the check yourself:
!include Sections.nsh
!include MUI.nsh
!ifndef VER_SUITE_EMBEDDEDNT
!define VER_SUITE_EMBEDDEDNT 0x00000040
!endif
!insertmacro MUI_PAGE_LICENSE "${__FILE__}"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Section "Embedded" SID_EMBED
SectionIn RO
SectionEnd
Section "Normal" SID_NORMAL
SectionIn RO
SectionEnd
Function .onInit
System::Call '*(i156,&i152)i.r1'
System::Call 'KERNEL32::GetVersionExA(ir1)'
System::Call '*$1(&i152,&i2.r2)'
System::Free $1
IntOp $2 $2 & ${VER_SUITE_EMBEDDEDNT}
${If} $2 <> 0
!insertmacro SelectSection ${SID_EMBED}
!insertmacro UnselectSection ${SID_NORMAL}
${Else}
!insertmacro UnselectSection ${SID_EMBED}
!insertmacro SelectSection ${SID_NORMAL}
${EndIf}
FunctionEnd

Set value of InstallDir in a function, or set auto populate value somehow?

I'm creating an installer using NSIS. This installer actually installs two programs in two different directories in the same installer. I am doing this using the modern user interface (MUI) pages and simply calling MUI_PAGE_DIRECTORY twice specifying different starting parameteres, and capturing the directory in the LEAVE macro. What I'm wondering is, can I somehow call InstallDir in a function, or set the auto directory populate value in a function? Or possibly even call a function after the browse button has been returned from?
The reason I want to do this is so when the user clicks the browse button in either of the two directory pages, after they select a directory, the name of the finnal directory specifed in InstallDir will be appended.
For example:
InstallDir value for program 1: c:\client
InstallDir value for program 2: c:\program files\server
user clicks browse on program 1 and chooses c:\temp the resulting path is c:\temp\client
user clicks browse on program 2 and chooses c:\whatever the resulting path is c:\whatever\server
For reference here are the code snipits of what I have that works, but does not deal with the auto append browse button behaviour:
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ClientDirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ServerDirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY
; Setup the page display for the client install page
Function ShowPageClient
!insertmacro MUI_HEADER_TEXT "Client" "Client"
!insertmacro MUI_INNERDIALOG_TEXT 1006 "Client"
; setup intal directory
Push $0
StrCpy $0 $PROGRAMFILES 2 #
; CLIENT_FOLDER_NAME is defined as a folder, but this would basicaly
; result in C:\Client as the first 2 characters of $PROGRAMFILES
; is the hard drive with program files installed on it
StrCpy $INSTDIR "$0\${CLIENT_FOLDER_NAME}"
Pop $0
; set the inital value of the directory text box
!insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR
; find and disable the directory selection box
; We do not want users to type in this box
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $R1 $R0 1019 ;Text Box
EnableWindow $R1 0
FunctionEnd
; Setup the page display for the server install location page
Function ShowPageServer
!insertmacro MUI_HEADER_TEXT "Server" "Server"
!insertmacro MUI_INNERDIALOG_TEXT 1006 "Server"
; setup intal directory
; SERVER_FOLDER_NAME is defined as a folder, but this would basicaly
; result in C:\Program Files\Server
StrCpy $INSTDIR "$PROGRAMFILES\${SERVER_FOLDER_NAME}"
; set the inital value of the directory text box
!insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR
; find and disable the directory selection box
; We do not want users to type in this box
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $R1 $R0 1019 ;Text Box
EnableWindow $R1 0
FunctionEnd
Note: I can make the browse button work for one of the directory pages, but then when I'm on the second page, the auto populate actual auto populates incorrectly
The appended folder name is constant and set at compile time, there is a bug report related to this.
My advice is to abandon the append feature and let the user have full control over the two destinations:
Name "NSIS Test"
InstallDir ""
!include MUI.nsh
Var DirClient
Var DirServer
Function .onInit
;Set default destinations
StrCpy $DirClient "$ProgramFiles\$(^Name)\Client"
StrCpy $DirServer "$ProgramFiles\$(^Name)\Server"
FunctionEnd
!macro ConfigureMyDirPage type var
!define MUI_DIRECTORYPAGE_VARIABLE ${var}
!define MUI_PAGE_HEADER_SUBTEXT "Choose the folder in which to install $(^NameDA) ${type}"
!define MUI_DIRECTORYPAGE_TEXT_TOP "Setup will install $(^NameDA) ${type} in the following folder. To install in a different folder, click Browse and select another folder. $_CLICK"
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "${type} $(^DirSubText)"
!macroend
!insertmacro ConfigureMyDirPage "Client" $DirClient
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro ConfigureMyDirPage "Server" $DirServer
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section
DetailPrint DirClient=$DirClient
DetailPrint DirServer=$DirServer
SectionEnd
Okay I finally figured it out. Basically there is a function that is called to "verify" the path after browse button is clicked. I tied into this function an appended the directory manual if needed. To do this I created a new variable and set it in a function called when the page is displays as follows:
; Client Directory
!define MUI_PAGE_CUSTOMFUNCTION_SHOW ShowPageClient
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE ClientDirectoryLeave
!insertmacro MUI_PAGE_DIRECTORY
; Setup the page display for the client install page
Function ShowPageClient
; setup intal directory
Push $0
StrCpy $0 $PROGRAMFILES 2 #
StrCpy $INSTDIR "$0\${CLIENT_FOLDER_NAME}"
Pop $0
!insertmacro MUI_INNERDIALOG_TEXT 1019 $INSTDIR
FindWindow $R0 "#32770" "" $HWNDPARENT
GetDlgItem $R1 $R0 1019 ;Text Box
EnableWindow $R1 0
; Setup the client or server variable to indicate that
; we're in the client install part to signal the .onVerifyInstDir function
; to put the correct directory
StrCpy $CLIENT_OR_SERVER "client"
FunctionEnd
The function that is called after browse is .onVerifyInstDir so that is where I check the CLIENT_OR_SERVER variable and set the path appropriately
; This function is special and is called any time a
; path is validated on returning from the browse button
; need to append the correct directory if it does not already exists
; in the install directory path
Function .onVerifyInstDir
; save the current $0 register, as it is used in this function
Push $0
${If} $CLIENT_OR_SERVER == "client"
; in the client stage so directory must contain CLIENT_FOLDER_NAME
${StrContains} $0 "${CLIENT_FOLDER_NAME}" "$INSTDIR"
${If} $0 == ""
; the install dir does not contain the folder so append it
StrCpy $INSTDIR "$INSTDIR\${CLIENT_FOLDER_NAME}"
${EndIf}
${Else}
; in the server stage so directory must contain SERVER_FOLDER_NAME
${StrContains} $0 "${SERVER_FOLDER_NAME}" "$INSTDIR"
${If} $0 == ""
; the install dir does not contain the folder so append it
StrCpy $INSTDIR "$INSTDIR\${SERVER_FOLDER_NAME}"
${EndIf}
${EndIf}
; pop the saved register value
Pop $0
FunctionEnd
Couple notes:
the StrContains function I used was found here:
http://nsis.sourceforge.net/StrContains
Further reference to the .onVerifyInstDir function can be found here:
http://nsis.sourceforge.net/Docs/Chapter4.html#4.7.2.1.10

Resources