aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Mba.Core/BootstrapperApplicationData.cs
blob: 05672f1bfa59968d79e0c0d2b5d17891616ff893 (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
// 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;

    public class BootstrapperApplicationData : IBootstrapperApplicationData
    {
        public const string DefaultFileName = "BootstrapperApplicationData.xml";
        public const string XMLNamespace = "http://wixtoolset.org/schemas/v4/BootstrapperApplicationData";

        public static readonly DirectoryInfo DefaultFolder;
        public static readonly FileInfo DefaultFile;

        static BootstrapperApplicationData()
        {
            DefaultFolder = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
            DefaultFile = new FileInfo(Path.Combine(DefaultFolder.FullName, DefaultFileName));
        }

        public FileInfo BADataFile { get; private set; }

        public IBundleInfo Bundle { get; private set; }

        public BootstrapperApplicationData() : this(DefaultFile) { }

        public BootstrapperApplicationData(FileInfo baDataFile)
        {
            this.BADataFile = baDataFile;

            using (FileStream fs = this.BADataFile.OpenRead())
            {
                this.Bundle = BundleInfo.ParseBundleFromStream(fs);
            }
        }

        public static string GetAttribute(XPathNavigator node, string attributeName)
        {
            XPathNavigator attribute = node.SelectSingleNode("@" + attributeName);

            if (attribute == null)
            {
                return null;
            }

            return attribute.Value;
        }

        public static bool? GetYesNoAttribute(XPathNavigator node, string attributeName)
        {
            string attributeValue = GetAttribute(node, attributeName);

            if (attributeValue == null)
            {
                return null;
            }

            return attributeValue.Equals("yes", StringComparison.InvariantCulture);
        }
    }
}