打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Wix使用整理(3)
userphoto

2023.04.24 加拿大

关注

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 即可。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(二)
基于Flex2的WYSIWYG编辑器设想
Fragment构建程序的框架
Fragment(碎片)
团队冲刺--第一阶段(二)
Android学习之——Fragment随堂笔记(一)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服