summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNiels Weber <niels.weber@digia.com>2013-05-15 10:22:57 +0200
committerTim Jenssen <tim.jenssen@digia.com>2013-05-30 17:21:14 +0200
commite551301a64d62f121a01c4c2ac051a931c75d5e7 (patch)
treeb57a83df9d7f4df16b53e3b6d3bd23bf645b51ac /src
parenta2371edc51a3837d37bd99a93fc937e99eb34408 (diff)
Implementation of time and date functions related to 7z.
Change-Id: Icb706d829f8470d8cc3cc50925c99255cf5f2b26 Reviewed-by: Karsten Heimrich <karsten.heimrich@digia.com> Reviewed-by: Tim Jenssen <tim.jenssen@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/libs/7zip/7zip.pro2
-rw-r--r--src/libs/7zip/unix/CPP/include_windows/windows.h2
-rw-r--r--src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp95
-rw-r--r--src/libs/installer/lib7z_facade.cpp12
4 files changed, 90 insertions, 21 deletions
diff --git a/src/libs/7zip/7zip.pro b/src/libs/7zip/7zip.pro
index d09cbf9a5..549778e67 100644
--- a/src/libs/7zip/7zip.pro
+++ b/src/libs/7zip/7zip.pro
@@ -1,6 +1,6 @@
include(../../../installerfw.pri)
-QT =
+QT = core
TARGET = 7z
TEMPLATE = lib
INCLUDEPATH += . ..
diff --git a/src/libs/7zip/unix/CPP/include_windows/windows.h b/src/libs/7zip/unix/CPP/include_windows/windows.h
index 871d9f3ae..5223e81ac 100644
--- a/src/libs/7zip/unix/CPP/include_windows/windows.h
+++ b/src/libs/7zip/unix/CPP/include_windows/windows.h
@@ -142,6 +142,8 @@ typedef struct _SYSTEMTIME {
extern "C" {
#endif
+BOOL WINAPI FileTimeToLocalFileTime(CONST FILETIME *,FILETIME *);
+//BOOL WINAPI LocalFileTimeToFileTime(CONST FILETIME *,FILETIME *);
BOOL WINAPI FileTimeToSystemTime(CONST FILETIME *,SYSTEMTIME *);
VOID WINAPI GetSystemTime(SYSTEMTIME *);
BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME*,FILETIME *);
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 <time.h>
+#include <QDebug>
+#include <QDateTime>
#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);
}
diff --git a/src/libs/installer/lib7z_facade.cpp b/src/libs/installer/lib7z_facade.cpp
index 607d774ac..a818e9a61 100644
--- a/src/libs/installer/lib7z_facade.cpp
+++ b/src/libs/installer/lib7z_facade.cpp
@@ -257,10 +257,6 @@ static bool IsDST(const QDateTime& datetime = QDateTime())
static bool getFileTimeFromProperty(IInArchive* archive, int index, int propId, FILETIME *fileTime)
{
-// TODO: fix getFileTimeFromProperty under unix systems, till then just ignore the property
-#ifndef Q_OS_WIN
- return false;
-#endif
const NCOM::CPropVariant prop = readProperty(archive, index, propId);
if (prop.vt != VT_FILETIME) {
throw SevenZipException(QObject::tr("Property %1 for item %2 not of type VT_FILETIME but %3")
@@ -281,12 +277,8 @@ QDateTime getDateTimeProperty(IInArchive* archive, int index, int propId, const
return defaultValue;
FILETIME localFileTime;
-#ifndef Q_OS_UNIX
- if (!FileTimeToLocalFileTime(&fileTime, &localFileTime))
- throw SevenZipException(QObject::tr("Could not convert file time to local time"));
-#else
- localFileTime = fileTime;
-#endif
+ if (!FileTimeToLocalFileTime(&fileTime, &localFileTime))
+ throw SevenZipException(QObject::tr("Could not convert file time to local time"));
SYSTEMTIME st;
if (!BOOLToBool(FileTimeToSystemTime(&localFileTime, &st)))