Archive: InstallDirRegKey when directory does not exist


InstallDirRegKey when directory does not exist
  Hello,

because of a former broken setup (not created with NSIS =) our customers sometimes have the problem that the directory from the registry isn´t valid.

The NSIS installer reads the regkey and as the format is correct it simply creates that directory.

Instead, I would like to have the installer inform the customer and also present MUI_PAGE_DIRECTORY.

How can I achieve this?


Lars


In the directory pages pre function, use this:

IfFileExists "$INSTDIR\*.*" abortdir continuedir
abortdir:
abort
continuedir:
; continue here


Use MUI_PAGE_CUSTOMFUNCTION_PRE to call the function just before the directory page is displayed. Calling abort in the pre function will skip that page.

Thanks. That brought me a little step closer to a solution. Now I have the problem that I cannot set the InstallDir within the function.

My code:


ShowDirectoryPage


>var /global test_key
>var /global test_key2
ReadRegStr $test_key HKLM "SOFTWARE\\MyApp" "Path"
>ReadRegStr $test_key2 HKLM "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\MyApp" "UserDir"

>MessageBox MB_OK "test: $test_key"
>MessageBox MB_OK "test2: $test_key2"

>IfFileExists "$test_key\\easy20.exe" continue test_zup
>continue:
MessageBox MB_OK "test: continue"
InstallDir $test_key
abort
test_zup:
IfFileExists "$test_key2\\easy20.exe" continue2 showdir
continue2:
MessageBox MB_OK "test2: continue"
InstallDir $test_key2
abort
showdir:
MessageBox MB_OK "test2: showdir"
>; continue here

functionend
>
I´m checking the old location (uninstall key) where Z-Up Maker made an entry and the new location (software\\myapp) where NSIS makes an entry.

This code works fine in checking the correct location to install, but I cannot set the InstallDir.
I could solely use the uninstall-key but I would find it better to use the standard NSIS key.

Use $INSTDIR var instead of InstallDir attribute.


Originally posted by Takhir
Use $INSTDIR var instead of InstallDir attribute.
It´s working - Thank you! :)

Should I post this as a bug report? I find it illogical that I cannot use InstallDir but use $INSTDIR as InstallDir AFAIK just sets the $INSTDIR variable.

InstallDir sets the default install directory on compile-time. This sets the $INSTDIR by default to its value. To change the value at run-time you need to modify the contents of the $INSTDIR variables (with StrCpy for example).

-Stu


InstallDir defines default value for $INSTDIR. You can find description in the manual 4.8.1.21 and 22.