NSIS to check installation location is empty or not - nsis

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

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.

Customise NSIS MessageBox title / caption

In an NSIS installer, I'm interested in displaying a MessageBox with a custom title. I currently have:
MessageBox MB_OK|MB_ICONEXCLAMATION|MB_TOPMOST "%SOME_STRING%"
In this call, there's no definition of MessageBox title, which then becomes a default string, saying <Installer Name> Setup. I would like to remove the 'Setup' part, or provide a string of my own.
Thank you.
You can use the Caption attribute to set the caption Caption "Whatever" but that changes it globally.
NSIS does not have native support for a custom MessageBox caption but you can call the Windows API directly:
Section
!define MB_OK 0x00000000
!define MB_ICONINFORMATION 0x00000040
System::Call 'USER32::MessageBox(i $hwndparent, t "The message", t "The caption", i ${MB_OK}|${MB_ICONINFORMATION})i'
SectionEnd
You can lookup the other MB_* flags on MSDN...

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.

How can I disable a button in NSIS while installation?

I am creating a installer which is having multiple component to install(checkbox are provide to select the desired component).
Now, suppose user has not selected any option, even then Next button on the component page is activated.Here I want to disable that next button when no option is selected.
Can anybody tell me how I can do that ?
Please Help me
your problem is really hard to solve if you use standard collection windows as MUI or XPUI, if you are using Modern UI (MUI) then the next code could help you to code the functionality you need (in the XPUI case this does not work at all)
WARNING :
I did NOT tested the next procedures (just compiled), because i'm currently using XPUI and i have deprecated the MUI in my installer, moreover i have provided no logic to re-enable the "next" button in the OnChange_Service function.
handle the event change on your target section, i do not know if it works, but i propose to use the NSD_OnChange procedure (defined in nsdialogs)
!include 'nsdialogs.nsh'
Function <...>
${NSD_OnChange} <... name of the target section ...> OnChange_Service
FunctionEnd
In the event handler function place the code to disable your button
function OnChange_Service
var /GLOBAL NextButton
GetDlgItem $NextButton $HWNDPARENT 1
SectionGetFlags <... name of the target section ...> $0
IntOp $0 $0 & ${SECTION_OFF}
StrCmp $0 "1" DISABLENEXT
GOTOENDONCHANGE
DISABLENEXT:
EnableWindow $NextButton 0
GOTOENDONCHANGE:
functionend
Anywhere i think it is better to use custom window if you need to do some manipulations on the window control state.
Make me know if it works in your project
(If you want to use boolean operator in your code, then use the LogicLib plugin)

Resources