如何在 Wix 中显示操作系统的非阻塞警告? [英] How to display a non-blocking warning for the operating system in Wix?

查看:16
本文介绍了如何在 Wix 中显示操作系统的非阻塞警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阻止在已知无法像这样运行的操作系统上安装我们的软件:

<Condition Message="此软件需要 Windows XP 或更新版本."><![CDATA[VersionNT>= 501]]></条件>

现在,如果用户尝试在未明确支持的操作系统(VersionNT + Service Pack)上安装软件,我还想显示非阻塞警告,即使它 可能工作.

例如,我们只明确支持每个操作系统的最新服务包.

如何显示这样的警告?

解决方案

我分三个部分解决了这个问题:

  1. 定义 OSWarningText 属性仅在警告时设置需要给予
  2. 制作自定义警告屏幕
  3. 如有必要,在 UI 序列中插入自定义警告屏幕

1.定义 OSWarningText 属性

首先,声明属性并默认给它未设置"值:

 <Property Id="OSWarningText" Value="{}"/>

要构造属性的实际值,请为每个可能的警告设置一个中间属性.确保每个警告的条件不重叠:

 <SetProperty Id="OSWarningText1" After="AppSearch"Value="检测到 XP SP [ServicePackLevel].建议使用 SP3 或更高版本."><![CDATA[(VersionNT = 501) AND NOT (ServicePackLevel >= 3)]]></设置属性><SetProperty Id="OSWarningText2" After="SetOSWarningText1"Value="检测到 Vista SP [ServicePackLevel].建议使用 SP2 或更高版本."><![CDATA[(VersionNT = 600) AND NOT (ServicePackLevel >= 2)]]></设置属性>

假设条件不重叠,我们可以安全地将警告压缩在一个属性中,如下所示:

 <SetProperty Id="OSWarningText" After="SetOSWarningText2"值="[OSWarningText1][OSWarningText2]"/>

<强>2.制作自定义警告屏幕.

这类似于

3.在 UI 序列中插入自定义警告屏幕

现在我们需要确保在欢迎对话框和许可协议对话框之间显示警告屏幕,但前提是确实要显示警告.这是更一般的 分支向导的特例序列 问题.

再次,从 wix 源复制预定义的 UI 序列,例如WixUI_InstallDir.wxs 并将 UI ID 重命名为 Id="MyWixUI".在您的主 wxs 文件中将其引用为 <UIRef Id="MyWixUI"/>.现在找到并编辑 WelcomeDlg 下一步按钮的事件处理程序.

您可以设置属性以响应按钮按下和额外条件,并且您可以根据属性显示下一个对话框.我们将使用它来处理 WelcomeDlg 的 next 按钮,如下所示:

  1. 重置 WelcomeDlg_Next 属性取消设置"
  2. 将 WelcomeDlg_Next 属性设置为WarningDlg",但前提是OSWarningText 已设置
  3. 将 WelcomeDlg_Next 属性设置为LicenseAgreementDlg",但前提是未设置 OSWarningText.
  4. 显示给出的对话框WelcomeDlg_Next,如果属性是正确设置.

执行此操作的 Wix 代码如下所示:

 <Publish Dialog="WelcomeDlg" Control="Next"属性="WelcomeDlg_Next" 值="{}"Order="1">1</Publish><发布对话框="WelcomeDlg" 控制="下一步"属性="WelcomeDlg_Next" 值="WarningDlg"Order="2">OSWarningText</Publish><发布对话框="WelcomeDlg" 控制="下一步"属性="WelcomeDlg_Next" 值="LicenseAgreementDlg"Order="3">NOT OSWarningText</Publish><发布对话框="WelcomeDlg" 控制="下一步"事件="NewDialog" 值="[WelcomeDlg_Next]"Order="4">WelcomeDlg_Next</Publish>

然后对许可协议返回"按钮执行等效操作:如果没有警告,它应该返回欢迎屏幕,否则返回警告屏幕.

I already block installation of our software on operating systems where it is known not to work like this:

<Condition Message="This software needs Windows XP or newer.">
   <![CDATA[VersionNT >= 501]]>
</Condition>

Now I would also like to display a non-blocking warning if the user tries to install the software on an operating system (VersionNT + Service Pack) that is not explicitly supported, even though it might work.

For example, we only explicitly support the latest service pack of each operating system.

How can I display such a warning?

解决方案

I tackled this problem in 3 parts:

  1. defining an OSWarningText property which is only set when a warning needs to be given
  2. authoring a custom warning screen
  3. Inserting the custom warning screen in the UI sequence if necessary

1. Defining an OSWarningText property

First, declare the property and give it the "unset" value by default:

  <Property Id="OSWarningText" Value="{}"/>

To construct the actual value of the property, set an intermediary property for each possible warning. Make sure the conditions for each warning do not overlap:

  <SetProperty Id="OSWarningText1" After="AppSearch"
     Value="Detected XP SP [ServicePackLevel]. SP3 or higher is recommended.">
     <![CDATA[(VersionNT = 501) AND NOT (ServicePackLevel >= 3)]]>
  </SetProperty>

  <SetProperty Id="OSWarningText2" After="SetOSWarningText1"
     Value="Detected Vista SP [ServicePackLevel]. SP2 or higher is recommended.">
     <![CDATA[(VersionNT = 600) AND NOT (ServicePackLevel >= 2)]]>
  </SetProperty>

Assuming the conditions don't overlap, we can safely condense the warnings in a single property like this:

  <SetProperty Id="OSWarningText" After="SetOSWarningText2"
     Value="[OSWarningText1][OSWarningText2]" />    

2. Authoring a custom warning screen.

This is similar to the example for adding a checkbox for the desktop shortcut. Copy one of the existing dialog definitions from the wix sources, e.g. InstallDirDlg.wxs and rename it to WarningDlg.wxs.

Set the dialog ID to Id="WarningDlg. Strip out the unnecessary controls and replace them by a warning image and our previously defined OSWarningText:

<Control Id="OSWarning" Type="Text" X="100" Y="80" Width="250" Height="60"
    NoPrefix="yes" Text="[OSWarningText]" />

<Control Id="WarningIcon" Type="Icon" X="20" Y="60" Width="64" Height="64"
   Text="Warning.ico" >
   <Binary Id="Warning.ico" SourceFile="..iconswarning.ico"/>
</Control>

The idea is to create something like this:

3. Inserting the custom warning screen in the UI sequence

Now we need to make sure that the warning screen is displayed between the welcome dialog and the license agreement dialog, but only if there actually is a warning to show. This is a special case of the more general branching wizard sequences problem.

Again, copy a predefined UI sequence from the wix sources, e.g. WixUI_InstallDir.wxs and rename the UI ID to Id="MyWixUI". Reference this in your main wxs file as <UIRef Id="MyWixUI" />. Now find and edit the event handlers for the WelcomeDlg next button.

You can set properties in response to a button press and an extra condition, and you can show the next dialog based on a property. We'll make use of that to handle the WelcomeDlg next button like this:

  1. reset the WelcomeDlg_Next property to "unset"
  2. set the WelcomeDlg_Next property to "WarningDlg" but only if OSWarningText is set
  3. set the WelcomeDlg_Next property to "LicenseAgreementDlg" but only if OSWarningText is NOT set.
  4. Show the dialog given by WelcomeDlg_Next, if the property was correctly set.

The Wix code to do that looks like this:

        <Publish Dialog="WelcomeDlg" Control="Next"
            Property="WelcomeDlg_Next" Value="{}"
            Order="1">1</Publish>
        <Publish Dialog="WelcomeDlg" Control="Next"
            Property="WelcomeDlg_Next" Value="WarningDlg"
            Order="2">OSWarningText</Publish>
        <Publish Dialog="WelcomeDlg" Control="Next"
            Property="WelcomeDlg_Next" Value="LicenseAgreementDlg"
            Order="3">NOT OSWarningText</Publish>
        <Publish Dialog="WelcomeDlg" Control="Next"
            Event="NewDialog" Value="[WelcomeDlg_Next]"
            Order="4">WelcomeDlg_Next</Publish>

Then do the equivalent for the License Agreement "back" button: it should go back to the welcome screen if there is no warning, or else to the warning screen.

这篇关于如何在 Wix 中显示操作系统的非阻塞警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆