| 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.Inscribe |
| 4 | { |
| 5 | using System; |
| 6 | using System.IO; |
| 7 | using WixToolset.Core.Burn.Bundles; |
| 8 | using WixToolset.Extensibility.Services; |
| 9 | |
| 10 | internal class InscribeBundleCommand |
| 11 | { |
| 12 | public InscribeBundleCommand(IServiceProvider serviceProvider, string inputPath, string signedEngineFile, string outputPath, string intermediateFolder) |
| 13 | { |
| 14 | this.Messaging = serviceProvider.GetService<IMessaging>(); |
| 15 | this.FileSystem = serviceProvider.GetService<IFileSystem>(); |
| 16 | this.IntermediateFolder = intermediateFolder; |
| 17 | this.InputFilePath = inputPath; |
| 18 | this.SignedEngineFile = signedEngineFile; |
| 19 | this.OutputFile = outputPath; |
| 20 | } |
| 21 | |
| 22 | private IMessaging Messaging { get; } |
| 23 | |
| 24 | private IFileSystem FileSystem { get; } |
| 25 | |
| 26 | private string IntermediateFolder { get; } |
| 27 | |
| 28 | private string InputFilePath { get; } |
| 29 | |
| 30 | private string SignedEngineFile { get; } |
| 31 | |
| 32 | private string OutputFile { get; } |
| 33 | |
| 34 | public bool Execute() |
| 35 | { |
| 36 | var inscribed = false; |
| 37 | var tempFile = Path.Combine(this.IntermediateFolder, "~bundle_engine_signed.exe"); |
| 38 | |
| 39 | using (var reader = BurnReader.Open(this.Messaging, this.FileSystem, this.InputFilePath)) |
| 40 | { |
| 41 | this.FileSystem.CopyFile(null, this.SignedEngineFile, tempFile, allowHardlink: false); |
| 42 | |
| 43 | using (var writer = BurnWriter.Open(this.Messaging, this.FileSystem, tempFile)) |
| 44 | { |
| 45 | inscribed = writer.ReattachContainers(reader); |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | this.FileSystem.MoveFile(null, tempFile, this.OutputFile); |
| 50 | |
| 51 | return inscribed; |
| 52 | } |
| 53 | } |
| 54 | } |