| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.Dtf.WindowsInstaller.Package |
| 4 | { |
| 5 | using System; |
| 6 | using System.IO; |
| 7 | using System.Globalization; |
| 8 | |
| 9 | /// <summary> |
| 10 | /// Contains properties of a transform package (.MST). |
| 11 | /// </summary> |
| 12 | public class TransformInfo |
| 13 | { |
| 14 | /// <summary> |
| 15 | /// Reads transform information from a transform package. |
| 16 | /// </summary> |
| 17 | /// <param name="mstFile">Path to a transform package (.MST file).</param> |
| 18 | public TransformInfo(string mstFile) |
| 19 | { |
| 20 | this.name = Path.GetFileName(mstFile); |
| 21 | using (SummaryInfo transformSummInfo = new SummaryInfo(mstFile, false)) |
| 22 | { |
| 23 | this.DecodeSummaryInfo(transformSummInfo); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | /// <summary> |
| 28 | /// Reads transform information from the summary information of a transform package. |
| 29 | /// </summary> |
| 30 | /// <param name="name">Filename of the transform (optional).</param> |
| 31 | /// <param name="transformSummaryInfo">Handle to the summary information of a transform package (.MST file).</param> |
| 32 | public TransformInfo(string name, SummaryInfo transformSummaryInfo) |
| 33 | { |
| 34 | this.name = name; |
| 35 | this.DecodeSummaryInfo(transformSummaryInfo); |
| 36 | } |
| 37 | |
| 38 | private void DecodeSummaryInfo(SummaryInfo transformSummaryInfo) |
| 39 | { |
| 40 | try |
| 41 | { |
| 42 | string[] rev = transformSummaryInfo.RevisionNumber.Split(new char[] { ';' }, 3); |
| 43 | this.targetProductCode = rev[0].Substring(0, 38); |
| 44 | this.targetProductVersion = rev[0].Substring(38); |
| 45 | this.upgradeProductCode = rev[1].Substring(0, 38); |
| 46 | this.upgradeProductVersion = rev[1].Substring(38); |
| 47 | this.upgradeCode = rev[2]; |
| 48 | |
| 49 | string[] templ = transformSummaryInfo.Template.Split(new Char[] { ';' }, 2); |
| 50 | this.targetPlatform = templ[0]; |
| 51 | this.targetLanguage = 0; |
| 52 | if (templ.Length >= 2 && templ[1].Length > 0) |
| 53 | { |
| 54 | this.targetLanguage = Int32.Parse(templ[1], CultureInfo.InvariantCulture.NumberFormat); |
| 55 | } |
| 56 | |
| 57 | this.validateFlags = (TransformValidations) transformSummaryInfo.CharacterCount; |
| 58 | } |
| 59 | catch (Exception ex) |
| 60 | { |
| 61 | throw new InstallerException("Invalid transform summary info", ex); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /// <summary> |
| 66 | /// Gets the filename of the transform. |
| 67 | /// </summary> |
| 68 | public string Name |
| 69 | { |
| 70 | get { return this.name; } |
| 71 | } |
| 72 | private string name; |
| 73 | |
| 74 | /// <summary> |
| 75 | /// Gets the target product code of the transform. |
| 76 | /// </summary> |
| 77 | public string TargetProductCode |
| 78 | { |
| 79 | get { return this.targetProductCode; } |
| 80 | } |
| 81 | private string targetProductCode; |
| 82 | |
| 83 | /// <summary> |
| 84 | /// Gets the target product version of the transform. |
| 85 | /// </summary> |
| 86 | public string TargetProductVersion |
| 87 | { |
| 88 | get { return this.targetProductVersion; } |
| 89 | } |
| 90 | private string targetProductVersion; |
| 91 | |
| 92 | /// <summary> |
| 93 | /// Gets the upgrade product code of the transform. |
| 94 | /// </summary> |
| 95 | public string UpgradeProductCode |
| 96 | { |
| 97 | get { return this.upgradeProductCode; } |
| 98 | } |
| 99 | private string upgradeProductCode; |
| 100 | |
| 101 | /// <summary> |
| 102 | /// Gets the upgrade product version of the transform. |
| 103 | /// </summary> |
| 104 | public string UpgradeProductVersion |
| 105 | { |
| 106 | get { return this.upgradeProductVersion; } |
| 107 | } |
| 108 | private string upgradeProductVersion; |
| 109 | |
| 110 | /// <summary> |
| 111 | /// Gets the upgrade code of the transform. |
| 112 | /// </summary> |
| 113 | public string UpgradeCode |
| 114 | { |
| 115 | get { return this.upgradeCode; } |
| 116 | } |
| 117 | private string upgradeCode; |
| 118 | |
| 119 | /// <summary> |
| 120 | /// Gets the target platform of the transform. |
| 121 | /// </summary> |
| 122 | public string TargetPlatform |
| 123 | { |
| 124 | get { return this.targetPlatform; } |
| 125 | } |
| 126 | private string targetPlatform; |
| 127 | |
| 128 | /// <summary> |
| 129 | /// Gets the target language of the transform, or 0 if the transform is language-neutral. |
| 130 | /// </summary> |
| 131 | public int TargetLanguage |
| 132 | { |
| 133 | get { return this.targetLanguage; } |
| 134 | } |
| 135 | private int targetLanguage; |
| 136 | |
| 137 | /// <summary> |
| 138 | /// Gets the validation flags specified when the transform was generated. |
| 139 | /// </summary> |
| 140 | public TransformValidations Validations |
| 141 | { |
| 142 | get { return this.validateFlags; } |
| 143 | } |
| 144 | private TransformValidations validateFlags; |
| 145 | |
| 146 | /// <summary> |
| 147 | /// Returns the name of the transform. |
| 148 | /// </summary> |
| 149 | public override string ToString() |
| 150 | { |
| 151 | return (this.Name != null ? this.Name : "MST"); |
| 152 | } |
| 153 | } |
| 154 | } |