gpt4 book ai didi

wix - 如何在 Wix 中显示操作系统的非阻塞警告?

转载 作者:行者123 更新时间:2023-12-04 03:18:01 26 4
gpt4 key购买 nike

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

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

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

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

我怎样才能显示这样的警告?

最佳答案

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

  • 定义 OSWarningText 属性
    仅在警告时设置
    需要给
  • 创作自定义警告屏幕
  • 如有必要,在 UI 序列中插入自定义警告屏幕

  • 1. 定义 OSWarningText 属性

    首先,声明属性并默认给它“未设置”值:
      <Property Id="OSWarningText" Value="{}"/>

    要构造属性的实际值,请为每个可能的警告设置一个中间属性。确保每个警告的条件不重叠:
      <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>

    假设条件不重叠,我们可以安全地将警告压缩在一个属性中,如下所示:
      <SetProperty Id="OSWarningText" After="SetOSWarningText2"
    Value="[OSWarningText1][OSWarningText2]" />

    2. 创作自定义警告屏幕。

    这类似于 example for adding a checkbox for the desktop shortcut .从 wix sources 复制现有对话框定义之一,例如 InstallDirDlg.wxs并将其重命名为 WarningDlg.wxs .

    将对话 ID 设置为 Id="WarningDlg .去掉不必要的控件,并用警告图像和我们之前定义的 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="..\icons\warning.ico"/>
    </Control>

    这个想法是创建这样的东西:



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

    现在我们需要确保在欢迎对话框和许可协议(protocol)对话框之间显示警告屏幕,但前提是确实有警告要显示。这是更一般的 branching wizard sequences 的特例。问题。

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

    您可以设置属性以响应按钮按下和额外条件,并且可以基于属性显示下一个对话框。我们将使用它来处理 WelcomeDlg 的 next 按钮,如下所示:
  • 重置 WelcomeDlg_Next 属性
    为“取消设置”
  • 将 WelcomeDlg_Next 属性设置为
    “WarningDlg”,但前提是
    OSWarningText 已设置
  • 将 WelcomeDlg_Next 属性设置为
    “LicenseAgreementDlg”,但前提是
    未设置 OSWarningText。
  • 显示由给出的对话框
    WelcomeDlg_Next,如果属性是
    正确设置。

  • 执行此操作的 Wix 代码如下所示:
            <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>

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

    关于wix - 如何在 Wix 中显示操作系统的非阻塞警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1810910/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com