From e551301a64d62f121a01c4c2ac051a931c75d5e7 Mon Sep 17 00:00:00 2001 From: Niels Weber Date: Wed, 15 May 2013 10:22:57 +0200 Subject: Implementation of time and date functions related to 7z. Change-Id: Icb706d829f8470d8cc3cc50925c99255cf5f2b26 Reviewed-by: Karsten Heimrich Reviewed-by: Tim Jenssen --- src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp | 95 +++++++++++++++++++--- 1 file changed, 85 insertions(+), 10 deletions(-) (limited to 'src/libs/7zip/unix/CPP/myWindows') diff --git a/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp b/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp index 984954979..1773feb86 100644 --- a/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp +++ b/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp @@ -39,33 +39,108 @@ ** **************************************************************************/ -#include +#include +#include #include "windows.h" +void FileTimeToDateTime(const FILETIME *source, QDateTime *target) +{ + ULARGE_INTEGER store; + QDateTime tempDateTime(QDate(1601, 1, 1)); + + store.QuadPart = source->dwHighDateTime; + store.QuadPart = store.QuadPart << 32; + store.QuadPart += source->dwLowDateTime; + + *target = tempDateTime.addMSecs(store.QuadPart / 10000); +} + +void DateTimeToSystemTime(const QDateTime *source, SYSTEMTIME *target) +{ + target->wYear = source->date().year(); + target->wMonth = source->date().month(); + target->wDayOfWeek = source->date().dayOfWeek(); + target->wDay = source->date().day(); + target->wHour = source->time().hour(); + target->wMinute = source->time().minute(); + target->wSecond = source->time().second(); + target->wMilliseconds = source->time().msec(); +} + + BOOL WINAPI FileTimeToSystemTime(CONST FILETIME *source,SYSTEMTIME *target) { - // TODO: Implementation! + QDateTime tempDateTime; + FileTimeToDateTime(source, &tempDateTime); + DateTimeToSystemTime(&tempDateTime, target); + return TRUE; } -BOOLEAN WINAPI RtlTimeToSecondsSince1970(const LARGE_INTEGER *Time, DWORD *Seconds) +BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME *source,FILETIME *target) { // TODO: Implementation! + // This doesn't seem to be called at all + + qDebug() << "SystemTimeToFileTime"; + + target->dwHighDateTime = 0; + target->dwLowDateTime = 0; + + qWarning() << Q_FUNC_INFO; + return TRUE; } -void WINAPI RtlSecondsSince1970ToFileTime(DWORD Seconds, FILETIME *ft) +BOOL WINAPI FileTimeToLocalFileTime(CONST FILETIME *source,FILETIME *target) { - // TODO: Implementation! + target->dwHighDateTime = source->dwHighDateTime; + target->dwLowDateTime = source->dwLowDateTime; + + QDateTime tempDateTime; + FileTimeToDateTime(source, &tempDateTime); + + tempDateTime = tempDateTime.toLocalTime(); + + return TRUE; } -VOID WINAPI GetSystemTime(SYSTEMTIME *st) +BOOLEAN WINAPI RtlTimeToSecondsSince1970(const LARGE_INTEGER *Time, DWORD *Seconds) { - // TODO: Implementation! + SYSTEMTIME tempSystemTime; + FILETIME fileTime; + + fileTime.dwLowDateTime = Time->QuadPart; + fileTime.dwHighDateTime = Time->QuadPart >> 32; + + FileTimeToSystemTime(&fileTime, &tempSystemTime); + + QDate targetDate(tempSystemTime.wYear, tempSystemTime.wMonth, tempSystemTime.wDay); + QTime targetTime(tempSystemTime.wHour, tempSystemTime.wMinute, tempSystemTime.wSecond, tempSystemTime.wMilliseconds); + QDateTime targetDateTime(targetDate, targetTime, Qt::UTC); + + quint64 secsSince1970 = targetDateTime.toMSecsSinceEpoch() / 1000; + + *Seconds = secsSince1970; + + return TRUE; } -BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME *source,FILETIME *target) +void WINAPI RtlSecondsSince1970ToFileTime(DWORD Seconds, FILETIME *ft) { - // TODO: Implementation! - return TRUE; + QDateTime fileTimeStartDate(QDate(1601, 1, 1)); + quint64 hnseconds = Seconds; + QDateTime sourceDateTime = QDateTime::fromMSecsSinceEpoch(hnseconds * 1000); + + hnseconds = fileTimeStartDate.msecsTo(sourceDateTime); + hnseconds *= 10000; + + ft->dwLowDateTime = hnseconds; + ft->dwHighDateTime = hnseconds >> 32; +} + +VOID WINAPI GetSystemTime(SYSTEMTIME *st) +{ + QDateTime nowDateTime = QDateTime::currentDateTimeUtc(); + DateTimeToSystemTime(&nowDateTime, st); } -- cgit v1.2.3