| 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.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 | DateTimeInterop.DateTimeToCabDateAndTime(dateTime, out var cabDate, out var cabTime); |
| 60 | return this.Date == cabDate && this.Time == cabTime; |
| 61 | } |
| 62 | } |
| 63 | } |