From ea3d18595a610ee07b03f07af4f03cf75b5ab420 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 29 Nov 2017 14:08:08 -0800 Subject: Improved cabinet handling --- src/WixToolset.Core.Native/CabinetFileInfo.cs | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/WixToolset.Core.Native/CabinetFileInfo.cs (limited to 'src/WixToolset.Core.Native/CabinetFileInfo.cs') 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 @@ +// 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. + +namespace WixToolset.Core.Native +{ + using System; + + /// + /// Properties of a file in a cabinet. + /// + public sealed class CabinetFileInfo + { + /// + /// Constructs CabinetFileInfo + /// + /// File Id + /// Size of file + /// Last modified date + /// Last modified time + public CabinetFileInfo(string fileId, int size, int date, int time) + { + this.FileId = fileId; + this.Size = size; + this.Date = date; + this.Time = time; + } + + /// + /// Gets the file Id of the file. + /// + /// file Id + public string FileId { get; } + + /// + /// Gets modified date (DOS format). + /// + public int Date { get; } + + /// + /// Gets modified time (DOS format). + /// + public int Time { get; } + + /// + /// Gets the size of the file in bytes. + /// + public int Size { get; } + + /// + /// Compares this file info's date and time with another datetime. + /// + /// Date and time to compare with/ + /// + /// For some reason DateTime.ToLocalTime() does not match kernel32.dll FileTimeToLocalFileTime(). + /// Since cabinets store date and time with the kernel32.dll functions, we need to convert DateTime + /// to local file time using the kernel32.dll functions. + /// + public bool SameAsDateTime(DateTime dateTime) + { + long filetime = dateTime.ToFileTime(); + long localTime = 0; + NativeMethods.FileTimeToLocalFileTime(ref filetime, ref localTime); + NativeMethods.FileTimeToDosDateTime(ref localTime, out var cabDate, out var cabTime); + + return this.Date == cabDate && this.Time == cabTime; + } + } +} -- cgit v1.2.3-55-g6feb