aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Cab/Interop/CabInterop.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Cab/Interop/CabInterop.cs')
-rw-r--r--src/WixToolset.Core/Cab/Interop/CabInterop.cs316
1 files changed, 0 insertions, 316 deletions
diff --git a/src/WixToolset.Core/Cab/Interop/CabInterop.cs b/src/WixToolset.Core/Cab/Interop/CabInterop.cs
deleted file mode 100644
index 6c1ae2c1..00000000
--- a/src/WixToolset.Core/Cab/Interop/CabInterop.cs
+++ /dev/null
@@ -1,316 +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#if false
4
5namespace WixToolset.Cab.Interop
6{
7 using System;
8 using System.Diagnostics.CodeAnalysis;
9 using System.Text;
10 using System.Runtime.InteropServices;
11 using WixToolset.Msi;
12 using WixToolset.Msi.Interop;
13
14 /// <summary>
15 /// The native methods.
16 /// </summary>
17 public sealed class NativeMethods
18 {
19 /// <summary>
20 /// Starts creating a cabinet.
21 /// </summary>
22 /// <param name="cabinetName">Name of cabinet to create.</param>
23 /// <param name="cabinetDirectory">Directory to create cabinet in.</param>
24 /// <param name="maxFiles">Maximum number of files that will be added to cabinet.</param>
25 /// <param name="maxSize">Maximum size of the cabinet.</param>
26 /// <param name="maxThreshold">Maximum threshold in the cabinet.</param>
27 /// <param name="compressionType">Type of compression to use in the cabinet.</param>
28 /// <param name="contextHandle">Handle to opened cabinet.</param>
29 [DllImport("winterop.dll", EntryPoint = "CreateCabBegin", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
30 internal static extern void CreateCabBegin(string cabinetName, string cabinetDirectory, uint maxFiles, uint maxSize, uint maxThreshold, uint compressionType, out IntPtr contextHandle);
31
32 /// <summary>
33 /// Adds a file to an open cabinet.
34 /// </summary>
35 /// <param name="file">Full path to file to add to cabinet.</param>
36 /// <param name="token">Name of file in cabinet.</param>
37 /// <param name="contextHandle">Handle to open cabinet.</param>
38 [DllImport("winterop.dll", EntryPoint = "CreateCabAddFile", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
39 internal static extern void CreateCabAddFile(string file, string token, MsiInterop.MSIFILEHASHINFO fileHash, IntPtr contextHandle);
40
41 /// <summary>
42 /// Closes a cabinet.
43 /// </summary>
44 /// <param name="contextHandle">Handle to open cabinet to close.</param>
45 /// <param name="newCabNamesCallBackAddress">Address of Binder's cabinet split callback</param>
46 [DllImport("winterop.dll", EntryPoint = "CreateCabFinish", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
47 internal static extern void CreateCabFinish(IntPtr contextHandle, IntPtr newCabNamesCallBackAddress);
48
49 /// <summary>
50 /// Cancels cabinet creation.
51 /// </summary>
52 /// <param name="contextHandle">Handle to open cabinet to cancel.</param>
53 [DllImport("winterop.dll", EntryPoint = "CreateCabCancel", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
54 internal static extern void CreateCabCancel(IntPtr contextHandle);
55
56 /// <summary>
57 /// Initializes cabinet extraction.
58 /// </summary>
59 [DllImport("winterop.dll", EntryPoint = "ExtractCabBegin", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
60 internal static extern void ExtractCabBegin();
61
62 /// <summary>
63 /// Extracts files from cabinet.
64 /// </summary>
65 /// <param name="cabinet">Path to cabinet to extract files from.</param>
66 /// <param name="extractDirectory">Directory to extract files to.</param>
67 [DllImport("winterop.dll", EntryPoint = "ExtractCab", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, PreserveSig = false)]
68 internal static extern void ExtractCab(string cabinet, string extractDirectory);
69
70 /// <summary>
71 /// Cleans up after cabinet extraction.
72 /// </summary>
73 [DllImport("winterop.dll", EntryPoint = "ExtractCabFinish", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
74 internal static extern void ExtractCabFinish();
75
76 /// <summary>
77 /// Initializes cabinet enumeration.
78 /// </summary>
79 [DllImport("winterop.dll", EntryPoint = "EnumerateCabBegin", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
80 internal static extern void EnumerateCabBegin();
81
82 /// <summary>
83 /// Enumerates files from cabinet.
84 /// </summary>
85 /// <param name="cabinet">Path to cabinet to enumerate files from.</param>
86 /// <param name="notify">callback that gets each file.</param>
87 [DllImport("winterop.dll", EntryPoint = "EnumerateCab", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true, PreserveSig = false)]
88 internal static extern void EnumerateCab(string cabinet, CabInterop.PFNNOTIFY notify);
89
90 /// <summary>
91 /// Cleans up after cabinet enumeration.
92 /// </summary>
93 [DllImport("winterop.dll", EntryPoint = "EnumerateCabFinish", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
94 internal static extern void EnumerateCabFinish();
95
96 /// <summary>
97 /// Resets the DACL on an array of files to "empty".
98 /// </summary>
99 /// <param name="files">Array of file reset ACL to "empty".</param>
100 /// <param name="fileCount">Number of file paths in array.</param>
101 [DllImport("winterop.dll", EntryPoint = "ResetAcls", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
102 internal static extern void ResetAcls(string[] files, uint fileCount);
103
104 /// <summary>
105 /// Gets the hash of the pCertContext->pCertInfo->SubjectPublicKeyInfo using ::CryptHashPublicKeyInfo() which does not seem
106 /// to be exposed by .NET Frameowkr.
107 /// </summary>
108 /// <param name="certContext">Pointer to a CERT_CONTEXT struct with public key information to hash.</param>
109 /// <param name="fileCount">Number of file paths in array.</param>
110 [DllImport("winterop.dll", EntryPoint = "HashPublicKeyInfo", CharSet = CharSet.Unicode, ExactSpelling = true, PreserveSig = false)]
111 internal static extern void HashPublicKeyInfo(IntPtr certContext, byte[] publicKeyInfoHashed, ref uint sizePublicKeyInfoHashed);
112
113 /// <summary>
114 /// Converts file time to a local file time.
115 /// </summary>
116 /// <param name="fileTime">file time</param>
117 /// <param name="localTime">local file time</param>
118 /// <returns>true if successful, false otherwise</returns>
119 [DllImport("kernel32.dll", SetLastError = true)]
120 [return: MarshalAs(UnmanagedType.Bool)]
121 internal static extern bool FileTimeToLocalFileTime(ref long fileTime, ref long localTime);
122
123 /// <summary>
124 /// Converts file time to a MS-DOS time.
125 /// </summary>
126 /// <param name="fileTime">file time</param>
127 /// <param name="wFatDate">MS-DOS date</param>
128 /// <param name="wFatTime">MS-DOS time</param>
129 /// <returns>true if successful, false otherwise</returns>
130 [DllImport("kernel32.dll", SetLastError = true)]
131 [return: MarshalAs(UnmanagedType.Bool)]
132 internal static extern bool FileTimeToDosDateTime(ref long fileTime, out ushort wFatDate, out ushort wFatTime);
133 }
134
135 /// <summary>
136 /// Interop class for the winterop.dll.
137 /// </summary>
138 internal static class CabInterop
139 {
140 /// <summary>
141 /// Delegate type that's called by cabinet api for every file in cabinet.
142 /// </summary>
143 /// <param name="fdint">NOTIFICATIONTYPE</param>
144 /// <param name="pfdin">NOTIFICATION</param>
145 /// <returns>0 for success, -1 otherwise</returns>
146 public delegate Int32 PFNNOTIFY(NOTIFICATIONTYPE fdint, NOTIFICATION pfdin);
147
148 /// <summary>
149 /// Wraps FDINOTIFICATIONTYPE.
150 /// </summary>
151 public enum NOTIFICATIONTYPE : int
152 {
153 /// <summary>Info about the cabinet.</summary>
154 CABINET_INFO,
155 /// <summary>One or more files are continued.</summary>
156 PARTIAL_FILE,
157 /// <summary>Called for each file in cabinet.</summary>
158 COPY_FILE,
159 /// <summary>Called after all of the data has been written to a target file.</summary>
160 CLOSE_FILE_INFO,
161 /// <summary>A file is continued to the next cabinet.</summary>
162 NEXT_CABINET,
163 /// <summary>Called once after a call to FDICopy() starts scanning a CAB's CFFILE entries, and again when there are no more CFFILE entries.</summary>
164 ENUMERATE,
165 }
166
167 /// <summary>
168 /// Converts DateTime to MS-DOS date and time which cabinet uses.
169 /// </summary>
170 /// <param name="dateTime">DateTime</param>
171 /// <param name="cabDate">MS-DOS date</param>
172 /// <param name="cabTime">MS-DOS time</param>
173 public static void DateTimeToCabDateAndTime(DateTime dateTime, out ushort cabDate, out ushort cabTime)
174 {
175 // dateTime.ToLocalTime() does not match FileTimeToLocalFileTime() for some reason.
176 // so we need to call FileTimeToLocalFileTime() from kernel32.dll.
177 long filetime = dateTime.ToFileTime();
178 long localTime = 0;
179 NativeMethods.FileTimeToLocalFileTime(ref filetime, ref localTime);
180 NativeMethods.FileTimeToDosDateTime(ref localTime, out cabDate, out cabTime);
181 }
182
183 /// <summary>
184 /// Wraps FDINOTIFICATION.
185 /// </summary>
186 [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses")]
187 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
188 public class NOTIFICATION
189 {
190 private int cb;
191 [MarshalAs(UnmanagedType.LPStr)]
192 private string psz1;
193 [MarshalAs(UnmanagedType.LPStr)]
194 private string psz2;
195 [MarshalAs(UnmanagedType.LPStr)]
196 private string psz3;
197 private IntPtr pv;
198
199 private IntPtr hf;
200
201 private ushort date;
202 private ushort time;
203 private ushort attribs;
204 private ushort setID;
205 private ushort cabinet;
206 private ushort folder;
207 private int fdie;
208
209 /// <summary>
210 /// Uncompressed size of file.
211 /// </summary>
212 public int Cb
213 {
214 get { return this.cb; }
215 }
216
217 /// <summary>
218 /// File name in cabinet.
219 /// </summary>
220 public String Psz1
221 {
222 get { return this.psz1; }
223 }
224
225 /// <summary>
226 /// Name of next disk.
227 /// </summary>
228 public string Psz2
229 {
230 get { return this.psz2; }
231 }
232
233 /// <summary>
234 /// Points to a 256 character buffer.
235 /// </summary>
236 public string Psz3
237 {
238 get { return this.psz3; }
239 }
240
241 /// <summary>
242 /// Value for client.
243 /// </summary>
244 public IntPtr Pv
245 {
246 get { return this.pv; }
247 }
248
249 /// <summary>
250 /// Not used.
251 /// </summary>
252 public Int32 Hf
253 {
254 get { return (Int32)this.hf; }
255 }
256
257 /// <summary>
258 /// Last modified MS-DOS date.
259 /// </summary>
260 public ushort Date
261 {
262 get { return this.date; }
263 }
264
265 /// <summary>
266 /// Last modified MS-DOS time.
267 /// </summary>
268 public ushort Time
269 {
270 get { return this.time; }
271 }
272
273 /// <summary>
274 /// File attributes.
275 /// </summary>
276 public ushort Attribs
277 {
278 get { return this.attribs; }
279 }
280
281 /// <summary>
282 /// Cabinet set ID (a random 16-bit number).
283 /// </summary>
284 public ushort SetID
285 {
286 get { return this.setID; }
287 }
288
289 /// <summary>
290 /// Cabinet number within cabinet set (0-based).
291 /// </summary>
292 public ushort Cabinet
293 {
294 get { return this.cabinet; }
295 }
296
297 /// <summary>
298 /// File's folder index.
299 /// </summary>
300 public ushort Folder
301 {
302 get { return this.folder; }
303 }
304
305 /// <summary>
306 /// Error code.
307 /// </summary>
308 public int Fdie
309 {
310 get { return this.fdie; }
311 }
312 }
313 }
314}
315
316#endif