From e62434acc6c6e41bbafd3f1d46b2ed2011a9ad98 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 19 Mar 2021 07:34:49 -0700 Subject: Remove a bunch of dead code related to winterop.dll --- src/WixToolset.Core.Native/DateTimeInterop.cs | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/WixToolset.Core.Native/DateTimeInterop.cs (limited to 'src/WixToolset.Core.Native/DateTimeInterop.cs') diff --git a/src/WixToolset.Core.Native/DateTimeInterop.cs b/src/WixToolset.Core.Native/DateTimeInterop.cs new file mode 100644 index 00000000..d2a0ba2b --- /dev/null +++ b/src/WixToolset.Core.Native/DateTimeInterop.cs @@ -0,0 +1,48 @@ +// 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; + using System.Runtime.InteropServices; + + /// + /// Interop class for the date/time handling. + /// + internal static class DateTimeInterop + { + /// + /// Converts DateTime to MS-DOS date and time which cabinet uses. + /// + /// DateTime + /// MS-DOS date + /// MS-DOS time + public static void DateTimeToCabDateAndTime(DateTime dateTime, out ushort cabDate, out ushort cabTime) + { + // dateTime.ToLocalTime() does not match FileTimeToLocalFileTime() for some reason. + // so we need to call FileTimeToLocalFileTime() from kernel32.dll. + long filetime = dateTime.ToFileTime(); + long localTime = 0; + FileTimeToLocalFileTime(ref filetime, ref localTime); + FileTimeToDosDateTime(ref localTime, out cabDate, out cabTime); + } + + /// + /// Converts file time to a local file time. + /// + /// file time + /// local file time + /// true if successful, false otherwise + [DllImport("kernel32.dll", SetLastError = true)] + private static extern bool FileTimeToLocalFileTime(ref long fileTime, ref long localTime); + + /// + /// Converts file time to a MS-DOS time. + /// + /// file time + /// MS-DOS date + /// MS-DOS time + /// true if successful, false otherwise + [DllImport("kernel32.dll", SetLastError = true)] + private static extern bool FileTimeToDosDateTime(ref long fileTime, out ushort wFatDate, out ushort wFatTime); + } +} -- cgit v1.2.3-55-g6feb