在 Wix 中满足条件时显示警告对话框

Display the warning dialog when a condition is satisfied in Wix

在我的 Wix 安装程序中,我正在搜索 Adob​​e acrobat reader 的注册表项并显示带有“是”和“否”选项的警告对话框。如果未安装 Adob​​e reader,WelcomeDlg 允许用户“继续”或“退出”安装,此对话框应在安装序列期间立即显示。

我在我的代码中发现一个问题,因为“AdobePrerequisiteDlg”不支持“ADOBEREADERINSTALLED”属性,即使注册表项存在,该对话框也会显示。

警告对话框“AdobePrerequisiteDlg”仅应在 属性“ADOBEREADERINSTALLED”不满足时显示(即注册表项不存在), 但到目前为止,这还没有发生,因为我每次都能看到对话框显示。

我尝试了很多更改,但无法找出问题所在。这是我的代码:

Product.wxs

<Property Id="ADOBEREADERINSTALLED">
  <RegistrySearch Id="ADOBEREADERINSTALLED_REGSEARCH" Key="Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe" Root="HKLM" Type="raw"/> 
</Property>

<UIRef Id="PrerequisiteDialogUI" />
 <UI Id="UserInterface">     
      <DialogRef Id="ProgressDlg" />     
      <DialogRef Id="ErrorDlg" />
      <DialogRef Id="FilesInUse" />
      <DialogRef Id="FatalError" />
      <DialogRef Id="UserExit" />

  <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
  <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="AdobePrerequisiteDlg">1</Publish>     
 </UI>  

Components.wxs

<Fragment>
 <UI Id="PrerequisiteDialogUI">         
      <Dialog Id="AdobePrerequisiteDlg" Width="370" Height="270" Title="Software Requirements Incomplete">       
        <Control Id="YES" Type="PushButton"  X="180" Y="243" Width="56" Height="17" Default="yes"  Cancel="yes" Text="YES">
          <Publish Event="EndDialog" Value="Return">1</Publish>
        </Control>
        <Control Id="NO" Type="PushButton" Text="NO"  X="236" Y="243" Width="56" Height="17" Cancel="yes" >
          <Publish Event="EndDialog" Value="Exit" />
        </Control>
        <Control Id="Text" Type="Text" X="1" Y="50" Width="340" Height="120" TabSkip="no">
          <Text>
           The following software requirements have not been met :
            
           Adobe Acrobat Reader                                      
           Do you wish to continue ?

          </Text>
        </Control>
        <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Prerequisite for $(var.ProductName) is not installed." />
        <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="Adobe Reader 9.0" />
        <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)" />
        <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
        <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />     
      </Dialog>      
    </UI>          
    <InstallUISequence>
      <Show Dialog="AdobePrerequisiteDlg" Before="ExecuteAction"> <![CDATA[NOT Installed AND ADOBEREADERINSTALLED]]></Show>     
    </InstallUISequence>
<Fragment> 

首先,您需要括号或双 NOT 条件:NOT (Installed AND ADOBEREADERINSTALLED) OR NOT Installed AND NOT ADOBEREADERINSTALLED

然后。启动安装程序时是否看到 WelcomeDialog?还是 Adob​​ePrerequisiteDlg 先行?如果是第二个变体,您需要对代码进行一些更改。试试这个:

  1. 在自定义 UI 中添加对自定义对话框的引用。
  2. UIRef 应指向自定义 UI,而不是描述自定义对话框的 UI。
  3. 在您的自定义 UI 中描述对话的所有变体和步骤。 (见下面的例子)
  4. 条件语句应该放在 Publish 元素中。
  5. 安装UI不需要序列。

Product.wxs

<Fragment>
    <Property Id="ADOBEREADERINSTALLED">
      <RegistrySearch Id="ADOBEREADERINSTALLED_REGSEARCH" Key="Software\Microsoft\Windows\CurrentVersion\App Paths\Acrobat.exe" Root="HKLM" Type="raw"/>
    </Property>
  </Fragment>
  <Fragment>
    <UIRef Id="UserInterface" />
  </Fragment>
  <Fragment>
    <UI Id="UserInterface">
      <DialogRef Id="ProgressDlg" />
      <DialogRef Id="ErrorDlg" />
      <DialogRef Id="FilesInUse" />
      <DialogRef Id="FatalError" />
      <DialogRef Id="UserExit" />
      <DialogRef Id="AdobePrerequisiteDlg"/>

      <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>
      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="AdobePrerequisiteDlg">NOT ADOBEREADERINSTALLED</Publish>
      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="Put_Next_Dialog_Id_Here">ADOBEREADERINSTALLED</Publish>

      <Publish Dialog="AdobePrerequisiteDlg" Control="YES" Event="NewDialog" Value="Put_Next_Dialog_Id_Here"/>
      <Publish Dialog="AdobePrerequisiteDlg" Control="NO" Event="NewDialog" Value="UserExit"/>
    </UI>
  </Fragment>

Components.wxs

 <Fragment>
    <UI Id="PrerequisiteDialogUI">
      <Dialog Id="AdobePrerequisiteDlg" Width="370" Height="270" Title="Software Requirements Incomplete">
        <Control Id="YES" Type="PushButton"  X="180" Y="243" Width="56" Height="17" Default="yes"  Cancel="yes" Text="YES"/>
        <Control Id="NO" Type="PushButton" Text="NO"  X="236" Y="243" Width="56" Height="17" Cancel="yes" />
        <Control Id="Text" Type="Text" X="1" Y="50" Width="340" Height="120" TabSkip="no">
          <Text>
            The following software requirements have not been met :

            Adobe Acrobat Reader
            Do you wish to continue ?

          </Text>
        </Control>
        <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes" Text="Prerequisite for $(var.ProductName) is not installed." />
        <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="Adobe Reader 9.0" />
        <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.InstallDirDlgBannerBitmap)" />
        <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
        <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
      </Dialog>
    </UI>
  </Fragment>