gpt4 book ai didi

xml - 收集用于 PerUser 安装程序的文件

转载 作者:数据小太阳 更新时间:2023-10-29 02:11:59 26 4
gpt4 key购买 nike

我有一个安装程序需要明确是一个 PerUser msi。当前的问题是使用 Heat 获取文件并没有提供一种方法来生成完全符合 PerUser 包的组件。特别是 ICE64“目录 dir7956CF617C38D877C93B5A7D33313596 在用户配置文件中,但未在 RemoveFile 表中列出。

现在,只要我知道结构,这就不是问题,因为我可以创建一个包含所有目录的组件并将其包含在功能中。但是,如果结构发生变化,则需要手动查找所有目录并手动添加它们。这消除了其他开发人员自由添加/删除文件的灵 active 。

对于那些感兴趣的人,这里是我使用的热命令:heat.exe dir "SourceDir"-dr INSTALLDIR -cg CG_Binaries -nologo -gg -g1 -sfrag -srd -svb6 -scom -sreg -var "var.Binaries"-out "Binaries.wxs"'/>

这是 heat.exe 未经任何转换生成的原始 XML:

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLDIR">
<Directory Id="dir7956CF617C38D877C93B5A7D33313596" Name="Folder1">
<Component Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" Guid="CBB5AF6A-D0A2-464D-BFAA-49F9C102A4F4">
<File Id="filB5C5E94E5D59CC7DB489F6823F341316" KeyPath="yes" Source="$(var.Binaries)\Folder1\NewTextFile0.txt" />
</Component>
</Directory>
<Directory Id="dir2BA1778353CDCC6DE102110034297AC9" Name="Folder2">
<Component Id="cmp55726990D3629FC63F840780B5BC7729" Guid="49CAB541-CEB5-423B-89E2-A42D51AD9E7E">
<File Id="fil98449FB9E91E1F95E2BA0E6AD712D2E6" KeyPath="yes" Source="$(var.Binaries)\Folder2\NewTextFile1.txt" />
</Component>
<Directory Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Name="Folder3">
<Component Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" Guid="B495A9DB-3449-45CC-9197-6FD9C8C29C72">
<File Id="filB96F911B8B2DE84CED663406AD87D508" KeyPath="yes" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile4.txt" />
</Component>
<Component Id="cmp873EC3B1583A11ED180C2B5A55082E5E" Guid="B9C57A66-DF0A-480D-83E6-C8E7624974BD">
<File Id="fil48004A44BAD8605014735C6A3D6F7004" KeyPath="yes" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile5.txt" />
</Component>
<Component Id="cmp1614194F7F0694F7AC043F7778BA8109" Guid="B9807535-AC38-41B3-AD9E-A5EB58AC6E12">
<File Id="filF11AF0F827CF7E0D02F918F3FD7502AC" KeyPath="yes" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile6.txt" />
</Component>
</Directory>
</Directory>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="CG_Binaries">
<ComponentRef Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" />
<ComponentRef Id="cmp55726990D3629FC63F840780B5BC7729" />
<ComponentRef Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" />
<ComponentRef Id="cmp873EC3B1583A11ED180C2B5A55082E5E" />
<ComponentRef Id="cmp1614194F7F0694F7AC043F7778BA8109" />
</ComponentGroup>
</Fragment>
</Wix>

我有一个 XSL 将 File 的 KeyPath 属性更改为 no 以符合 ICE38 并添加 RegistryValue 以修复没有为 File 设置 KeyPaths 时的错误。

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
xmlns="http://schemas.microsoft.com/wix/2006/wi"
exclude-result-prefixes="xsl wix">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

<xsl:strip-space elements="*" />

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>

<!--File keypath to no and add registry keypath-->
<xsl:template match="wix:Component/wix:File[@Id]">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:attribute name="KeyPath">
<xsl:text>no</xsl:text>
</xsl:attribute>
</xsl:copy>
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</xsl:template>

<xsl:template match="wix:Component/wix:File[not(@Id)]">
<xsl:copy>
<xsl:apply-templates select="@*" />
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

这是期望的输出

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLDIR">
<Component Id="SomeName" Guid="A99D16EF-80A3-4C98-A91D-3E95C7BD98AE">
<RemoveFolder Id="dir7956CF617C38D877C93B5A7D33313596" Directory="dir7956CF617C38D877C93B5A7D33313596" On="uninstall" />
<RemoveFolder Id="dir2BA1778353CDCC6DE102110034297AC9" Directory="dir2BA1778353CDCC6DE102110034297AC9" On="uninstall"/>
<RemoveFolder Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Directory="dir52EB3739C4D4F7DFB9D67E41E7687374" On="uninstall"/>
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
<Directory Id="dir7956CF617C38D877C93B5A7D33313596" Name="Folder1">
<Component Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" Guid="CBB5AF6A-D0A2-464D-BFAA-49F9C102A4F4">
<File Id="filB5C5E94E5D59CC7DB489F6823F341316" KeyPath="no" Source="$(var.Binaries)\Folder1\NewTextFile0.txt" />
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Directory>
<Directory Id="dir2BA1778353CDCC6DE102110034297AC9" Name="Folder2">
<Component Id="cmp55726990D3629FC63F840780B5BC7729" Guid="49CAB541-CEB5-423B-89E2-A42D51AD9E7E">
<File Id="fil98449FB9E91E1F95E2BA0E6AD712D2E6" KeyPath="no" Source="$(var.Binaries)\Folder2\NewTextFile1.txt" />
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
<Directory Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Name="Folder3">
<Component Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" Guid="B495A9DB-3449-45CC-9197-6FD9C8C29C72">
<File Id="filB96F911B8B2DE84CED663406AD87D508" KeyPath="no" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile4.txt" />
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
<Component Id="cmp873EC3B1583A11ED180C2B5A55082E5E" Guid="B9C57A66-DF0A-480D-83E6-C8E7624974BD">
<File Id="fil48004A44BAD8605014735C6A3D6F7004" KeyPath="no" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile5.txt" />
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
<Component Id="cmp1614194F7F0694F7AC043F7778BA8109" Guid="B9807535-AC38-41B3-AD9E-A5EB58AC6E12">
<File Id="filF11AF0F827CF7E0D02F918F3FD7502AC" KeyPath="no" Source="$(var.Binaries)\Folder2\Folder3\NewTextFile6.txt" />
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
</Directory>
</Directory>
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="CG_Binaries">
<ComponentRef Id="SomeName"/>
<ComponentRef Id="cmp1CBAE345A14FB4F0343E1FC307F5EE1D" />
<ComponentRef Id="cmp55726990D3629FC63F840780B5BC7729" />
<ComponentRef Id="cmpEC9C0276E68BB6794098A24DCF44E0BD" />
<ComponentRef Id="cmp873EC3B1583A11ED180C2B5A55082E5E" />
<ComponentRef Id="cmp1614194F7F0694F7AC043F7778BA8109" />
</ComponentGroup>
</Fragment>
</Wix>

所以我想要实现的是让转换器循环遍历 xml,找到目录元素的所有 ID 并创建一个新元素,如下所示:

<Component Id="SomeName" Guid="A99D16EF-80A3-4C98-A91D-3E95C7BD98AE">
<RemoveFolder Id="dir7956CF617C38D877C93B5A7D33313596" Directory="dir7956CF617C38D877C93B5A7D33313596" On="uninstall" />
<RemoveFolder Id="dir2BA1778353CDCC6DE102110034297AC9" Directory="dir2BA1778353CDCC6DE102110034297AC9" On="uninstall"/>
<RemoveFolder Id="dir52EB3739C4D4F7DFB9D67E41E7687374" Directory="dir52EB3739C4D4F7DFB9D67E41E7687374" On="uninstall"/>
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>

我做了一些尝试来实现这一目标,但惨遭失败。我们将不胜感激。

最佳答案

从您所期望的外观来看,您需要做的就是一个包含 DirectoryRef 元素的模板...

<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR']">

然后您可以使用 xsl:for-each 构造选择所有 Directory 元素

<xsl:for-each select=".//wix:Directory[wix:Component/wix:File[@Id]]">
<RemoveFolder Id="{@Id}" Directory="{@Id}" On="uninstall" />
</xsl:for-each>

试试这个 XSLT(我硬编码了 Guid 属性,因为您需要为此使用某种扩展函数)

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
xmlns="http://schemas.microsoft.com/wix/2006/wi"
exclude-result-prefixes="xsl wix">

<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />

<xsl:strip-space elements="*" />

<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="wix:DirectoryRef[@Id='INSTALLDIR']">
<xsl:copy>
<xsl:apply-templates select="@*" />
<Component Id="SomeName" Guid="A99D16EF-80A3-4C98-A91D-3E95C7BD98AE">
<xsl:for-each select=".//wix:Directory[wix:Component/wix:File[@Id]]">
<RemoveFolder Id="{@Id}" Directory="{@Id}" On="uninstall" />
</xsl:for-each>
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</Component>
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>

<!--File keypath to no and add registry keypath-->
<xsl:template match="wix:Component/wix:File[@Id]">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:attribute name="KeyPath">
<xsl:text>no</xsl:text>
</xsl:attribute>
</xsl:copy>
<RegistryValue Root="HKCU" Key="!(wix.RegKeyLocation)" Name="installed" Type="integer" Value="1" KeyPath="yes" />
</xsl:template>
</xsl:stylesheet>

关于xml - 收集用于 PerUser 安装程序的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35848336/

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