0

我想检查用户选择的安装目录是否为空(例如,他们不会尝试将应用程序安装到他们的桌面目录中,而不是那里的文件夹中)。到目前为止,我有一个自定义的可执行文件,它会以非常混乱的错误消息中止安装,就在成本最终确定的时候。不过,我宁愿阻止用户继续完成自定义步骤。

这里似乎没有任何相关内容;在 wix-users@ 上也有一些没有有用答案的消息。

4

2 回答 2

1

我也在 DLL 中使用 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>

自定义操作:

  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;
    }
  }
于 2013-07-17T17:14:39.190 回答
0

值得一提的是:最终在 DLL 中编写了一个 WiX 自定义操作,我可以在其中访问安装会话并设置属性。丑陋的解决方案;我仍然认为应该有内置的东西可以做到这一点......我只是找不到它。

对于那些感兴趣的人,相关的变更集在这里

于 2013-07-16T20:52:10.680 回答