6

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?

Michael
  • 63
  • 1
  • 4

2 Answers2

4

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.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • The user's choice only identifies the installation location, not whether a sub-directory I'm searching for "MyDirectory" exists in that location. Without the DirectorySearch, how does the installer know if it should set the property? – Michael Sep 09 '11 at 16:35
  • You'll have to simulate the directory search yourself. As long as the real DirectorySearch happens during AppSearch, it doesn't suit your needs. That's why I quoted the "set property" action - it should not only set a property, but do some logic to find out if the subdirectory exists. – Yan Sklyarenko Sep 09 '11 at 19:19
  • I thought the comment above sounds confusing :) I'll update my answer – Yan Sklyarenko Sep 09 '11 at 19:22
  • Thank you for the detailed answer. The step that was tripping me up is your 3rd item, creating a custom action to do the search. I take it that this part can not be done in Wix, but will require me to create a .dll with the directory search in it? – Michael Sep 09 '11 at 20:46
  • Right, this can't be done in WiX for this particular situation - it's not a typical use case for AppSearch. The code you'll have to write is quite simple - just look for the direct child directories of INSTALLDIR – Yan Sklyarenko Sep 09 '11 at 21:58
0

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"/>
Muthukkumaran
  • 213
  • 4
  • 14