Wix 安裝部署教程(三)自定義安裝界面和行為


         接上一篇自定義安裝界面,這篇繼續探索,首先介紹下,Wix為我們定義了五種風格,每種風格的UI都是有一定順序的。我們可以改變安裝順序,也可以完全自定義一個Dialog插入其中。比如Wix_Mondo 風格的順序就如下,但不一定每個dialog會在安裝的時候展示。

BrowseDlg 
CustomizeDlg 
DiskCostDlg 
LicenseAgreementDlg 
SetupTypeDlg 
WelcomeDlg 
In addition, WixUI_Mondo includes the following common dialogs that appear in all WixUI dialog sets:

CancelDlg 
ErrorDlg 
ExitDlg 
FatalError 
FilesInUse 
MaintenanceTypeDlg 
MaintenanceWelcomeDlg 
MsiRMFilesInUse 
OutOfDiskDlg 
OutOfRbDiskDlg 
PrepareDlg 
ProgressDlg 
ResumeDlg 
UserExit 
VerifyReadyDlg 
WaitForCostingDlg 
View Code

 五、改變UI界面的安裝順序

      要做到這一步,需要借助Wix的源碼了,源碼下載:http://wix.codeplex.com/SourceControl/latest 。這里我選的界面風格是 WixUI_Mondo,源碼不用全部打開,直接搜WixUI_Mondo.wxs,找到后直接丟到VS中就可以了。我們試着把展示許可證書的這一步跳過,這需要三步:

      1)將源碼中Fragment中的內容全部copy到Product 元素中 一個ui和一個uiref元素

      2)刪除兩個與LicenseAgreementDlg 相關的Publish 元素,pubulish元素定義了頁面了上一步,下一步這些操作。Event="NewDialog" 表示打開一個對話框,value就表示,需要打開的對話框Id。

      3)然后同理改變WelcomeDlg和下一步和SetupTypeDlg的上一步 相互在value中指向彼此。  

      4)  這個時候出現了兩個Id="WixUI_Mondo ,將之前UI中的<UIRef Id="WixUI_Mondo" /> 注釋掉就可以了。 

      再次安裝,就不再出現許可證書頁面了。

    全部的代碼如下,我們也可以留意下源碼中publish元素中的text 其實就是個條件表達式,1就是執行,還有or。 NOT Installed AND NOT PATCH表示沒有安裝也沒有打補丁。 等等

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="!(loc.ApplicationName)"
 Language="1033" Version="1.0.0.0" Manufacturer="RJStone" UpgradeCode="3486eddf-0957-45cf-8c26-3de8bceca2b4">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />

    <Feature Id="ProductFeature" Title="Setup07" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>

    <UI>
      <!--<UIRef Id="WixUI_Mondo" />-->
      <Publish Dialog="ExitDialog"
      Control="Finish"
      Event="DoAction"
      Value="LaunchApplication">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
    </UI>

    <WixVariable Id="WixUILicenseRtf" Value="lisences.rtf" />
    <WixVariable Id="WixUIDialogBmp" Value="bb.jpg"/>
    <WixVariable Id="WixUIBannerBmp" Value="top.jpg"/>

    <Property Id="WIXUI_EXITDIALOGOPTIONALTEXT" Value="Thank you for installing this product." />
    <Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Launch this Application " />

    <Property Id="WixShellExecTarget" Value="[#myapplication.exe]" />
    <CustomAction Id="LaunchApplication" BinaryKey="WixCA" DllEntry="WixShellExec" Impersonate="yes" />
    
  <UI Id="WixUI_Mondo">
    
      <TextStyle Id="WixUI_Font_Normal" FaceName="Tahoma" Size="8" />
      <TextStyle Id="WixUI_Font_Bigger" FaceName="Tahoma" Size="12" />
      <TextStyle Id="WixUI_Font_Title" FaceName="Tahoma" Size="9" Bold="yes" />

      <Property Id="DefaultUIFont" Value="WixUI_Font_Normal" />
      <Property Id="WixUI_Mode" Value="Mondo" />
      <DialogRef Id="ErrorDlg" />
      <DialogRef Id="FatalError" />
      <DialogRef Id="FilesInUse" />
      <DialogRef Id="MsiRMFilesInUse" />
      <DialogRef Id="PrepareDlg" />
      <DialogRef Id="ProgressDlg" />
      <DialogRef Id="ResumeDlg" />
      <DialogRef Id="UserExit" />

      <Publish Dialog="ExitDialog" Control="Finish" Event="EndDialog" Value="Return" Order="999">1</Publish>

      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="SetupTypeDlg">NOT Installed AND NOT PATCH</Publish>
      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish>

      <!--<Publish Dialog="LicenseAgreementDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
            <Publish Dialog="LicenseAgreementDlg" Control="Next" Event="NewDialog" Value="SetupTypeDlg" Order="2">LicenseAccepted = "1"</Publish>-->

      <Publish Dialog="SetupTypeDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
      <Publish Dialog="SetupTypeDlg" Control="TypicalButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
      <Publish Dialog="SetupTypeDlg" Control="CustomButton" Event="NewDialog" Value="CustomizeDlg">1</Publish>
      <Publish Dialog="SetupTypeDlg" Control="CompleteButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>

      <Publish Dialog="CustomizeDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="1">WixUI_InstallMode = "Change"</Publish>
      <Publish Dialog="CustomizeDlg" Control="Back" Event="NewDialog" Value="SetupTypeDlg" Order="2">WixUI_InstallMode = "InstallCustom"</Publish>
      <Publish Dialog="CustomizeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>

      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="CustomizeDlg" Order="1">WixUI_InstallMode = "InstallCustom"</Publish>
      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="SetupTypeDlg" Order="2">WixUI_InstallMode = "InstallTypical" OR WixUI_InstallMode = "InstallComplete"</Publish>
      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="CustomizeDlg" Order="3">WixUI_InstallMode = "Change"</Publish>
      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="4">WixUI_InstallMode = "Repair" OR WixUI_InstallMode = "Remove"</Publish>
      <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">WixUI_InstallMode = "Update"</Publish>

      <Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>

      <Publish Dialog="MaintenanceTypeDlg" Control="ChangeButton" Event="NewDialog" Value="CustomizeDlg">1</Publish>
      <Publish Dialog="MaintenanceTypeDlg" Control="RepairButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
      <Publish Dialog="MaintenanceTypeDlg" Control="RemoveButton" Event="NewDialog" Value="VerifyReadyDlg">1</Publish>
      <Publish Dialog="MaintenanceTypeDlg" Control="Back" Event="NewDialog" Value="MaintenanceWelcomeDlg">1</Publish>
    </UI>

    <UIRef Id="WixUI_Common" />

  </Product>
   
  
  
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="Setup07" />
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
      <!-- <Component Id="ProductComponent"> -->
      <!-- TODO: Insert files, registry keys, and other resources here. -->
      <Component Id="ProductComponent">
        <File Id="myapplication.exe"  Source="$(var.MyApplication.TargetPath)" />
      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>
View Code

六、自定義Dialog 

    自定義界面,需要借助源碼了,這一節,也可以參考 子林的博客 http://blog.csdn.net/duanzilin/article/details/5956727  

    在找到WixUI_Mondo.wxs 的源碼文件夾中,隨便找一個名字中有Dlg的wxs文件,丟到vs中就可以看見一個Dlg 是個什么樣的結構。 比如LicenseAgreementDlg.wxs 的源碼如下

<?xml version="1.0" encoding="UTF-8"?>
<!--
  <copyright file="LicenseAgreementDlg.wxs" company="Outercurve Foundation">
    Copyright (c) 2004, Outercurve Foundation.
    This software is released under Microsoft Reciprocal License (MS-RL).
    The license and further copyright text can be found in the file
    LICENSE.TXT at the root directory of the distribution.
  </copyright>
-->
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Fragment>
        <UI>
            <Dialog Id="LicenseAgreementDlg" Width="370" Height="270" Title="!(loc.LicenseAgreementDlg_Title)">
                <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.LicenseAgreementDlgBannerBitmap)" />
                <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
                <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
                <Control Id="Description" Type="Text" X="25" Y="23" Width="340" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.LicenseAgreementDlgDescription)" />
                <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.LicenseAgreementDlgTitle)" />
                <Control Id="LicenseAcceptedCheckBox" Type="CheckBox" X="20" Y="207" Width="330" Height="18" CheckBoxValue="1" Property="LicenseAccepted" Text="!(loc.LicenseAgreementDlgLicenseAcceptedCheckBox)" />
                <Control Id="Print" Type="PushButton" X="112" Y="243" Width="56" Height="17" Text="!(loc.WixUIPrint)">
                    <Publish Event="DoAction" Value="WixUIPrintEula">1</Publish>
                </Control>
                <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
                <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)">
                    <Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">!(wix.WixUICostingPopupOptOut) OR CostingComplete = 1</Publish>
                    <Condition Action="disable"><![CDATA[LicenseAccepted <> "1"]]></Condition>
                    <Condition Action="enable">LicenseAccepted = "1"</Condition>
                </Control>
                <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="!(loc.WixUICancel)">
                    <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
                </Control>
                <Control Id="LicenseText" Type="ScrollableText" X="20" Y="60" Width="330" Height="140" Sunken="yes" TabSkip="no">
                    <Text SourceFile="!(wix.WixUILicenseRtf=$(var.licenseRtf))" />
                </Control>
            </Dialog>
        </UI>
    </Fragment>
</Wix>
View Code

  Control 是個主要的元素,相當於vs中的控件了。但這里是個統稱,通過Type也決定這個是一個lable 還是個text(edit) type的類型有  Billboard, Bitmap, CheckBox, ComboBox, DirectoryCombo,  DirectoryList, Edit, GroupBox, Hyperlink, Icon, Line, ListBox, ListView, MaskedEdit, PathEdit, ProgressBar, PushButton, RadioButtonGroup, ScrollableText, SelectionTree, Text,   VolumeCostList, VolumeSelectCombo  , 需要定義類型,位置,大小,文本。

     自定義一個頁面插入進去,需要兩步。

    1.先新建一個wxs文件,右鍵 添加 新建項 選擇Installer File 。命名為SpecialDlg 修改為

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <UI>
      <Dialog Id="SpecialDlg" Width="370" Height="270" Title="this is a special dialog made by rjstone ">
        <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="!(loc.LicenseAgreementDlgBannerBitmap)" />
        <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
        <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
        <Control Id="Description" Type="Text" X="25" Y="23" Width="340" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.LicenseAgreementDlgDescription)" />
        <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes" Text="!(loc.LicenseAgreementDlgTitle)" />
        <Control Id="MyLabel" Width="40" Height="40" Type="Text" X="30" Y="63" Text="Soga" />      
        <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="!(loc.WixUIBack)" />
        <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)"/>        
      </Dialog>
    </UI>
  </Fragment>   
</Wix>

   這就是個簡單的對話框,因為不像html或者wpf 那么直觀,這個看起來確實有點不“形象”   ,生成就是如下的樣子。  我們可以看line text title 各自對應的地方

  

  千萬不要少了 下面的兩個按鈕,不然安裝到這就傻眼了。 這只是個簡單的頁面,但我們如何加入到安裝目錄中呢,需要第二步 

  2. 插入到安裝順序中,我們先把之前的UI順序復原,把LicenseAgreementDlg 還原在WelcomeDlg后面,再在這兩者之間插入上面的SpecialDlg 。修改Product中的publish元素 

      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="SpecialDlg">NOT Installed AND NOT PATCH</Publish>
      <Publish Dialog="WelcomeDlg" Control="Next" Event="NewDialog" Value="VerifyReadyDlg">Installed AND PATCH</Publish> 
      <Publish Dialog="SpecialDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg">1</Publish>
      <Publish Dialog="SpecialDlg" Control="Next" Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
      <Publish Dialog="LicenseAgreementDlg" Control="Back" Event="NewDialog" Value="SpecialDlg">1</Publish>
      <Publish Dialog="LicenseAgreementDlg" Control="Next" Event="NewDialog" Value="SetupTypeDlg" Order="2">LicenseAccepted = "1"</Publish>

  當然,需要復雜的界面,還需要加入自定義的行為,比如讓用戶輸入再檢測,並調用dll中的方法,這寫wix都是可以做到的。

 今天關於自定義界面的就到這里,明天繼續。

 

 如過你覺得對你有幫助,就頂一個吧。

   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM