wix 操作 ini 文本 文件

What we can do with the Ini file 

//z 2012-08-21 17:35:55 IS2120@CSDN.T2347462763[T12,L1149,R8,V93]
These are the options we have when we add/delete value:

  • Create a new entry or update it if entry already exist.
  • Create a new entry if it does not exist.
  • Remove entry.
  • Create a new entry or append a tag if entry already exist.
  • Remove a tag from the entry.  If entry becomes empty, it will be removed.

Also, keep in mind that if you delete a last entry in the .ini file, file will be deleted.

How it translates to WiX?

To create/delete entries:

IniFile/Action RemoveIniFile/
Action
<IniFile> attribute Description
msidbIniFileActionAddLine (0)   Action="addLine" Create or update an .ini entry.
msidbIniFileActionCreateLine (1)   Action="createLine" Create an .ini entry if entry does not exist.
msidbIniFileActionAddTag (3)   Action="addTag" Creates a new entry or appends value to existing entry.
  msidbIniFileActionRemoveLine (2) Action="removeLine" Removes an entry.
  msidbIniFileActionRemoveTag (4) Action="removeTag" Removes a tag from an entry.  If entry's value becomes empty, entry is removed.

Examples

  • Create a new entry if it does not exist: 

     <IniFileId="Ini1"

              Action="createLine"

              Directory="INSTALLLOCATION"

              Section="Test"

              Name="Minimal.ini"

              Key="TestKey"

              Value="TestValue" />

 Creates this:

[Test]

TestKey=TestValue

  • Add a tag to already existing entry:

     <IniFileId="Ini1"

              Action="addTag"

              Directory="INSTALLLOCATION"

              Section="Test"

              Name="Minimal.ini"

              Key="TestKey"

              Value="TestValue2" />

Creates this:

[Test]

TestKey=TestValue,TestValue2

  • Remove a tag:

     <IniFileId="Ini1"

              Action="removeTag"

              Directory="INSTALLLOCATION"

              Section="Test"

              Name="Minimal.ini"

              Key="TestKey"

              Value="TestValue" />

Creates this:

[Test]

TestKey=TestValue2

Here is the sample which installs ini file both in the installation folder and Windows folder.  Code for this sample is attached.

<?xmlversion="1.0"encoding="UTF-8"?>

<Wixxmlns="http://schemas.microsoft.com/wix/2003/01/wi">

 

  <?include..\..\Common\CommonDefinitions.wxi?>

  <?includeDefinitions.wxi?>

 

  <ProductId="$(var.ProductCode)"

           Name="$(var.ProductName)"

           Language="$(var.Language)"

           Version="$(var.CurrentVersion)"

           Manufacturer="$(var.Manufacturer)"

           UpgradeCode="$(var.UpgradeCode)" >

 

    <PackageId="$(var.PackageCode)"

             Description="$(var.PackageDescription)"

             Comments="$(var.PackageComments)"

             InstallerVersion="200"

             Compressed="yes"

             Languages="$(var.Languages)" />

 

    <?include..\..\Common\ARP.wxi?>

 

    <MediaId="1"Cabinet="Product.cab"EmbedCab="yes" />

 

    <?include..\..\Common\UpgradeSupport.wxi?>

 

    <DirectoryId="TARGETDIR"Name="SourceDir">

      <DirectoryId="ProgramFilesFolder">

        <DirectoryId="INSTALLLOCATION"

                   Name="Minimal"

                   LongName="MinimalInstallation">

 

          <ComponentId="TestIni"

                     Guid="{DC752365-A598-4B76-AC60-C99BF34D539F}">

            <CreateFolder />

 

            <IniFileId="Ini1"

                     Action="createLine"

                     Directory="INSTALLLOCATION"

                     Section="Test"

                     Name="Minimal.ini"

                     Key="TestKey"

                     Value="TestValue" />

 

            <IniFileId="Ini2"

                     Action="createLine"

                     Directory="WindowsFolder"

                     Section="Test"

                     Name="Minimal.ini"

                     Key="TestKey"

                     Value="WindowsFolder TestValue" />

 

          </Component>

        </Directory>

      </Directory>

    </Directory>

 //z 2012-08-21 17:35:55 IS2120@CSDN.T2347462763[T12,L1149,R8,V93]

    <FeatureId="MainFeature"

             Title="TestApp application"

             Level="1">

      <ComponentRefId="TestIni" />

    </Feature>

   </Product>

</Wix>

msi wix 安装 操作 文本 文件 ini 修改 xml wxi 打包 安装包 配置文件
//z 2012-08-21 17:35:55 IS2120@CSDN.T2347462763[T12,L1149,R8,V93]
原文地址:https://www.cnblogs.com/IS2120/p/6745845.html