Archive: Verifying that the selected install folder exists and contains <file>


Verifying that the selected install folder exists and contains <file>
I am working on an install in NSIS.
This install installs an enhancement to an existing program.
I use InstallDir to set the default install path of this program and then Page directory to let the end user pick another one.

What I want to do is to be able to force the user to only pick an install folder that contains a specific file (which would be used to be sure they only installed in a folder containing an install of the program my enhancement is for)

How can I do this? Preferably I would like to prevent the user from choosing the wrong folder in the first place but if I cant do that, I want to bring up the directory dialog, have the user select a folder, verify that its correct, if its not, go back and bring up the directory dialog again (after displaying a message to the user) and keep going until the user either cancels the installer or they pick a valid folder.


OnVerifyInstDir
Just add the Function ".onVerifyInstDir" to your script. This function is called everytime the user changes the directory. If you want to ensure that the folder contains a specific file then you could do this with "IfFileExist". Here an example:

Function .onVerifyInstDir
IfFileExists "$INSTDIR\somefile.exe" FileIsThere
Abort ; user can´t go on if "somefile.exe" isn´t present
FileIsThere:
FunctionEnd


have fun ;)

BTW: Nearly every software store it´s installdirectory in the registry. So you can read it out and use it as default instdir so the user don´t have to browse to the right folder. You only have to find out the right registry key. And if the key doesn´t exist you can define a "default installdir":

InstallDir "c:\programs\examplesoftware\" ;define default installdir
InstallDirRegKey HKLM "Software\ExampleSoftware" "TheInstallDirRegkey"
;if exist $insdir contains now the path stored in this key


And alltogether with .onVerifyInstDir the user can´t do anything wrong no more. ;)

Are you sure you can abort from .onVerifyInstDir? I thought you'd have to use the page's leave function and call abort there...


...
Nope... have a look at this. :)