// 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; /// /// Utility class for reading BootstrapperApplicationData.xml. /// public class BootstrapperApplicationData : IBootstrapperApplicationData { /// /// /// public const string DefaultFileName = "BootstrapperApplicationData.xml"; /// /// /// public const string XMLNamespace = "http://wixtoolset.org/schemas/v4/BootstrapperApplicationData"; /// /// The default path of where the BA was extracted to. /// public static readonly DirectoryInfo DefaultFolder; /// /// The default path to BootstrapperApplicationData.xml. /// 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; } /// /// Uses the default location for BootstrapperApplicationData.xml. /// public BootstrapperApplicationData() : this(DefaultFile) { } /// /// Uses the given file for BootstrapperApplicationData.xml. /// /// public BootstrapperApplicationData(FileInfo baDataFile) { this.BADataFile = baDataFile; using (FileStream fs = this.BADataFile.OpenRead()) { this.Bundle = BundleInfo.ParseBundleFromStream(fs); } } /// /// Utility method for parsing BootstrapperApplicationData.xml. /// /// /// /// public static string GetAttribute(XPathNavigator node, string attributeName) { XPathNavigator attribute = node.SelectSingleNode("@" + attributeName); if (attribute == null) { return null; } return attribute.Value; } /// /// Utility method for parsing BootstrapperApplicationData.xml. /// /// /// /// public static bool? GetYesNoAttribute(XPathNavigator node, string attributeName) { string attributeValue = GetAttribute(node, attributeName); if (attributeValue == null) { return null; } return attributeValue.Equals("yes", StringComparison.InvariantCulture); } } }