diff options
Diffstat (limited to 'src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs')
-rw-r--r-- | src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs b/src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs new file mode 100644 index 00000000..26af056b --- /dev/null +++ b/src/WixToolset.Core.Burn/Inscribe/InscribeBundleEngineCommand.cs | |||
@@ -0,0 +1,61 @@ | |||
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; | ||
9 | |||
10 | internal class InscribeBundleEngineCommand | ||
11 | { | ||
12 | public InscribeBundleEngineCommand(IInscribeContext context) | ||
13 | { | ||
14 | this.Context = context; | ||
15 | } | ||
16 | |||
17 | private IInscribeContext Context { get; } | ||
18 | |||
19 | public bool Execute() | ||
20 | { | ||
21 | string tempFile = Path.Combine(this.Context.IntermediateFolder, "bundle_engine_unsigned.exe"); | ||
22 | |||
23 | using (BurnReader reader = BurnReader.Open(this.Context.InputFilePath)) | ||
24 | using (FileStream writer = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete)) | ||
25 | { | ||
26 | reader.Stream.Seek(0, SeekOrigin.Begin); | ||
27 | |||
28 | byte[] buffer = new byte[4 * 1024]; | ||
29 | int total = 0; | ||
30 | int read = 0; | ||
31 | do | ||
32 | { | ||
33 | read = Math.Min(buffer.Length, (int)reader.EngineSize - total); | ||
34 | |||
35 | read = reader.Stream.Read(buffer, 0, read); | ||
36 | writer.Write(buffer, 0, read); | ||
37 | |||
38 | total += read; | ||
39 | } while (total < reader.EngineSize && 0 < read); | ||
40 | |||
41 | if (total != reader.EngineSize) | ||
42 | { | ||
43 | throw new InvalidOperationException("Failed to copy engine out of bundle."); | ||
44 | } | ||
45 | |||
46 | // TODO: update writer with detached container signatures. | ||
47 | } | ||
48 | |||
49 | Directory.CreateDirectory(Path.GetDirectoryName(this.Context.OutputFile)); | ||
50 | if (File.Exists(this.Context.OutputFile)) | ||
51 | { | ||
52 | File.Delete(this.Context.OutputFile); | ||
53 | } | ||
54 | |||
55 | File.Move(tempFile, this.Context.OutputFile); | ||
56 | WixToolset.Core.Native.NativeMethods.ResetAcls(new string[] { this.Context.OutputFile }, 1); | ||
57 | |||
58 | return true; | ||
59 | } | ||
60 | } | ||
61 | } | ||