diff options
author | Rob Mensching <rob@firegiant.com> | 2021-04-22 05:46:03 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-04-29 16:41:44 -0700 |
commit | c00516901e6b67e398396b14fe7682d0376f8643 (patch) | |
tree | b0d62089a1c5700c7f2c3e3790750bf2d8ea33c0 /src/api/burn/WixToolset.Mba.Core/BundleInfo.cs | |
parent | 8eb98efd2175d9ece2e4639d43081667af9a4990 (diff) | |
download | wix-c00516901e6b67e398396b14fe7682d0376f8643.tar.gz wix-c00516901e6b67e398396b14fe7682d0376f8643.tar.bz2 wix-c00516901e6b67e398396b14fe7682d0376f8643.zip |
Move balutil into API/burn
Diffstat (limited to 'src/api/burn/WixToolset.Mba.Core/BundleInfo.cs')
-rw-r--r-- | src/api/burn/WixToolset.Mba.Core/BundleInfo.cs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/api/burn/WixToolset.Mba.Core/BundleInfo.cs b/src/api/burn/WixToolset.Mba.Core/BundleInfo.cs new file mode 100644 index 00000000..3d5d535d --- /dev/null +++ b/src/api/burn/WixToolset.Mba.Core/BundleInfo.cs | |||
@@ -0,0 +1,86 @@ | |||
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.Mba.Core | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using System.Xml; | ||
9 | using System.Xml.XPath; | ||
10 | |||
11 | /// <summary> | ||
12 | /// Default implementation of <see cref="IBundleInfo"/>. | ||
13 | /// </summary> | ||
14 | public class BundleInfo : IBundleInfo | ||
15 | { | ||
16 | /// <inheritdoc/> | ||
17 | public bool PerMachine { get; internal set; } | ||
18 | |||
19 | /// <inheritdoc/> | ||
20 | public string Name { get; internal set; } | ||
21 | |||
22 | /// <inheritdoc/> | ||
23 | public string LogVariable { get; internal set; } | ||
24 | |||
25 | /// <inheritdoc/> | ||
26 | public IDictionary<string, IPackageInfo> Packages { get; internal set; } | ||
27 | |||
28 | internal BundleInfo() | ||
29 | { | ||
30 | this.Packages = new Dictionary<string, IPackageInfo>(); | ||
31 | } | ||
32 | |||
33 | /// <inheritdoc/> | ||
34 | public IPackageInfo AddRelatedBundleAsPackage(DetectRelatedBundleEventArgs e) | ||
35 | { | ||
36 | var package = PackageInfo.GetRelatedBundleAsPackage(e.ProductCode, e.RelationType, e.PerMachine, e.Version); | ||
37 | this.Packages.Add(package.Id, package); | ||
38 | return package; | ||
39 | } | ||
40 | |||
41 | /// <summary> | ||
42 | /// Parses BA manifest from the given stream. | ||
43 | /// </summary> | ||
44 | /// <param name="stream"></param> | ||
45 | /// <returns></returns> | ||
46 | public static IBundleInfo ParseBundleFromStream(Stream stream) | ||
47 | { | ||
48 | XPathDocument manifest = new XPathDocument(stream); | ||
49 | XPathNavigator root = manifest.CreateNavigator(); | ||
50 | return ParseBundleFromXml(root); | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Parses BA manifest from the given <see cref="XPathNavigator"/>. | ||
55 | /// </summary> | ||
56 | /// <param name="root">The root of the BA manifest.</param> | ||
57 | /// <returns></returns> | ||
58 | public static IBundleInfo ParseBundleFromXml(XPathNavigator root) | ||
59 | { | ||
60 | BundleInfo bundle = new BundleInfo(); | ||
61 | |||
62 | XmlNamespaceManager namespaceManager = new XmlNamespaceManager(root.NameTable); | ||
63 | namespaceManager.AddNamespace("p", BootstrapperApplicationData.XMLNamespace); | ||
64 | XPathNavigator bundleNode = root.SelectSingleNode("/p:BootstrapperApplicationData/p:WixBundleProperties", namespaceManager); | ||
65 | |||
66 | if (bundleNode == null) | ||
67 | { | ||
68 | throw new Exception("Failed to select bundle information."); | ||
69 | } | ||
70 | |||
71 | bool? perMachine = BootstrapperApplicationData.GetYesNoAttribute(bundleNode, "PerMachine"); | ||
72 | if (perMachine.HasValue) | ||
73 | { | ||
74 | bundle.PerMachine = perMachine.Value; | ||
75 | } | ||
76 | |||
77 | bundle.Name = BootstrapperApplicationData.GetAttribute(bundleNode, "DisplayName"); | ||
78 | |||
79 | bundle.LogVariable = BootstrapperApplicationData.GetAttribute(bundleNode, "LogPathVariable"); | ||
80 | |||
81 | bundle.Packages = PackageInfo.ParsePackagesFromXml(root); | ||
82 | |||
83 | return bundle; | ||
84 | } | ||
85 | } | ||
86 | } | ||