| 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.Core.Burn.Bundles |
| 4 | { |
| 5 | using System; |
| 6 | using System.Globalization; |
| 7 | using System.IO; |
| 8 | using System.Text; |
| 9 | using System.Xml; |
| 10 | using WixToolset.Data; |
| 11 | using WixToolset.Data.Burn; |
| 12 | using WixToolset.Data.Symbols; |
| 13 | |
| 14 | internal class CreateBootstrapperExtensionManifestCommand |
| 15 | { |
| 16 | public CreateBootstrapperExtensionManifestCommand(IntermediateSection section, WixBundleSymbol bundleSymbol, int lastUXPayloadIndex, string intermediateFolder, IInternalBurnBackendHelper internalBurnBackendHelper) |
| 17 | { |
| 18 | this.Section = section; |
| 19 | this.BundleSymbol = bundleSymbol; |
| 20 | this.LastUXPayloadIndex = lastUXPayloadIndex; |
| 21 | this.IntermediateFolder = intermediateFolder; |
| 22 | this.InternalBurnBackendHelper = internalBurnBackendHelper; |
| 23 | } |
| 24 | |
| 25 | private IntermediateSection Section { get; } |
| 26 | |
| 27 | private WixBundleSymbol BundleSymbol { get; } |
| 28 | |
| 29 | private IInternalBurnBackendHelper InternalBurnBackendHelper { get; } |
| 30 | |
| 31 | private int LastUXPayloadIndex { get; } |
| 32 | |
| 33 | private string IntermediateFolder { get; } |
| 34 | |
| 35 | public WixBundlePayloadSymbol BootstrapperExtensionManifestPayloadRow { get; private set; } |
| 36 | |
| 37 | public string OutputPath { get; private set; } |
| 38 | |
| 39 | public void Execute() |
| 40 | { |
| 41 | this.OutputPath = this.CreateBootstrapperExtensionManifest(); |
| 42 | |
| 43 | this.BootstrapperExtensionManifestPayloadRow = this.CreateBootstrapperExtensionManifestPayloadRow(this.OutputPath); |
| 44 | } |
| 45 | |
| 46 | private string CreateBootstrapperExtensionManifest() |
| 47 | { |
| 48 | var path = Path.Combine(this.IntermediateFolder, "wix-bextdata.xml"); |
| 49 | |
| 50 | Directory.CreateDirectory(Path.GetDirectoryName(path)); |
| 51 | |
| 52 | using (var writer = new XmlTextWriter(path, Encoding.Unicode)) |
| 53 | { |
| 54 | writer.Formatting = Formatting.Indented; |
| 55 | writer.WriteStartDocument(); |
| 56 | writer.WriteStartElement("BootstrapperExtensionData", BurnConstants.BootstrapperExtensionDataNamespace); |
| 57 | |
| 58 | this.InternalBurnBackendHelper.WriteBootstrapperExtensionData(writer); |
| 59 | |
| 60 | writer.WriteEndElement(); |
| 61 | writer.WriteEndDocument(); |
| 62 | } |
| 63 | |
| 64 | return path; |
| 65 | } |
| 66 | |
| 67 | private WixBundlePayloadSymbol CreateBootstrapperExtensionManifestPayloadRow(string bextManifestPath) |
| 68 | { |
| 69 | var generatedId = this.InternalBurnBackendHelper.GenerateIdentifier("ux", BurnCommon.BootstrapperExtensionDataFileName); |
| 70 | |
| 71 | this.Section.AddSymbol(new WixGroupSymbol(this.BundleSymbol.SourceLineNumbers) |
| 72 | { |
| 73 | ParentType = ComplexReferenceParentType.Container, |
| 74 | ParentId = BurnConstants.BurnUXContainerName, |
| 75 | ChildType = ComplexReferenceChildType.Payload, |
| 76 | ChildId = generatedId |
| 77 | }); |
| 78 | |
| 79 | var symbol = this.Section.AddSymbol(new WixBundlePayloadSymbol(this.BundleSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, generatedId)) |
| 80 | { |
| 81 | Name = BurnCommon.BootstrapperExtensionDataFileName, |
| 82 | SourceFile = new IntermediateFieldPathValue { Path = bextManifestPath }, |
| 83 | Compressed = true, |
| 84 | UnresolvedSourceFile = bextManifestPath, |
| 85 | ContainerRef = BurnConstants.BurnUXContainerName, |
| 86 | EmbeddedId = String.Format(CultureInfo.InvariantCulture, BurnCommon.BurnUXContainerEmbeddedIdFormat, this.LastUXPayloadIndex), |
| 87 | Packaging = PackagingType.Embedded, |
| 88 | }); |
| 89 | |
| 90 | var fileInfo = new FileInfo(bextManifestPath); |
| 91 | |
| 92 | symbol.FileSize = (int)fileInfo.Length; |
| 93 | |
| 94 | symbol.Hash = BundleHashAlgorithm.Hash(fileInfo); |
| 95 | |
| 96 | return symbol; |
| 97 | } |
| 98 | } |
| 99 | } |