2

Rob Mensching 有一篇文章“记住属性模式”,它允许保护在命令行中指定的值不被 RegSearches 覆盖。在我们需要一些高级逻辑(例如默认值)之前,一切正常。

我扩展了该模式以使用自定义操作设置默认值(仍然可以正常工作):

<Fragment>
  <Property Id="MY_PROPERTY">
    <RegistrySearch Id="MyProperty_RegSearch" Root="HKLM" Key="SOFTWARE\MyCompanyName\MyApplicationName" Name="MyProperty" Type="raw"></RegistrySearch>
  </Property>

  <DirectoryRef Id="INSTALLDIR">
    <Component Id="PermanentRegistryValues" Guid="MY_GUID" Permanent="yes">
      <RegistryKey Root="HKLM" Key="SOFTWARE\MyCompanyName\MyApplicationName" Action="create">
        <RegistryValue Name="MyProperty" Type="string" Value="[MY_PROPERTY]" />
      </RegistryKey>
    </Component>
  </DirectoryRef>

  <CustomAction Id="SaveCmd_MyProperty" Property="cmd_MyProperty" Value="[MY_PROPERTY]" Execute="firstSequence" />
  <CustomAction Id="RestoreCmd_MyProperty" Property="MY_PROPERTY" Value="[cmd_MyProperty]" Execute="firstSequence" />
  <CustomAction Id="SetDefault_MyProperty" Property="MY_PROPERTY" Value="MyPropertyDefaultValue" Execute="firstSequence" />

  <InstallUISequence>
    <Custom Action="SaveCmd_MyProperty" Before="AppSearch" />
    <Custom Action="RestoreCmd_MyProperty" After="AppSearch">cmd_MyProperty</Custom>
    <Custom Action="SetDefault_MyProperty" Before="ValidateProductID">NOT MY_PROPERTY</Custom>
  </InstallUISequence>

  <InstallExecuteSequence>
    <Custom Action="SaveCmd_MyProperty" Before="AppSearch" />
    <Custom Action="RestoreCmd_MyProperty" After="AppSearch">cmd_MyProperty</Custom>
    <Custom Action="SetDefault_MyProperty" Before="ValidateProductID">NOT MY_PROPERTY</Custom>
  </InstallExecuteSequence>
</Fragment>

但这里有一个问题:

例如,如果我需要在 RadioButtonGroup 中使用 MyProperty,WIX(我认为它实际上是 MSI 限制)不允许声明此属性而没有像上面示例中设置的值。也无法设置一些虚拟值 - WIX 给出另一个编译错误:

error LGHT0204: ICE34: dummy is not a valid default value for the RadioButtonGroup using property MyProperty. The value must be listed as an option in the RadioButtonGroup table.

我还尝试向 RadiobuttonGroup 添加 'dummy' 选项,并将该选项放置在远远超出 RadioButtonGroup 控件边界的坐标 (1000;1000) 中。但缺点是使用键盘的用户可以选择该选项。此外,这绝对是一个不好的做法。

所以我的问题是: 如果我需要一组固定的允许值中的默认值,是否有可能以及如何实现记住属性模式?

这是我正在谈论的代码的其余部分(希望对您有所帮助):

<Property Id="MY_PROPERTY" Value="Value1">
  <RegistrySearch Id="MyProperty_RegSearch" Root="HKLM" Key="SOFTWARE\MyCompanyName\MyApplicationName" Name="MyProperty" Type="raw"></RegistrySearch>
</Property>

<Control Type="RadioButtonGroup" Property="MY_PROPERTY" Id="MyRbtn" Width="100" Height="159" X="34" Y="90">
  <RadioButtonGroup Property="MY_PROPERTY">
    <RadioButton Text="Value1" Value="Users" Width="100" Height="17" X="0" Y="0" />
    <RadioButton Text="Value2" Value="Roles" Width="100" Height="17" X="0" Y="45" />
  </RadioButtonGroup>
</Control>

PS:我在 Restore 和 SetDefault 自定义操作上尝试了许多条件组合,但它们都不适用于所有必需的情况:在 UI 模式/静默模式下安装、升级、更改/修复。

我没有看到任何简单的方法来克服这个问题。唯一的可能性是涉及一个更多的辅助属性并将自定义操作的数量加倍(对于单个属性来说,这已经是很多 (3) 了)。

4

0 回答 0