// 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;
}
}
}