在WiX工具集中,如何让用户修改从注册表读取的路径?

时间:2019-02-01 10:25:34

标签: wix

我的应用程序正在从目录(“ SITEDIR”)中读取数据库(称为“站点”)。在安装过程中,我希望安装程序读取注册表中先前版本设置的目录路径(如果存在),然后让用户修改该路径。

我的问题是我从注册表中读取的值会覆盖用户设置的值。

如何确保用户设置的值是安装程序将使用的值?

这是我的代码:

<!-- Set the USER_SITEDIR property to the default value before reading the value from the Registry, in case there is no previous version installed . -->
<Property Id="USER_SITEDIR" Value="C:\User Sites"/>

<!-- Read the Sites Directory from the registry. If the key doesn't exist, the property will be null. If the directory doesn't exist, the property will be set to C:\-->
<Property Id="REG_SITEDIR">
  <RegistrySearch Id="RegSearchSiteDir" Root="HKLM" Key="Software\$(var.Manufacturer)\$(var.ProductName)\$(var.PrevVersion)\Directories" Name="Site Directories" Type="directory" />          
</Property>

<!-- Set the SITEDIR directory to the value read from the registry, only if that value has been set -->
<SetProperty Id="USER_SITEDIR" After="AppSearch" Value="[REG_SITEDIR]">
  REG_SITEDIR
</SetProperty>

<!-- finally, set the directory's name to the one read from the Registry -->
<SetDirectory Id="SITEDIR" Value="[USER_SITEDIR]"/>


<!-- This is somewhat of a "dummy" feature. It's only here to let the users define the databases location-->
<Feature Id="Databases" Title ="Databases" Level="1" Absent="disallow" Description="Location of your databases" ConfigurableDirectory="SITEDIR"/>

示例:

SITEDIR的默认值为“ C:\ Sites”。 属性USER_SITEDIR的初始值为“ C:\ User Sites” 先前版本的“站点目录”键设置为“ C:\ Sites Old”。

在安装过程中,在CustomizeDlg对话框中,为“数据库”功能显示的文件夹为“ C:\ Sites Old”。 我单击“浏览...”,然后将文件夹更改为“ C:\ Sites New”。

我希望将站点复制到“ C:\ Sites New”,并且已安装版本的“ Directory”注册表项的值也应为“ C:\ Sites New”。

但是,实际结果是将文件复制到“ C:\ Sites Old”,并且注册表项也指向该路径。

如果没有以前安装的版本,则将文件复制到“ C:\ User Sites”(USER_SITES的值)。

1 个答案:

答案 0 :(得分:0)

好吧,我找到了答案。 不知道这是否是正确的方法,但是可以。

综观安装日志,我实现的价值被覆盖的原因是后CustomizeDlg对话框中的安装程序被调用“AppSearch”行动一次,它调用从注册表读取值并把它置SITEDIR一次

为防止出现这种情况,我添加了另一个名为“ SITEDIR_SET”的属性,并将其值设置为“ 1” 之后的行动“FileCost”。此外,我在代码设置SITEDIR中添加了条件“ NOT SITEDIR_SET”。 第一次调用setSITEDIR之后立即触发“ FileCost”,因此SITEDIR设置一次就可以了。

代码如下:

<Property Id="SITEDIR_SET" />

<!-- Read the Sites Directory from the registry. If the key or the directory don't exist, the property will not be set.-->
<Property Id="REG_SITEDIR">
  <RegistrySearch Id="RegSearchSiteDir" Root="HKLM" Key="Software\$(var.Manufacturer)\$(var.ProductName)\$(var.PrevVersion)\Directories" Name="Site Directories" Type="directory" />
</Property>

<!-- Set the SITEDIR directory to the value read from the registry, only if that value has been set -->
<SetProperty Id="USER_SITEDIR" After="AppSearch" Value="[REG_SITEDIR]" >
  REG_SITEDIR
</SetProperty>

<!-- finally, set the directory's name to the one read from the Registry if is hasn't already been set -->
<SetDirectory Id="SITEDIR" Value="[USER_SITEDIR]" >
  NOT SITEDIR_SET
</SetDirectory>

<!-- Flag used to stop WiX from resetting SITEDIR's value. The FileCost action happens right after setting SITEDIR for the first time -->
<SetProperty Id="SITEDIR_SET" After ="FileCost" Value="1" />