wix Condition patch

16 篇文章 0 订阅

1) 安装时用户权限的判断

使用MSI程序进行安装时,一般要进行用户权限的判断,可以使用内置的属性Privileged进行判断,也可以通过设置Package的相关属性进行判断。

Privileged属性

<Condition Message="!(loc.InstallWarning)">Privileged</Condition>
当用户不具备管理员权限时,安装停止并给出提示消息。

使用Package属性设置,一般来说有2中安装方式,面向用户和面向机器。
面向用户指的是所有用户下均进行安装,而不需要操作权限,即所有的用户均可安装、卸载。而面向机器指的是要求一定的管理员权限来安装或卸载程序。
Wix中的代码为:
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>
InstallScope
为perMachine时面向机器,为perUser时为面向用户。

2) patch更新方式实现

对于少量文件的更新,Wix提供了patch的方式进行更新,不需要对所有的安装源文件进行覆盖,仅仅选择更新后的文件进行安装。
具体流程为:

准备2分安装源文件,一份为原始的,一份为更新后的文件

分别对2分安装源文件进行build操作,得到不同的msi安装文件

使用torch.exe 和 pyro.exe 工具对2份msi文件进行分析,得到两者之间的不同,整理出patch安装文件
实例:
Product.wxs
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="
http://schemas.microsoft.com/wix/2006/wi">
<Product Id="48C49ACE-90CF-4161-9C6E-9162115A54DD"
Name="WiX Patch Example Product"
Language="1033"
Version="1.0.0"
Manufacturer="Dynamo Corporation"
UpgradeCode="48C49ACE-90CF-4161-9C6E-9162115A54DD">
<Package Description="Installs a file that will be patched."
Comments="This Product does not install any executables"
InstallerVersion="200"
Compressed="yes" />

<Media Id="1" Cabinet="product.cab" EmbedCab="yes" />
<FeatureRef Id="SampleProductFeature"/>
</Product>

<Fragment>
<Feature Id="SampleProductFeature" Title="Sample Product Feature" Level="1">
<ComponentRef Id="SampleComponent" />
</Feature>
</Fragment>

<Fragment>
<DirectoryRef Id="SampleProductFolder">
<Component Id="SampleComponent" Guid="{C28843DA-EF08-41CC-BA75-D2B99D8A1983}" DiskId="1">
<File Id="SampleFile" Name="Sample.txt" Source="./$(var.Version)/Sample.txt" />
</Component>
</DirectoryRef>
</Fragment>

<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="SampleProductFolder" Name="Patch Sample Directory">
</Directory>
</Directory>
</Directory>
</Fragment>
</Wix>

Patch.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="
http://schemas.microsoft.com/wix/2006/wi">
<Patch
AllowRemoval="yes"
Manufacturer="Dynamo Corp"
MoreInfoURL="
http://www.dynamocorp.com/"
DisplayName="Sample Patch"
Description="Small Update Patch"
Classification="Update"
>

<Media Id="5000" Cabinet="RTM.cab">
<PatchBaseline Id="RTM"/>
</Media>

<PatchFamilyRef Id="SamplePatchFamily"/>
</Patch>

<Fragment>
<PatchFamily Id='SamplePatchFamily' Version='1.0.0.0' Supersede='yes'>
<ComponentRef Id="SampleComponent"/>
</PatchFamily>
</Fragment>
</Wix>

cmd
命令依次为:
candle.exe -dVersion=1.0 product.wxs
light.exe product.wixobj -out 1.0/product.msi
candle.exe -dVersion=1.1 product.wxs
light.exe product.wixobj -out 1.1/product.msi
torch.exe -p -xi 1.0/product.wixpdb 1.1/product.wixpdb -out patch/diff.wixmst
candle.exe patch.wxs
light.exe patch.wixobj -out patch/patch.wixmsp
pyro.exe patch/patch.wixmsp -out patch/patch.msp -t RTM patch/diff.wixmst
最后得到的msp文件即为patch更新文件。

3) 安装程序版本控制问题

在安装程序更新时,假如product的id没有改变,则表明该安装程序不允许多个版本共存。
一般msi程序更新时,都需要用到UpGradeCode,这个属性是安装程序更新唯一标示。

4) 序列号验证机制的加入

<Control Id="CDKeyNumber" Type="Edit" X="55" Y="80" Width="200" Height="15" Property="CDKEY"/>

<Control Id="CDKeyErrorInfo" Type="Text" X="55" Y="100" Width="200" Height="15" Hidden="yes" Text="!(loc.CDKeyError)">

<Condition Action="show"><![CDATA[CDKEY <> "123" AND CDKEYCHECK = "yes"]]></Condition>

</Control>

自定义一个安装对话框,然后使用type为text的control控件,采用一个公用属性 CDKEY 获得用户输入的CDKey,然后定义一个CustomAction,对CDKey进行判断即可。此处将CDKey限定为123。

更多用户信息要求的对话框:

<Fragment>

<UI>

<Dialog Id="UserRegistrationDlg" Width="370" Height="270" Title="[ProductName] [Setup]" NoMinimize="yes">

<Control Id="NameLabel" Type="Text" X="45" Y="73" Width="100" Height="15" TabSkip="no" Text="&UserName:" />"

<Control Id="NameEdit" Type="Edit" X="45" Y="85" Width="220" Height="18" Property="USERNAME" Text="{80}" />

<Control Id="OrganizationLabel" Type="Text" X="45" Y="110" Width="100" Height="15" TabSkip="no" Text="&Organization:" />"

<Control Id="OrganizationEdit" Type="Edit" X="45" Y="122" Width="220" Height="18" Property="COMPANYNAME" Text="{80}" />

<Control Id="CDKeyLabel" Type="Text" X="45" Y="147" Width="50" Height="10" TabSkip="no">

<Text>CD &Key:</Text>

</Control>

<Control Id="CDKeyEdit" Type="MaskedEdit" X="45" Y="159" Width="250" Height="16" Property="PIDKEY" Text="[PIDTemplate]" />

<Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&Back">

<Publish Event="NewDialog" Value="[WixUI_UserRegistrationDlgBack]">1</Publish>

</Control>

<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&Next">

<Publish Event="ValidateProductID" Value="0">1</Publish>

<Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">CostingComplete = 1</Publish>

<Publish Event="NewDialog" Value="[WixUI_UserRegistrationDlgNext]">ProductID</Publish>

</Control>

<Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">

<Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>

</Control>

<Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" />

<Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes">

<Text>Please enter your customer information</Text>

</Control>

<Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />

<Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes">

<Text>{/WixUI_Font_Title}Customer Information</Text>

</Control>

<Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />

</Dialog>

</UI>

</Fragment>

(选自WIx tutorial)

5) 如何给本机所有用户安装桌面快捷方式和开始菜单项

<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"/>

InstallScope 设置为 perMachine 即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值