Archive: Strange Behaviour with .onVerifyInstDir


Strange Behaviour with .onVerifyInstDir
I am writing an installer to replace an executable that already exists and to ensure the user chooses the correct directory I am using onVerifyInstDir to check that the executable to be replaced already exists.

However, although in the install directory browse popup the OK button enables and disables correctly, the Install button on the main dialog only enables if you choose the default install directory, if you choose an alternate directory that contains the executable to be replaced the Install button remains disabled.

Here is the entire script:


Name "Uploader SP1"
OutFile "UploaderSP1.exe"

InstallDir $PROGRAMFILES\Uploader

Page directory
Page instfiles

Section ""
SetOutPath $INSTDIR
File "Uploader.exe"
SectionEnd

Function .onVerifyInstDir
IfFileExists $INSTDIR\Uploader.exe PathGood
Abort ;
PathGood:
FunctionEnd


Any suggestions on what I'm doing wrong?

Try using quotes, like this:

IfFileExists "$INSTDIR\Uploader.exe" PathGood


I have tried quoting everything and that didn't work. I just worked out what's happening:

$INSTDIR is $PROGRAMFILES\Uploader, if you then browse for a directory that contains Uploader.exe (for example C:\Test) the OK button in the Browse box is enabled but when you click OK instead of putting C:\Test in the directory text box it is putting C:\Test\Uploader, it is as if it is appending the static part of $INSTDIR. Is this a bug?


Is this a bug?
No, this is explainied in the Users Manual

http://nsis.sourceforge.net/Docs/Chapter4.html#4.8.1.21

Here is a relevant extract from that section:

"Note that the part of this string following the last \ will be used if the user selects 'browse', and may be appended back on to the string at install time (to disable this, end the directory with a \ (which will require the entire parameter to be enclosed with quotes)"

Thanks, works a treat.