I would like to detect if a directory already exists in a custom installation location selected by the user in the GUI. I tried the following:
<Property Id="DIRECTORY_PATH">
<DirectorySearch Id="DirectorySearch" Path="[INSTALLDIR]\MyDirectory" />
</Property>
But this doesn't work because the DirectorySearch is happening during AppSearch. While INSTALLDIR is set later during InstallDirDlg. Since INSTALLDIR is not set in time for AppSearch, DIRECTORY_PATH is incorrectly set to "\MyDirectory".
I tried to change when AppSearch happens with InstallUISequence and InstallExecuteSequence, but it will only let AppSearch come before CostInitialize, no later.
So how do I do a directory search at the user selected INSTALLDIR location?
If you only have to wait for the user's choice to verify that directory, then DirectorySearch won't do the job for you. You'll have to author a "set property" custom action right after the user chooses INSTALLDIR, for instance, on a Next click of InstallDirDlg.
UPDATE. So, I mean basically the following:
- when the user gets to the InstallDirDlg of your setup, he/she selects the directory, which is put to the INSTALLDIR property
- the dialog InstallDirDlg should then trigger a custom action on Next button
- this custom action should get the value of INSTALLDIR property, and do a simple file system check whether INSTALLDIR contains MyDirectory
- if it does, the DIRECTORY_PATH property is set to the necessary value, e.g.
session["DIRECTORY_PATH"] = session[INSTALLDIR] + "\MyDirectory";
- otherwise, DIRECTORY_PATH is not set (and you can use this fact in any condition by checking
NOT DIRECTORY_PATH
)
Hope it makes it clearer.
Hope this will help you.
If you have stored the INSTALLDIR of previous installation in registry, you can get it and search for it. In the Install UI sequence the Installtion location will point to previous location.
<!-- Set previous install location, if available -->
<Property Id="INSTALLDIR" Secure="yes">
<RegistrySearch Id="InstallRootRegistry"
Type="raw"
Root="HKLM"
Key="SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
Name="INSTALLDIR" />
</Property>
<!-- The property WIXUI_INSTALLDIR must be set for the UI to know which directory to use as default -->
<Property Id="WIXUI_INSTALLDIR"
Value="INSTALLDIR" Secure="yes"/>