0

I'd like to check that the installation directory the user has selected is empty (so that, for example, they don't try to install the app into their desktop directory, instead of a folder in there). So far, I've got a custom executable that aborts the installation with a very confusing error message, right around the point the cost gets finalized. I'd rather just prevent the user from continuing past the customization step, though.

Nothing related seemed to be on here; there's a few messages without useful answers on wix-users@ too.

  • Do you plan on changing the directory during upgrades? – Christopher Painter Jul 17 '13 at 19:26
  • Nope; upgrades are expected to be in-place. We are currently using a non-MSI based upgrade system, anyway - yeah, that's sort of bad, but that's known. (I guess I should have mentioned in the question that I only expect the extra checking in the installer UI; people who can do non-interactive installs are expected to be smart enough to not shoot themselves in the foot.) – user5999744 Jul 19 '13 at 23:39
  • This is wrong on so many levels that I'm not even going to touch it – Christopher Painter Jul 20 '13 at 01:33

2 Answers2

1

I did this with WiX custom action in a DLL as well. Here is the code:

WiX:

<Binary Id="CustomAction" SourceFile="$(var.SourceBinFolder)\MyCustomAction.CA.dll" />
<CustomAction Id="CheckFolderCustomAction" BinaryKey="CustomAction" DllEntry="CheckFolder" />
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />

<Publish Dialog="InstallDirDlg" Control="Next" Event="SetTargetPath" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="DoAction" Value="CheckFolderCustomAction" Order="2">1</Publish>
<Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="3">InstallDirOk = "1"</Publish>

Custom Action:

  public class CustomActions
  {
    [CustomAction]
    public static ActionResult CheckFolder(Session session)
    {
      string installDir = session["INSTALLFOLDER"];
      installDir = installDir.Trim();
      session["InstallDirOk"] = "1";
      if (Directory.Exists(installDir) && Directory.EnumerateFileSystemEntries(installDir, "*", SearchOption.TopDirectoryOnly).Any())
      {
        if (DialogResult.No == MessageBox.Show(
              string.Format("Selected folder \"{0}\" is not empty. This might cause existing files to be overwritten. Do you want to proceed?", installDir),
              "Please confirm",
              MessageBoxButtons.YesNo))
        {
          session["InstallDirOk"] = "0";
        }
      }

      return ActionResult.Success;
    }
  }
sean717
  • 11,759
  • 20
  • 66
  • 90
0

For what it's worth: ended up writing a WiX custom action in a DLL, where I can access the install session and set properties. Ugly solution; I still think there should be built-in things that do this... I just can't find it.

For those interested, relevant changeset is here.