WiX自定义操作中的UI验证继续到服务器模式/安装。

huangapple go评论66阅读模式
英文:

UI validation in WiX custom action proceeds to server mode / installation

问题

在使用wix4(也适用于rc2、rc3和最新版本)中尝试验证自定义对话框中的用户输入。

我找到了各种示例,说明了应该如何工作,但不幸的是,我在这里无法正确实现它。

有一个对话框用于选择文件夹,设置属性如下:

<Publish Dialog="CustomPropertiesDlg" Control="ChangeFooFolder" Property="_BrowseProperty" Value="FOO_DIR" Order="1" />
<Publish Dialog="CustomPropertiesDlg" Control="ChangeFooFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2" />

然后,当用户单击“下一步”时,我尝试运行验证:

<Publish Dialog="CustomPropertiesDlg" Control="Next" Event="DoAction" Value="UI_CheckFooDir" Order="1" />
<Publish Dialog="CustomPropertiesDlg" Control="Next" Event="NewDialog" Value="InvalidFooPathDlg" Order="2" Condition="FOO_DIR_VALID<>"1"" />
<Publish Dialog="CustomPropertiesDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg" Order="5" Condition="FOO_DIR_VALID="1"" />

<Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="CustomPropertiesDlg" Order="10" />

在这一点上,我的期望是,无效的目录将设置FOO_DIR_VALID="0"(如果有效则为"1")。

这是一个简单的代码,如下所示:

[CustomAction]
public static ActionResult VerifyFooPath(Session session)
{
  session["FOO_DIR_VALID"] = "0";
  var fooDir= session["FOO_DIR"];
  session.Log($"Checking whether {fooDir} contains a foo.exe file");
  if (Directory.Exists(fooDir) && File.Exists(Path.Combine(fooDir, "foo.exe")))
  {
    session.Log($"Foo directory accepted as {fooDir}");
    session["FOO_DIR_VALID"] = "1";
  }
  return ActionResult.Success;
}

然而,尽管日志显示自定义操作执行并设置了FOO_DIR_VALID属性,尽管UI显示“不,路径无效”的对话框,但安装过程仍然直接进行到服务器阶段。如果我关闭对话框(一个默认的InvalidDirDlg.wxs的副本,具有不同的消息),我希望UI保持在原地,让用户修复错误。然而,它跳过了VerifyReadyDlg(最后一个屏幕)并立即提示提升。我做错了什么?

日志:

Action start 18:19:30: UI_CheckFooDir.
MSI (c) (F4:04) [18:19:30:414]: 调用远程自定义操作。DLL: C:\Users\bla\AppData\Local\Temp\MSI5048.tmp, 入口点: VerifyFooPath
MSI (c) (F4:10) [18:19:30:415]: 启用伪装。
MSI (c) (F4:10) [18:19:30:415]: 在调用服务器上的安装之前尝试启用所有禁用的特权
MSI (c) (F4:10) [18:19:30:415]: 已连接到CA接口的服务。
MSI (c) (F4!C0) [18:19:30:876]: 属性更改: 添加了FOO_DIR_VALID属性。其值为'0'。
Action ended 18:19:30: UI_CheckFooDir. 返回值 1。
Action 18:19:30: InvalidFooPathDlg. 对话框已创建
Action ended 18:19:32: WelcomeDlg. 返回值 1。
MSI (c) (F4:34) [18:19:32:623]: 跳过操作: MaintenanceWelcomeDlg(条件为false)
MSI (c) (F4:34) [18:19:32:623]: 正在执行操作: ProgressDlg
MSI (c) (F4:34) [18:19:32:623]: 注意: 1: 2205 2:  3: ActionText 
Action 18:19:32: ProgressDlg. 
Action start 18:19:32: ProgressDlg.
Action 18:19:32: ProgressDlg. 对话框已创建
Action ended 18:19:32: ProgressDlg. 返回值 1。
MSI (c) (F4:34) [18:19:32:729]: 正在执行操作: ExecuteAction
MSI (c) (F4:34) [18:19:32:729]: 注意: 1: 2205 2:  3: ActionText 
Action 18:19:32: ExecuteAction. 
Action start 18:19:32: ExecuteAction.
MSI (c) (F4:34) [18:19:32:735]: 属性更改: 添加了SECONDSEQUENCE属性。其值为'1'。
MSI (c) (F4:34) [18:19:32:736]: 获取执行互斥体。
MSI (c) (F4:34) [18:19:32:736]: 增加计数器以禁用关机。增加计数器后: 0
MSI (c) (F4:34) [18:19:32:736]: 切换到服务器:(此处省略了属性)```


<details>
<summary>英文:</summary>

Trying to verify user input in a custom dialog using wix4 (same behavior with rc2, rc3 and latest builds).

I found various examples of how it&#39;s supposed to work, but unfortunately I cannot get it right here.

There&#39;s a dialog to pick a folder, setting a property like this: 

```xml
&lt;Publish Dialog=&quot;CustomPropertiesDlg&quot; Control=&quot;ChangeFooFolder&quot; Property=&quot;_BrowseProperty&quot; Value=&quot;FOO_DIR&quot; Order=&quot;1&quot; /&gt;
&lt;Publish Dialog=&quot;CustomPropertiesDlg&quot; Control=&quot;ChangeFooFolder&quot; Event=&quot;SpawnDialog&quot; Value=&quot;BrowseDlg&quot; Order=&quot;2&quot; /&gt;

then I try to run validation when the user clicks Next:

&lt;Publish Dialog=&quot;CustomPropertiesDlg&quot; Control=&quot;Next&quot; Event=&quot;DoAction&quot; Value=&quot;UI_CheckFooDir&quot; Order=&quot;1&quot; /&gt;
&lt;Publish Dialog=&quot;CustomPropertiesDlg&quot; Control=&quot;Next&quot; Event=&quot;NewDialog&quot; Value=&quot;InvalidFooPathDlg&quot; Order=&quot;2&quot; Condition=&quot;FOO_DIR_VALID&amp;lt;&amp;gt;&amp;quot;1&amp;quot;&quot; /&gt;
&lt;Publish Dialog=&quot;CustomPropertiesDlg&quot; Control=&quot;Next&quot; Event=&quot;NewDialog&quot; Value=&quot;VerifyReadyDlg&quot; Order=&quot;5&quot; Condition=&quot;FOO_DIR_VALID=&amp;quot;1&amp;quot;&quot; /&gt;

&lt;Publish Dialog=&quot;VerifyReadyDlg&quot; Control=&quot;Back&quot; Event=&quot;NewDialog&quot; Value=&quot;CustomPropertiesDlg&quot; Order=&quot;10&quot; /&gt;

My expectation at this point is that an invalid directory will set FOO_DIR_VALID="0" (and "1" if it is).

It's trivial code like this:

[CustomAction]
public static ActionResult VerifyFooPath(Session session)
{
  session[&quot;FOO_DIR_VALID&quot;] = &quot;0&quot;;
  var fooDir= session[&quot;FOO_DIR&quot;];
  session.Log($&quot;Checking whether {fooDir} contains a foo.exe file&quot;);
  if (Directory.Exists(fooDir) &amp;&amp; File.Exists(Path.Combine(fooDir, &quot;foo.exe&quot;)))
  {
    session.Log($&quot;Foo directory accepted as {fooDir}&quot;);
    session[&quot;FOO_DIR_VALID&quot;] = &quot;1&quot;;
  }
  return ActionResult.Success;
}

Yet, even though the log shows me that the custom action executes and sets the FOO_DIR_VALID property and even though the UI shows me the "Nope, the path is invalid" dialog.. the installation proceeds straight to the server phase afterwards. If I close the dialog (a straight up copy of the default InvalidDirDlg.wxs with a different message) I want the UI to remain where it is. Let the user fix the error. Yet it skips the VerifyReadyDlg (the last screen) and immediately prompts for elevation. What am I doing wrong?

Log:

Action start 18:19:30: UI_CheckFooDir.
MSI (c) (F4:04) [18:19:30:414]: Invoking remote custom action. DLL: C:\Users\bla\AppData\Local\Temp\MSI5048.tmp, Entrypoint: VerifyFooPath
MSI (c) (F4:10) [18:19:30:415]: Cloaking enabled.
MSI (c) (F4:10) [18:19:30:415]: Attempting to enable all disabled privileges before calling Install on Server
MSI (c) (F4:10) [18:19:30:415]: Connected to service for CA interface.
MSI (c) (F4!C0) [18:19:30:876]: PROPERTY CHANGE: Adding FOO_DIR_VALID property. Its value is &#39;0&#39;.
Action ended 18:19:30: UI_CheckFooDir. Return value 1.
Action 18:19:30: InvalidFooPathDlg. Dialog created
Action ended 18:19:32: WelcomeDlg. Return value 1.
MSI (c) (F4:34) [18:19:32:623]: Skipping action: MaintenanceWelcomeDlg (condition is false)
MSI (c) (F4:34) [18:19:32:623]: Doing action: ProgressDlg
MSI (c) (F4:34) [18:19:32:623]: Note: 1: 2205 2:  3: ActionText 
Action 18:19:32: ProgressDlg. 
Action start 18:19:32: ProgressDlg.
Action 18:19:32: ProgressDlg. Dialog created
Action ended 18:19:32: ProgressDlg. Return value 1.
MSI (c) (F4:34) [18:19:32:729]: Doing action: ExecuteAction
MSI (c) (F4:34) [18:19:32:729]: Note: 1: 2205 2:  3: ActionText 
Action 18:19:32: ExecuteAction. 
Action start 18:19:32: ExecuteAction.
MSI (c) (F4:34) [18:19:32:735]: PROPERTY CHANGE: Adding SECONDSEQUENCE property. Its value is &#39;1&#39;.
MSI (c) (F4:34) [18:19:32:736]: Grabbed execution mutex.
MSI (c) (F4:34) [18:19:32:736]: Incrementing counter to disable shutdown. Counter after increment: 0
MSI (c) (F4:34) [18:19:32:736]: Switching to server: (snipped properties here)```

</details>


# 答案1
**得分**: 1

你需要 `SpawnDialog` `InvalidDirDlg`;`NewDialog` 会替换当前对话框,而 `InvalidDirDlg` 被设计成一个弹出式对话框。(它只有一个“确定”按钮。)

<details>
<summary>英文:</summary>

You need to `SpawnDialog` the `InvalidDirDlg`; `NewDialog` replaces the current dialog and `InvalidDirDlg` is designed as a popup. (It has only an OK button.)

</details>



huangapple
  • 本文由 发表于 2023年2月27日 18:44:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75579438.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定