aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Mba.Core/PackageInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixToolset.Mba.Core/PackageInfo.cs181
1 files changed, 181 insertions, 0 deletions
diff --git a/src/WixToolset.Mba.Core/PackageInfo.cs b/src/WixToolset.Mba.Core/PackageInfo.cs
new file mode 100644
index 00000000..99ebb33a
--- /dev/null
+++ b/src/WixToolset.Mba.Core/PackageInfo.cs
@@ -0,0 +1,181 @@
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
3namespace WixToolset.BootstrapperCore
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Xml;
8 using System.Xml.XPath;
9
10 public enum CacheType
11 {
12 No,
13 Yes,
14 Always,
15 }
16
17 public enum PackageType
18 {
19 Unknown,
20 Exe,
21 Msi,
22 Msp,
23 Msu,
24 UpgradeBundle,
25 AddonBundle,
26 PatchBundle,
27 }
28
29 public class PackageInfo : IPackageInfo
30 {
31 public string Id { get; internal set; }
32 public string DisplayName { get; internal set; }
33 public string Description { get; internal set; }
34 public PackageType Type { get; internal set; }
35 public bool Permanent { get; internal set; }
36 public bool Vital { get; internal set; }
37 public bool DisplayInternalUI { get; internal set; }
38 public string ProductCode { get; internal set; }
39 public string UpgradeCode { get; internal set; }
40 public string Version { get; internal set; }
41 public string InstallCondition { get; internal set; }
42 public CacheType CacheType { get; internal set; }
43
44 internal PackageInfo() { }
45
46 public static IEnumerable<IPackageInfo> ParsePackagesFromXml(XPathNavigator root)
47 {
48 XmlNamespaceManager namespaceManager = new XmlNamespaceManager(root.NameTable);
49 namespaceManager.AddNamespace("p", BootstrapperApplicationData.XMLNamespace);
50 XPathNodeIterator nodes = root.Select("/p:BootstrapperApplicationData/p:WixPackageProperties", namespaceManager);
51
52 foreach (XPathNavigator node in nodes)
53 {
54 var package = new PackageInfo();
55
56 string id = BootstrapperApplicationData.GetAttribute(node, "Package");
57 if (id == null)
58 {
59 throw new Exception("Failed to get package identifier for package.");
60 }
61 package.Id = id;
62
63 package.DisplayName = BootstrapperApplicationData.GetAttribute(node, "DisplayName");
64
65 package.Description = BootstrapperApplicationData.GetAttribute(node, "Description");
66
67 PackageType? packageType = GetPackageTypeAttribute(node, "PackageType");
68 if (!packageType.HasValue)
69 {
70 throw new Exception("Failed to get package type for package.");
71 }
72 package.Type = packageType.Value;
73
74 bool? permanent = BootstrapperApplicationData.GetYesNoAttribute(node, "Permanent");
75 if (!permanent.HasValue)
76 {
77 throw new Exception("Failed to get permanent settings for package.");
78 }
79 package.Permanent = permanent.Value;
80
81 bool? vital = BootstrapperApplicationData.GetYesNoAttribute(node, "Vital");
82 if (!vital.HasValue)
83 {
84 throw new Exception("Failed to get vital setting for package.");
85 }
86 package.Vital = vital.Value;
87
88 bool? displayInternalUI = BootstrapperApplicationData.GetYesNoAttribute(node, "DisplayInternalUI");
89 package.DisplayInternalUI = displayInternalUI.HasValue && displayInternalUI.Value;
90
91 package.ProductCode = BootstrapperApplicationData.GetAttribute(node, "ProductCode");
92
93 package.UpgradeCode = BootstrapperApplicationData.GetAttribute(node, "UpgradeCode");
94
95 package.Version = BootstrapperApplicationData.GetAttribute(node, "Version");
96
97 package.InstallCondition = BootstrapperApplicationData.GetAttribute(node, "InstallCondition");
98
99 yield return package;
100 }
101 }
102
103 public static CacheType? GetCacheTypeAttribute(XPathNavigator node, string attributeName)
104 {
105 string attributeValue = BootstrapperApplicationData.GetAttribute(node, attributeName);
106
107 if (attributeValue == null)
108 {
109 return null;
110 }
111
112 if (attributeValue.Equals("yes", StringComparison.InvariantCulture))
113 {
114 return CacheType.Yes;
115 }
116 else if (attributeValue.Equals("always", StringComparison.InvariantCulture))
117 {
118 return CacheType.Always;
119 }
120 else
121 {
122 return CacheType.No;
123 }
124 }
125
126 public static PackageType? GetPackageTypeAttribute(XPathNavigator node, string attributeName)
127 {
128 string attributeValue = BootstrapperApplicationData.GetAttribute(node, attributeName);
129
130 if (attributeValue == null)
131 {
132 return null;
133 }
134
135 if (attributeValue.Equals("Exe", StringComparison.InvariantCulture))
136 {
137 return PackageType.Exe;
138 }
139 else if (attributeValue.Equals("Msi", StringComparison.InvariantCulture))
140 {
141 return PackageType.Msi;
142 }
143 else if (attributeValue.Equals("Msp", StringComparison.InvariantCulture))
144 {
145 return PackageType.Msp;
146 }
147 else if (attributeValue.Equals("Msu", StringComparison.InvariantCulture))
148 {
149 return PackageType.Msu;
150 }
151 else
152 {
153 return PackageType.Unknown;
154 }
155 }
156
157 public static PackageInfo GetRelatedBundleAsPackage(string id, RelationType relationType, bool perMachine, Version version)
158 {
159 PackageInfo package = new PackageInfo();
160 package.Id = id;
161 package.Version = version.ToString();
162
163 switch (relationType)
164 {
165 case RelationType.Addon:
166 package.Type = PackageType.AddonBundle;
167 break;
168 case RelationType.Patch:
169 package.Type = PackageType.PatchBundle;
170 break;
171 case RelationType.Upgrade:
172 package.Type = PackageType.UpgradeBundle;
173 break;
174 default:
175 throw new Exception(string.Format("Unknown related bundle type: {0}", relationType));
176 }
177
178 return package;
179 }
180 }
181}