diff options
author | Rob Mensching <rob@firegiant.com> | 2021-03-16 10:49:09 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2021-03-16 11:07:44 -0700 |
commit | 60f75abcd1fe49052c118a2597ac59a82c372b64 (patch) | |
tree | 1fd88e6c67846b97e61dbc3bf6f5f440516829a2 /src/WixToolset.Core | |
parent | 1c23520ed490b56e292dc1544463af83807745ad (diff) | |
download | wix-60f75abcd1fe49052c118a2597ac59a82c372b64.tar.gz wix-60f75abcd1fe49052c118a2597ac59a82c372b64.tar.bz2 wix-60f75abcd1fe49052c118a2597ac59a82c372b64.zip |
Migrate PInvoke out of Core to Core.Native
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r-- | src/WixToolset.Core/Bind/FileSystem.cs | 86 | ||||
-rw-r--r-- | src/WixToolset.Core/Bind/TransferFilesCommand.cs | 52 | ||||
-rw-r--r-- | src/WixToolset.Core/Inscriber.cs | 437 | ||||
-rw-r--r-- | src/WixToolset.Core/WixToolset.Core.csproj | 1 |
4 files changed, 30 insertions, 546 deletions
diff --git a/src/WixToolset.Core/Bind/FileSystem.cs b/src/WixToolset.Core/Bind/FileSystem.cs deleted file mode 100644 index bdd65503..00000000 --- a/src/WixToolset.Core/Bind/FileSystem.cs +++ /dev/null | |||
@@ -1,86 +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 | |||
3 | namespace WixToolset.Core.Bind | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using System.Runtime.InteropServices; | ||
9 | using WixToolset.Extensibility; | ||
10 | |||
11 | internal class FileSystem | ||
12 | { | ||
13 | public FileSystem(IEnumerable<ILayoutExtension> extensions) | ||
14 | { | ||
15 | this.Extensions = extensions ?? Array.Empty<ILayoutExtension>(); | ||
16 | } | ||
17 | |||
18 | private IEnumerable<ILayoutExtension> Extensions { get; } | ||
19 | |||
20 | /// <summary> | ||
21 | /// Copies a file. | ||
22 | /// </summary> | ||
23 | /// <param name="source">The file to copy.</param> | ||
24 | /// <param name="destination">The destination file.</param> | ||
25 | public bool CopyFile(string source, string destination) | ||
26 | { | ||
27 | foreach (var extension in this.Extensions) | ||
28 | { | ||
29 | if (extension.CopyFile(source, destination)) | ||
30 | { | ||
31 | return true; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | if (File.Exists(destination)) | ||
36 | { | ||
37 | File.Delete(destination); | ||
38 | } | ||
39 | |||
40 | if (!CreateHardLink(destination, source, IntPtr.Zero)) | ||
41 | { | ||
42 | #if DEBUG | ||
43 | int er = Marshal.GetLastWin32Error(); | ||
44 | #endif | ||
45 | |||
46 | File.Copy(source, destination, true); | ||
47 | } | ||
48 | |||
49 | return true; | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Moves a file. | ||
54 | /// </summary> | ||
55 | /// <param name="source">The file to move.</param> | ||
56 | /// <param name="destination">The destination file.</param> | ||
57 | public bool MoveFile(string source, string destination) | ||
58 | { | ||
59 | foreach (var extension in this.Extensions) | ||
60 | { | ||
61 | if (extension.MoveFile(source, destination)) | ||
62 | { | ||
63 | return true; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | if (File.Exists(destination)) | ||
68 | { | ||
69 | File.Delete(destination); | ||
70 | } | ||
71 | |||
72 | var directory = Path.GetDirectoryName(destination); | ||
73 | if (!String.IsNullOrEmpty(directory)) | ||
74 | { | ||
75 | Directory.CreateDirectory(directory); | ||
76 | } | ||
77 | |||
78 | File.Move(source, destination); | ||
79 | |||
80 | return true; | ||
81 | } | ||
82 | |||
83 | [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] | ||
84 | private static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes); | ||
85 | } | ||
86 | } | ||
diff --git a/src/WixToolset.Core/Bind/TransferFilesCommand.cs b/src/WixToolset.Core/Bind/TransferFilesCommand.cs index b9c54a14..9c104187 100644 --- a/src/WixToolset.Core/Bind/TransferFilesCommand.cs +++ b/src/WixToolset.Core/Bind/TransferFilesCommand.cs | |||
@@ -6,6 +6,7 @@ namespace WixToolset.Core.Bind | |||
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.IO; | 7 | using System.IO; |
8 | using System.Security.AccessControl; | 8 | using System.Security.AccessControl; |
9 | using WixToolset.Core.Native; | ||
9 | using WixToolset.Data; | 10 | using WixToolset.Data; |
10 | using WixToolset.Extensibility; | 11 | using WixToolset.Extensibility; |
11 | using WixToolset.Extensibility.Data; | 12 | using WixToolset.Extensibility.Data; |
@@ -15,23 +16,23 @@ namespace WixToolset.Core.Bind | |||
15 | { | 16 | { |
16 | public TransferFilesCommand(IMessaging messaging, IEnumerable<ILayoutExtension> extensions, IEnumerable<IFileTransfer> fileTransfers, bool suppressAclReset) | 17 | public TransferFilesCommand(IMessaging messaging, IEnumerable<ILayoutExtension> extensions, IEnumerable<IFileTransfer> fileTransfers, bool suppressAclReset) |
17 | { | 18 | { |
18 | this.FileSystem = new FileSystem(extensions); | 19 | this.Extensions = extensions; |
19 | this.Messaging = messaging; | 20 | this.Messaging = messaging; |
20 | this.FileTransfers = fileTransfers; | 21 | this.FileTransfers = fileTransfers; |
21 | this.SuppressAclReset = suppressAclReset; | 22 | this.SuppressAclReset = suppressAclReset; |
22 | } | 23 | } |
23 | 24 | ||
24 | private FileSystem FileSystem { get; } | ||
25 | |||
26 | private IMessaging Messaging { get; } | 25 | private IMessaging Messaging { get; } |
27 | 26 | ||
27 | private IEnumerable<ILayoutExtension> Extensions { get; } | ||
28 | |||
28 | private IEnumerable<IFileTransfer> FileTransfers { get; } | 29 | private IEnumerable<IFileTransfer> FileTransfers { get; } |
29 | 30 | ||
30 | private bool SuppressAclReset { get; } | 31 | private bool SuppressAclReset { get; } |
31 | 32 | ||
32 | public void Execute() | 33 | public void Execute() |
33 | { | 34 | { |
34 | List<string> destinationFiles = new List<string>(); | 35 | var destinationFiles = new List<string>(); |
35 | 36 | ||
36 | foreach (var fileTransfer in this.FileTransfers) | 37 | foreach (var fileTransfer in this.FileTransfers) |
37 | { | 38 | { |
@@ -42,7 +43,7 @@ namespace WixToolset.Core.Bind | |||
42 | continue; | 43 | continue; |
43 | } | 44 | } |
44 | 45 | ||
45 | bool retry = false; | 46 | var retry = false; |
46 | do | 47 | do |
47 | { | 48 | { |
48 | try | 49 | try |
@@ -50,12 +51,12 @@ namespace WixToolset.Core.Bind | |||
50 | if (fileTransfer.Move) | 51 | if (fileTransfer.Move) |
51 | { | 52 | { |
52 | this.Messaging.Write(VerboseMessages.MoveFile(fileTransfer.Source, fileTransfer.Destination)); | 53 | this.Messaging.Write(VerboseMessages.MoveFile(fileTransfer.Source, fileTransfer.Destination)); |
53 | this.TransferFile(true, fileTransfer.Source, fileTransfer.Destination); | 54 | this.MoveFile(fileTransfer.Source, fileTransfer.Destination); |
54 | } | 55 | } |
55 | else | 56 | else |
56 | { | 57 | { |
57 | this.Messaging.Write(VerboseMessages.CopyFile(fileTransfer.Source, fileTransfer.Destination)); | 58 | this.Messaging.Write(VerboseMessages.CopyFile(fileTransfer.Source, fileTransfer.Destination)); |
58 | this.TransferFile(false, fileTransfer.Source, fileTransfer.Destination); | 59 | this.CopyFile(fileTransfer.Source, fileTransfer.Destination); |
59 | } | 60 | } |
60 | 61 | ||
61 | retry = false; | 62 | retry = false; |
@@ -73,7 +74,7 @@ namespace WixToolset.Core.Bind | |||
73 | throw; | 74 | throw; |
74 | } | 75 | } |
75 | 76 | ||
76 | string directory = Path.GetDirectoryName(fileTransfer.Destination); | 77 | var directory = Path.GetDirectoryName(fileTransfer.Destination); |
77 | this.Messaging.Write(VerboseMessages.CreateDirectory(directory)); | 78 | this.Messaging.Write(VerboseMessages.CreateDirectory(directory)); |
78 | Directory.CreateDirectory(directory); | 79 | Directory.CreateDirectory(directory); |
79 | retry = true; | 80 | retry = true; |
@@ -91,7 +92,7 @@ namespace WixToolset.Core.Bind | |||
91 | this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); | 92 | this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); |
92 | 93 | ||
93 | // try to ensure the file is not read-only | 94 | // try to ensure the file is not read-only |
94 | FileAttributes attributes = File.GetAttributes(fileTransfer.Destination); | 95 | var attributes = File.GetAttributes(fileTransfer.Destination); |
95 | try | 96 | try |
96 | { | 97 | { |
97 | File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly); | 98 | File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly); |
@@ -131,7 +132,7 @@ namespace WixToolset.Core.Bind | |||
131 | this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); | 132 | this.Messaging.Write(VerboseMessages.RemoveDestinationFile(fileTransfer.Destination)); |
132 | 133 | ||
133 | // ensure the file is not read-only, then delete it | 134 | // ensure the file is not read-only, then delete it |
134 | FileAttributes attributes = File.GetAttributes(fileTransfer.Destination); | 135 | var attributes = File.GetAttributes(fileTransfer.Destination); |
135 | File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly); | 136 | File.SetAttributes(fileTransfer.Destination, attributes & ~FileAttributes.ReadOnly); |
136 | try | 137 | try |
137 | { | 138 | { |
@@ -161,8 +162,6 @@ namespace WixToolset.Core.Bind | |||
161 | 162 | ||
162 | try | 163 | try |
163 | { | 164 | { |
164 | //WixToolset.Core.Native.NativeMethods.ResetAcls(destinationFiles.ToArray(), (uint)destinationFiles.Count); | ||
165 | |||
166 | foreach (var file in destinationFiles) | 165 | foreach (var file in destinationFiles) |
167 | { | 166 | { |
168 | new FileInfo(file).SetAccessControl(aclReset); | 167 | new FileInfo(file).SetAccessControl(aclReset); |
@@ -175,23 +174,30 @@ namespace WixToolset.Core.Bind | |||
175 | } | 174 | } |
176 | } | 175 | } |
177 | 176 | ||
178 | private void TransferFile(bool move, string source, string destination) | 177 | private void CopyFile(string source, string destination) |
179 | { | 178 | { |
180 | bool complete = false; | 179 | foreach (var extension in this.Extensions) |
181 | |||
182 | if (move) | ||
183 | { | 180 | { |
184 | complete = this.FileSystem.MoveFile(source, destination); | 181 | if (extension.CopyFile(source, destination)) |
185 | } | 182 | { |
186 | else | 183 | return; |
187 | { | 184 | } |
188 | complete = this.FileSystem.CopyFile(source, destination); | ||
189 | } | 185 | } |
190 | 186 | ||
191 | if (!complete) | 187 | FileSystem.CopyFile(source, destination, allowHardlink: true); |
188 | } | ||
189 | |||
190 | private void MoveFile(string source, string destination) | ||
191 | { | ||
192 | foreach (var extension in this.Extensions) | ||
192 | { | 193 | { |
193 | throw new InvalidOperationException(); // TODO: something needs to be said here that none of the binder file managers returned a result. | 194 | if (extension.MoveFile(source, destination)) |
195 | { | ||
196 | return; | ||
197 | } | ||
194 | } | 198 | } |
199 | |||
200 | FileSystem.MoveFile(source, destination); | ||
195 | } | 201 | } |
196 | } | 202 | } |
197 | } | 203 | } |
diff --git a/src/WixToolset.Core/Inscriber.cs b/src/WixToolset.Core/Inscriber.cs deleted file mode 100644 index cff2dab2..00000000 --- a/src/WixToolset.Core/Inscriber.cs +++ /dev/null | |||
@@ -1,437 +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 | |||
3 | namespace WixToolset.Core | ||
4 | { | ||
5 | using System.IO; | ||
6 | using WixToolset.Data; | ||
7 | |||
8 | /// <summary> | ||
9 | /// Converts a wixout representation of an MSM database into a ComponentGroup the form of WiX source. | ||
10 | /// </summary> | ||
11 | internal class Inscriber | ||
12 | { | ||
13 | // <summary> | ||
14 | // Gets or sets the temp files collection. | ||
15 | // </summary> | ||
16 | // <value>The temp files collection.</value> | ||
17 | // public TempFileCollection TempFiles | ||
18 | // { | ||
19 | // get { return this.tempFiles; } | ||
20 | // set { this.tempFiles = value; } | ||
21 | // } | ||
22 | |||
23 | /// <summary> | ||
24 | /// Gets or sets the path to the temp files location. | ||
25 | /// </summary> | ||
26 | /// <value>The path to the temp files location.</value> | ||
27 | public string TempFilesLocation | ||
28 | { | ||
29 | get | ||
30 | { | ||
31 | // if (null == this.tempFiles) | ||
32 | // { | ||
33 | // return null; | ||
34 | // } | ||
35 | // else | ||
36 | // { | ||
37 | // return this.tempFiles.BasePath; | ||
38 | // } | ||
39 | return Path.GetTempPath(); | ||
40 | } | ||
41 | // set | ||
42 | // { | ||
43 | // this.DeleteTempFiles(); | ||
44 | |||
45 | // if (null == value) | ||
46 | // { | ||
47 | // this.tempFiles = new TempFileCollection(); | ||
48 | // } | ||
49 | // else | ||
50 | // { | ||
51 | // this.tempFiles = new TempFileCollection(value); | ||
52 | // } | ||
53 | |||
54 | // // ensure the base path exists | ||
55 | // Directory.CreateDirectory(this.tempFiles.BasePath); | ||
56 | // } | ||
57 | } | ||
58 | |||
59 | /// <summary> | ||
60 | /// Extracts engine from attached container and updates engine with detached container signatures. | ||
61 | /// </summary> | ||
62 | /// <param name="bundleFile">Bundle with attached container.</param> | ||
63 | /// <param name="outputFile">Bundle engine only.</param> | ||
64 | /// <returns>True if bundle was updated.</returns> | ||
65 | public bool InscribeBundleEngine(string bundleFile, string outputFile) | ||
66 | { | ||
67 | //string tempFile = Path.Combine(this.TempFilesLocation, "bundle_engine_unsigned.exe"); | ||
68 | |||
69 | //using (BurnReader reader = BurnReader.Open(bundleFile)) | ||
70 | //using (FileStream writer = File.Open(tempFile, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Delete)) | ||
71 | //{ | ||
72 | // reader.Stream.Seek(0, SeekOrigin.Begin); | ||
73 | |||
74 | // byte[] buffer = new byte[4 * 1024]; | ||
75 | // int total = 0; | ||
76 | // int read = 0; | ||
77 | // do | ||
78 | // { | ||
79 | // read = Math.Min(buffer.Length, (int)reader.EngineSize - total); | ||
80 | |||
81 | // read = reader.Stream.Read(buffer, 0, read); | ||
82 | // writer.Write(buffer, 0, read); | ||
83 | |||
84 | // total += read; | ||
85 | // } while (total < reader.EngineSize && 0 < read); | ||
86 | |||
87 | // if (total != reader.EngineSize) | ||
88 | // { | ||
89 | // throw new InvalidOperationException("Failed to copy engine out of bundle."); | ||
90 | // } | ||
91 | |||
92 | // // TODO: update writer with detached container signatures. | ||
93 | //} | ||
94 | |||
95 | //Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); | ||
96 | //if (File.Exists(outputFile)) | ||
97 | //{ | ||
98 | // File.Delete(outputFile); | ||
99 | //} | ||
100 | //File.Move(tempFile, outputFile); | ||
101 | //WixToolset.Core.Native.NativeMethods.ResetAcls(new string[] { outputFile }, 1); | ||
102 | |||
103 | return true; | ||
104 | } | ||
105 | |||
106 | /// <summary> | ||
107 | /// Updates engine with attached container information and adds attached container again. | ||
108 | /// </summary> | ||
109 | /// <param name="bundleFile">Bundle with attached container.</param> | ||
110 | /// <param name="signedEngineFile">Signed bundle engine.</param> | ||
111 | /// <param name="outputFile">Signed engine with attached container.</param> | ||
112 | /// <returns>True if bundle was updated.</returns> | ||
113 | public bool InscribeBundle(string bundleFile, string signedEngineFile, string outputFile) | ||
114 | { | ||
115 | //bool inscribed = false; | ||
116 | //string tempFile = Path.Combine(this.TempFilesLocation, "bundle_engine_signed.exe"); | ||
117 | |||
118 | //using (BurnReader reader = BurnReader.Open(bundleFile)) | ||
119 | //{ | ||
120 | // File.Copy(signedEngineFile, tempFile, true); | ||
121 | |||
122 | // // If there was an attached container on the original (unsigned) bundle, put it back. | ||
123 | // if (reader.AttachedContainerSize > 0) | ||
124 | // { | ||
125 | // reader.Stream.Seek(reader.AttachedContainerAddress, SeekOrigin.Begin); | ||
126 | |||
127 | // using (BurnWriter writer = BurnWriter.Open(tempFile)) | ||
128 | // { | ||
129 | // writer.RememberThenResetSignature(); | ||
130 | // writer.AppendContainer(reader.Stream, reader.AttachedContainerSize, BurnCommon.Container.Attached); | ||
131 | // inscribed = true; | ||
132 | // } | ||
133 | // } | ||
134 | //} | ||
135 | |||
136 | //Directory.CreateDirectory(Path.GetDirectoryName(outputFile)); | ||
137 | //if (File.Exists(outputFile)) | ||
138 | //{ | ||
139 | // File.Delete(outputFile); | ||
140 | //} | ||
141 | //File.Move(tempFile, outputFile); | ||
142 | //WixToolset.Core.Native.NativeMethods.ResetAcls(new string[] { outputFile }, 1); | ||
143 | |||
144 | //return inscribed; | ||
145 | return false; | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Updates database with signatures from external cabinets. | ||
150 | /// </summary> | ||
151 | /// <param name="databaseFile">Path to MSI database.</param> | ||
152 | /// <param name="outputFile">Ouput for updated MSI database.</param> | ||
153 | /// <param name="tidy">Clean up files.</param> | ||
154 | /// <returns>True if database is updated.</returns> | ||
155 | public bool InscribeDatabase(string databaseFile, string outputFile, bool tidy) | ||
156 | { | ||
157 | //// Keeps track of whether we've encountered at least one signed cab or not - we'll throw a warning if no signed cabs were encountered | ||
158 | //bool foundUnsignedExternals = false; | ||
159 | //bool shouldCommit = false; | ||
160 | |||
161 | //FileAttributes attributes = File.GetAttributes(databaseFile); | ||
162 | //if (FileAttributes.ReadOnly == (attributes & FileAttributes.ReadOnly)) | ||
163 | //{ | ||
164 | // this.OnMessage(WixErrors.ReadOnlyOutputFile(databaseFile)); | ||
165 | // return shouldCommit; | ||
166 | //} | ||
167 | |||
168 | //using (Database database = new Database(databaseFile, OpenDatabase.Transact)) | ||
169 | //{ | ||
170 | // // Just use the English codepage, because the tables we're importing only have binary streams / MSI identifiers / other non-localizable content | ||
171 | // int codepage = 1252; | ||
172 | |||
173 | // // list of certificates for this database (hash/identifier) | ||
174 | // Dictionary<string, string> certificates = new Dictionary<string, string>(); | ||
175 | |||
176 | // // Reset the in-memory tables for this new database | ||
177 | // Table digitalSignatureTable = new Table(null, this.tableDefinitions["MsiDigitalSignature"]); | ||
178 | // Table digitalCertificateTable = new Table(null, this.tableDefinitions["MsiDigitalCertificate"]); | ||
179 | |||
180 | // // If any digital signature records exist that are not of the media type, preserve them | ||
181 | // if (database.TableExists("MsiDigitalSignature")) | ||
182 | // { | ||
183 | // using (View digitalSignatureView = database.OpenExecuteView("SELECT `Table`, `SignObject`, `DigitalCertificate_`, `Hash` FROM `MsiDigitalSignature` WHERE `Table` <> 'Media'")) | ||
184 | // { | ||
185 | // while (true) | ||
186 | // { | ||
187 | // using (Record digitalSignatureRecord = digitalSignatureView.Fetch()) | ||
188 | // { | ||
189 | // if (null == digitalSignatureRecord) | ||
190 | // { | ||
191 | // break; | ||
192 | // } | ||
193 | |||
194 | // Row digitalSignatureRow = null; | ||
195 | // digitalSignatureRow = digitalSignatureTable.CreateRow(null); | ||
196 | |||
197 | // string table = digitalSignatureRecord.GetString(0); | ||
198 | // string signObject = digitalSignatureRecord.GetString(1); | ||
199 | |||
200 | // digitalSignatureRow[0] = table; | ||
201 | // digitalSignatureRow[1] = signObject; | ||
202 | // digitalSignatureRow[2] = digitalSignatureRecord.GetString(2); | ||
203 | |||
204 | // if (false == digitalSignatureRecord.IsNull(3)) | ||
205 | // { | ||
206 | // // Export to a file, because the MSI API's require us to provide a file path on disk | ||
207 | // string hashPath = Path.Combine(this.TempFilesLocation, "MsiDigitalSignature"); | ||
208 | // string hashFileName = string.Concat(table, ".", signObject, ".bin"); | ||
209 | |||
210 | // Directory.CreateDirectory(hashPath); | ||
211 | // hashPath = Path.Combine(hashPath, hashFileName); | ||
212 | |||
213 | // using (FileStream fs = File.Create(hashPath)) | ||
214 | // { | ||
215 | // int bytesRead; | ||
216 | // byte[] buffer = new byte[1024 * 4]; | ||
217 | |||
218 | // while (0 != (bytesRead = digitalSignatureRecord.GetStream(3, buffer, buffer.Length))) | ||
219 | // { | ||
220 | // fs.Write(buffer, 0, bytesRead); | ||
221 | // } | ||
222 | // } | ||
223 | |||
224 | // digitalSignatureRow[3] = hashFileName; | ||
225 | // } | ||
226 | // } | ||
227 | // } | ||
228 | // } | ||
229 | // } | ||
230 | |||
231 | // // If any digital certificates exist, extract and preserve them | ||
232 | // if (database.TableExists("MsiDigitalCertificate")) | ||
233 | // { | ||
234 | // using (View digitalCertificateView = database.OpenExecuteView("SELECT * FROM `MsiDigitalCertificate`")) | ||
235 | // { | ||
236 | // while (true) | ||
237 | // { | ||
238 | // using (Record digitalCertificateRecord = digitalCertificateView.Fetch()) | ||
239 | // { | ||
240 | // if (null == digitalCertificateRecord) | ||
241 | // { | ||
242 | // break; | ||
243 | // } | ||
244 | |||
245 | // string certificateId = digitalCertificateRecord.GetString(1); // get the identifier of the certificate | ||
246 | |||
247 | // // Export to a file, because the MSI API's require us to provide a file path on disk | ||
248 | // string certPath = Path.Combine(this.TempFilesLocation, "MsiDigitalCertificate"); | ||
249 | // Directory.CreateDirectory(certPath); | ||
250 | // certPath = Path.Combine(certPath, string.Concat(certificateId, ".cer")); | ||
251 | |||
252 | // using (FileStream fs = File.Create(certPath)) | ||
253 | // { | ||
254 | // int bytesRead; | ||
255 | // byte[] buffer = new byte[1024 * 4]; | ||
256 | |||
257 | // while (0 != (bytesRead = digitalCertificateRecord.GetStream(2, buffer, buffer.Length))) | ||
258 | // { | ||
259 | // fs.Write(buffer, 0, bytesRead); | ||
260 | // } | ||
261 | // } | ||
262 | |||
263 | // // Add it to our "add to MsiDigitalCertificate" table dictionary | ||
264 | // Row digitalCertificateRow = digitalCertificateTable.CreateRow(null); | ||
265 | // digitalCertificateRow[0] = certificateId; | ||
266 | |||
267 | // // Now set the file path on disk where this binary stream will be picked up at import time | ||
268 | // digitalCertificateRow[1] = string.Concat(certificateId, ".cer"); | ||
269 | |||
270 | // // Load the cert to get it's thumbprint | ||
271 | // X509Certificate cert = X509Certificate.CreateFromCertFile(certPath); | ||
272 | // X509Certificate2 cert2 = new X509Certificate2(cert); | ||
273 | |||
274 | // certificates.Add(cert2.Thumbprint, certificateId); | ||
275 | // } | ||
276 | // } | ||
277 | // } | ||
278 | // } | ||
279 | |||
280 | // using (View mediaView = database.OpenExecuteView("SELECT * FROM `Media`")) | ||
281 | // { | ||
282 | // while (true) | ||
283 | // { | ||
284 | // using (Record mediaRecord = mediaView.Fetch()) | ||
285 | // { | ||
286 | // if (null == mediaRecord) | ||
287 | // { | ||
288 | // break; | ||
289 | // } | ||
290 | |||
291 | // X509Certificate2 cert2 = null; | ||
292 | // Row digitalSignatureRow = null; | ||
293 | |||
294 | // string cabName = mediaRecord.GetString(4); // get the name of the cab | ||
295 | // // If there is no cabinet or it's an internal cab, skip it. | ||
296 | // if (String.IsNullOrEmpty(cabName) || cabName.StartsWith("#", StringComparison.Ordinal)) | ||
297 | // { | ||
298 | // continue; | ||
299 | // } | ||
300 | |||
301 | // string cabId = mediaRecord.GetString(1); // get the ID of the cab | ||
302 | // string cabPath = Path.Combine(Path.GetDirectoryName(databaseFile), cabName); | ||
303 | |||
304 | // // If the cabs aren't there, throw an error but continue to catch the other errors | ||
305 | // if (!File.Exists(cabPath)) | ||
306 | // { | ||
307 | // this.OnMessage(WixErrors.WixFileNotFound(cabPath)); | ||
308 | // continue; | ||
309 | // } | ||
310 | |||
311 | // try | ||
312 | // { | ||
313 | // // Get the certificate from the cab | ||
314 | // X509Certificate signedFileCert = X509Certificate.CreateFromSignedFile(cabPath); | ||
315 | // cert2 = new X509Certificate2(signedFileCert); | ||
316 | // } | ||
317 | // catch (System.Security.Cryptography.CryptographicException e) | ||
318 | // { | ||
319 | // uint HResult = unchecked((uint)Marshal.GetHRForException(e)); | ||
320 | |||
321 | // // If the file has no cert, continue, but flag that we found at least one so we can later give a warning | ||
322 | // if (0x80092009 == HResult) // CRYPT_E_NO_MATCH | ||
323 | // { | ||
324 | // foundUnsignedExternals = true; | ||
325 | // continue; | ||
326 | // } | ||
327 | |||
328 | // // todo: exactly which HRESULT corresponds to this issue? | ||
329 | // // If it's one of these exact platforms, warn the user that it may be due to their OS. | ||
330 | // if ((5 == Environment.OSVersion.Version.Major && 2 == Environment.OSVersion.Version.Minor) || // W2K3 | ||
331 | // (5 == Environment.OSVersion.Version.Major && 1 == Environment.OSVersion.Version.Minor)) // XP | ||
332 | // { | ||
333 | // this.OnMessage(WixErrors.UnableToGetAuthenticodeCertOfFileDownlevelOS(cabPath, String.Format(CultureInfo.InvariantCulture, "HRESULT: 0x{0:x8}", HResult))); | ||
334 | // } | ||
335 | // else // otherwise, generic error | ||
336 | // { | ||
337 | // this.OnMessage(WixErrors.UnableToGetAuthenticodeCertOfFile(cabPath, String.Format(CultureInfo.InvariantCulture, "HRESULT: 0x{0:x8}", HResult))); | ||
338 | // } | ||
339 | // } | ||
340 | |||
341 | // // If we haven't added this cert to the MsiDigitalCertificate table, set it up to be added | ||
342 | // if (!certificates.ContainsKey(cert2.Thumbprint)) | ||
343 | // { | ||
344 | // // generate a stable identifier | ||
345 | // string certificateGeneratedId = Common.GenerateIdentifier("cer", cert2.Thumbprint); | ||
346 | |||
347 | // // Add it to our "add to MsiDigitalCertificate" table dictionary | ||
348 | // Row digitalCertificateRow = digitalCertificateTable.CreateRow(null); | ||
349 | // digitalCertificateRow[0] = certificateGeneratedId; | ||
350 | |||
351 | // // Export to a file, because the MSI API's require us to provide a file path on disk | ||
352 | // string certPath = Path.Combine(this.TempFilesLocation, "MsiDigitalCertificate"); | ||
353 | // Directory.CreateDirectory(certPath); | ||
354 | // certPath = Path.Combine(certPath, string.Concat(cert2.Thumbprint, ".cer")); | ||
355 | // File.Delete(certPath); | ||
356 | |||
357 | // using (BinaryWriter writer = new BinaryWriter(File.Open(certPath, FileMode.Create))) | ||
358 | // { | ||
359 | // writer.Write(cert2.RawData); | ||
360 | // writer.Close(); | ||
361 | // } | ||
362 | |||
363 | // // Now set the file path on disk where this binary stream will be picked up at import time | ||
364 | // digitalCertificateRow[1] = string.Concat(cert2.Thumbprint, ".cer"); | ||
365 | |||
366 | // certificates.Add(cert2.Thumbprint, certificateGeneratedId); | ||
367 | // } | ||
368 | |||
369 | // digitalSignatureRow = digitalSignatureTable.CreateRow(null); | ||
370 | |||
371 | // digitalSignatureRow[0] = "Media"; | ||
372 | // digitalSignatureRow[1] = cabId; | ||
373 | // digitalSignatureRow[2] = certificates[cert2.Thumbprint]; | ||
374 | // } | ||
375 | // } | ||
376 | // } | ||
377 | |||
378 | // if (digitalCertificateTable.Rows.Count > 0) | ||
379 | // { | ||
380 | // database.ImportTable(codepage, digitalCertificateTable, this.TempFilesLocation, true); | ||
381 | // shouldCommit = true; | ||
382 | // } | ||
383 | |||
384 | // if (digitalSignatureTable.Rows.Count > 0) | ||
385 | // { | ||
386 | // database.ImportTable(codepage, digitalSignatureTable, this.TempFilesLocation, true); | ||
387 | // shouldCommit = true; | ||
388 | // } | ||
389 | |||
390 | // // TODO: if we created the table(s), then we should add the _Validation records for them. | ||
391 | |||
392 | // certificates = null; | ||
393 | |||
394 | // // If we did find external cabs but none of them were signed, give a warning | ||
395 | // if (foundUnsignedExternals) | ||
396 | // { | ||
397 | // this.OnMessage(WixWarnings.ExternalCabsAreNotSigned(databaseFile)); | ||
398 | // } | ||
399 | |||
400 | // if (shouldCommit) | ||
401 | // { | ||
402 | // database.Commit(); | ||
403 | // } | ||
404 | //} | ||
405 | |||
406 | //return shouldCommit; | ||
407 | return false; | ||
408 | } | ||
409 | |||
410 | /// <summary> | ||
411 | /// Cleans up the temp files used by the Inscriber. | ||
412 | /// </summary> | ||
413 | /// <returns>True if all files were deleted, false otherwise.</returns> | ||
414 | public bool DeleteTempFiles() | ||
415 | { | ||
416 | #if REDO_IN_NETCORE | ||
417 | if (null == this.tempFiles) | ||
418 | { | ||
419 | return true; // no work to do | ||
420 | } | ||
421 | else | ||
422 | { | ||
423 | bool deleted = Common.DeleteTempFiles(this.TempFilesLocation, this); | ||
424 | |||
425 | if (deleted) | ||
426 | { | ||
427 | ((IDisposable)this.tempFiles).Dispose(); | ||
428 | this.tempFiles = null; // temp files have been deleted, no need to remember this now | ||
429 | } | ||
430 | |||
431 | return deleted; | ||
432 | } | ||
433 | #endif | ||
434 | return true; | ||
435 | } | ||
436 | } | ||
437 | } | ||
diff --git a/src/WixToolset.Core/WixToolset.Core.csproj b/src/WixToolset.Core/WixToolset.Core.csproj index 947c445f..abb9bcb8 100644 --- a/src/WixToolset.Core/WixToolset.Core.csproj +++ b/src/WixToolset.Core/WixToolset.Core.csproj | |||
@@ -16,6 +16,7 @@ | |||
16 | <ItemGroup> | 16 | <ItemGroup> |
17 | <PackageReference Include="WixToolset.Data" Version="4.0.*" /> | 17 | <PackageReference Include="WixToolset.Data" Version="4.0.*" /> |
18 | <PackageReference Include="WixToolset.Extensibility" Version="4.0.*" /> | 18 | <PackageReference Include="WixToolset.Extensibility" Version="4.0.*" /> |
19 | <PackageReference Include="WixToolset.Core.Native" Version="4.0.*" /> | ||
19 | </ItemGroup> | 20 | </ItemGroup> |
20 | 21 | ||
21 | <!-- | 22 | <!-- |