Wix使用整理(四)

 

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 工具對2msi文件進行分析,得到兩者之間的不同,整理出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)         安裝程序版本控制問題

在安裝程序更新時,假如productid沒有改變,則表明該安裝程序不允許多個版本共存。
一般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>     

自定義一個安裝對話框,然後使用typetextcontrol控件,採用一個公用屬性 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 即可。

 

發佈了29 篇原創文章 · 獲贊 3 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章