aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Bind/Bundles/ProcessPayloadsCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Bind/Bundles/ProcessPayloadsCommand.cs')
-rw-r--r--src/WixToolset.Core/Bind/Bundles/ProcessPayloadsCommand.cs159
1 files changed, 0 insertions, 159 deletions
diff --git a/src/WixToolset.Core/Bind/Bundles/ProcessPayloadsCommand.cs b/src/WixToolset.Core/Bind/Bundles/ProcessPayloadsCommand.cs
deleted file mode 100644
index a83a7a4a..00000000
--- a/src/WixToolset.Core/Bind/Bundles/ProcessPayloadsCommand.cs
+++ /dev/null
@@ -1,159 +0,0 @@
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
3namespace WixToolset.Bind.Bundles
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Diagnostics;
8 using System.IO;
9 using System.Security.Cryptography;
10 using System.Security.Cryptography.X509Certificates;
11 using System.Text;
12 using WixToolset.Data;
13 using WixToolset.Data.Rows;
14
15 internal class ProcessPayloadsCommand : ICommand
16 {
17 private static readonly Version EmptyVersion = new Version(0, 0, 0, 0);
18
19 public IEnumerable<WixBundlePayloadRow> Payloads { private get; set; }
20
21 public PackagingType DefaultPackaging { private get; set; }
22
23 public string LayoutDirectory { private get; set; }
24
25 public IEnumerable<FileTransfer> FileTransfers { get; private set; }
26
27 public void Execute()
28 {
29 List<FileTransfer> fileTransfers = new List<FileTransfer>();
30
31 foreach (WixBundlePayloadRow payload in this.Payloads)
32 {
33 string normalizedPath = payload.Name.Replace('\\', '/');
34 if (normalizedPath.StartsWith("../", StringComparison.Ordinal) || normalizedPath.Contains("/../"))
35 {
36 Messaging.Instance.OnMessage(WixErrors.PayloadMustBeRelativeToCache(payload.SourceLineNumbers, "Payload", "Name", payload.Name));
37 }
38
39 // Embedded files (aka: files from binary .wixlibs) are not content files (because they are hidden
40 // in the .wixlib).
41 ObjectField field = (ObjectField)payload.Fields[2];
42 payload.ContentFile = !field.EmbeddedFileIndex.HasValue;
43
44 this.UpdatePayloadPackagingType(payload);
45
46 if (String.IsNullOrEmpty(payload.SourceFile))
47 {
48 // Remote payloads obviously cannot be embedded.
49 Debug.Assert(PackagingType.Embedded != payload.Packaging);
50 }
51 else // not a remote payload so we have a lot more to update.
52 {
53 this.UpdatePayloadFileInformation(payload);
54
55 this.UpdatePayloadVersionInformation(payload);
56
57 // External payloads need to be transfered.
58 if (PackagingType.External == payload.Packaging)
59 {
60 FileTransfer transfer;
61 if (FileTransfer.TryCreate(payload.FullFileName, Path.Combine(this.LayoutDirectory, payload.Name), false, "Payload", payload.SourceLineNumbers, out transfer))
62 {
63 fileTransfers.Add(transfer);
64 }
65 }
66 }
67 }
68
69 this.FileTransfers = fileTransfers;
70 }
71
72 private void UpdatePayloadPackagingType(WixBundlePayloadRow payload)
73 {
74 if (PackagingType.Unknown == payload.Packaging)
75 {
76 if (YesNoDefaultType.Yes == payload.Compressed)
77 {
78 payload.Packaging = PackagingType.Embedded;
79 }
80 else if (YesNoDefaultType.No == payload.Compressed)
81 {
82 payload.Packaging = PackagingType.External;
83 }
84 else
85 {
86 payload.Packaging = this.DefaultPackaging;
87 }
88 }
89
90 // Embedded payloads that are not assigned a container already are placed in the default attached
91 // container.
92 if (PackagingType.Embedded == payload.Packaging && String.IsNullOrEmpty(payload.Container))
93 {
94 payload.Container = Compiler.BurnDefaultAttachedContainerId;
95 }
96 }
97
98 private void UpdatePayloadFileInformation(WixBundlePayloadRow payload)
99 {
100 FileInfo fileInfo = new FileInfo(payload.SourceFile);
101
102 if (null != fileInfo)
103 {
104 payload.FileSize = (int)fileInfo.Length;
105
106 payload.Hash = Common.GetFileHash(fileInfo.FullName);
107
108 // Try to get the certificate if the payload is a signed file and we're not suppressing signature validation.
109 if (payload.EnableSignatureValidation)
110 {
111 X509Certificate2 certificate = null;
112 try
113 {
114 certificate = new X509Certificate2(fileInfo.FullName);
115 }
116 catch (CryptographicException) // we don't care about non-signed files.
117 {
118 }
119
120 // If there is a certificate, remember its hashed public key identifier and thumbprint.
121 if (null != certificate)
122 {
123 byte[] publicKeyIdentifierHash = new byte[128];
124 uint publicKeyIdentifierHashSize = (uint)publicKeyIdentifierHash.Length;
125
126 WixToolset.Core.Native.NativeMethods.HashPublicKeyInfo(certificate.Handle, publicKeyIdentifierHash, ref publicKeyIdentifierHashSize);
127 StringBuilder sb = new StringBuilder(((int)publicKeyIdentifierHashSize + 1) * 2);
128 for (int i = 0; i < publicKeyIdentifierHashSize; ++i)
129 {
130 sb.AppendFormat("{0:X2}", publicKeyIdentifierHash[i]);
131 }
132
133 payload.PublicKey = sb.ToString();
134 payload.Thumbprint = certificate.Thumbprint;
135 }
136 }
137 }
138 }
139
140 private void UpdatePayloadVersionInformation(WixBundlePayloadRow payload)
141 {
142 FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(payload.SourceFile);
143
144 if (null != versionInfo)
145 {
146 // Use the fixed version info block for the file since the resource text may not be a dotted quad.
147 Version version = new Version(versionInfo.ProductMajorPart, versionInfo.ProductMinorPart, versionInfo.ProductBuildPart, versionInfo.ProductPrivatePart);
148
149 if (ProcessPayloadsCommand.EmptyVersion != version)
150 {
151 payload.Version = version.ToString();
152 }
153
154 payload.Description = versionInfo.FileDescription;
155 payload.DisplayName = versionInfo.ProductName;
156 }
157 }
158 }
159}