NSIS - force the user to select a different directory

So far, I have figured out how to detect a previous installation of my software by reading the registry keys and checking if the directory exists. (Both documents are well described in the NSIS help file.) Now I want to force the user to specify a different directory if the application has previously been installed. (No need to force delete yourself, because previous versions just delete everything, including saved data).

As far as I can see, MUI2.nsh has predefined templates for a license, installation folder, progress indicator, etc. How to add verification at this point in the installer thread?

The update is a Tried Paul solution, but it does not work. At the top of the script, I declared

!define MUI_PAGE_CUSTOMFUNCTION_LEAVE validateDirectory !insertmacro MUI_PAGE_DIRECTORY 

for reference to this function:

 Function validateDirectory ReadRegStr $R0 HKLM "SOFTWARE\Aadhaar Enrolment Client" "Installdir" Pop $R0 StrCmp $R0 $OUTDIR +1 +3 MessageBox MB_ICONSTOP|MB_OK 'The directory $OUTDIR already exists.Please choose a different directory.' Abort FunctionEnd 

This function displays a message but does not interrupt. Moreover, if I click "back" on the directory selection page and go forward again, it will simply continue the installation.

+4
source share
1 answer

You need to specify the β€œLeave” function for a directory page like this

 !define MUI_PAGE_CUSTOMFUNCTION_LEAVE LeaveDirectory !insertmacro MUI_PAGE_DIRECTORY 

and this will call the function specified when you click Next.

Then create a LeaveDirectory function with the logic necessary to check the selected directory, and if the directory is defined as invalid, just call Abort in the function and the installer will not proceed to the next step.

The documentation is on the this page in the Custom Functions section, but because you need to expand the Custom Functions page is not obvious.

+4
source

Source: https://habr.com/ru/post/1385524/


All Articles