blob: 739a08bb6b7aff5654dfb5dc055f071180e69d5b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// 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.
namespace WixToolset.Mba.Core
{
using System;
using System.IO;
using System.Xml.XPath;
/// <summary>
/// Utility class for reading BootstrapperApplicationData.xml.
/// </summary>
public class BootstrapperApplicationData : IBootstrapperApplicationData
{
/// <summary>
///
/// </summary>
public const string DefaultFileName = "BootstrapperApplicationData.xml";
/// <summary>
///
/// </summary>
public const string XMLNamespace = "http://wixtoolset.org/schemas/v4/BootstrapperApplicationData";
/// <summary>
/// The default path of where the BA was extracted to.
/// </summary>
public static readonly DirectoryInfo DefaultFolder;
/// <summary>
/// The default path to BootstrapperApplicationData.xml.
/// </summary>
public static readonly FileInfo DefaultFile;
static BootstrapperApplicationData()
{
DefaultFolder = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
DefaultFile = new FileInfo(Path.Combine(DefaultFolder.FullName, DefaultFileName));
}
/// <inheritdoc/>
public FileInfo BADataFile { get; private set; }
/// <inheritdoc/>
public IBundleInfo Bundle { get; private set; }
/// <summary>
/// Uses the default location for BootstrapperApplicationData.xml.
/// </summary>
public BootstrapperApplicationData() : this(DefaultFile) { }
/// <summary>
/// Uses the given file for BootstrapperApplicationData.xml.
/// </summary>
/// <param name="baDataFile"></param>
public BootstrapperApplicationData(FileInfo baDataFile)
{
this.BADataFile = baDataFile;
using (FileStream fs = this.BADataFile.OpenRead())
{
this.Bundle = BundleInfo.ParseBundleFromStream(fs);
}
}
/// <summary>
/// Utility method for parsing BootstrapperApplicationData.xml.
/// </summary>
/// <param name="node"></param>
/// <param name="attributeName"></param>
/// <returns></returns>
public static string GetAttribute(XPathNavigator node, string attributeName)
{
XPathNavigator attribute = node.SelectSingleNode("@" + attributeName);
if (attribute == null)
{
return null;
}
return attribute.Value;
}
/// <summary>
/// Utility method for parsing BootstrapperApplicationData.xml.
/// </summary>
/// <param name="node"></param>
/// <param name="attributeName"></param>
/// <returns></returns>
public static bool? GetYesNoAttribute(XPathNavigator node, string attributeName)
{
string attributeValue = GetAttribute(node, attributeName);
if (attributeValue == null)
{
return null;
}
return attributeValue.Equals("yes", StringComparison.InvariantCulture);
}
}
}
|