aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.Native/CabinetFileInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixToolset.Core.Native/CabinetFileInfo.cs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/WixToolset.Core.Native/CabinetFileInfo.cs b/src/WixToolset.Core.Native/CabinetFileInfo.cs
new file mode 100644
index 00000000..ea229121
--- /dev/null
+++ b/src/WixToolset.Core.Native/CabinetFileInfo.cs
@@ -0,0 +1,67 @@
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.Core.Native
4{
5 using System;
6
7 /// <summary>
8 /// Properties of a file in a cabinet.
9 /// </summary>
10 public sealed class CabinetFileInfo
11 {
12 /// <summary>
13 /// Constructs CabinetFileInfo
14 /// </summary>
15 /// <param name="fileId">File Id</param>
16 /// <param name="size">Size of file</param>
17 /// <param name="date">Last modified date</param>
18 /// <param name="time">Last modified time</param>
19 public CabinetFileInfo(string fileId, int size, int date, int time)
20 {
21 this.FileId = fileId;
22 this.Size = size;
23 this.Date = date;
24 this.Time = time;
25 }
26
27 /// <summary>
28 /// Gets the file Id of the file.
29 /// </summary>
30 /// <value>file Id</value>
31 public string FileId { get; }
32
33 /// <summary>
34 /// Gets modified date (DOS format).
35 /// </summary>
36 public int Date { get; }
37
38 /// <summary>
39 /// Gets modified time (DOS format).
40 /// </summary>
41 public int Time { get; }
42
43 /// <summary>
44 /// Gets the size of the file in bytes.
45 /// </summary>
46 public int Size { get; }
47
48 /// <summary>
49 /// Compares this file info's date and time with another datetime.
50 /// </summary>
51 /// <param name="dateTime">Date and time to compare with/</param>
52 /// <returns>
53 /// For some reason DateTime.ToLocalTime() does not match kernel32.dll FileTimeToLocalFileTime().
54 /// Since cabinets store date and time with the kernel32.dll functions, we need to convert DateTime
55 /// to local file time using the kernel32.dll functions.
56 /// </returns>
57 public bool SameAsDateTime(DateTime dateTime)
58 {
59 long filetime = dateTime.ToFileTime();
60 long localTime = 0;
61 NativeMethods.FileTimeToLocalFileTime(ref filetime, ref localTime);
62 NativeMethods.FileTimeToDosDateTime(ref localTime, out var cabDate, out var cabTime);
63
64 return this.Date == cabDate && this.Time == cabTime;
65 }
66 }
67}