diff options
Diffstat (limited to 'src/libs/7zip/unix/CPP/myWindows')
-rw-r--r-- | src/libs/7zip/unix/CPP/myWindows/StdAfx.h | 89 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/myWindows/config.h | 7 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/myWindows/myCommandLineParser.cpp | 51 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp | 176 | ||||
-rw-r--r-- | src/libs/7zip/unix/CPP/myWindows/myWindows.pri | 7 |
5 files changed, 256 insertions, 74 deletions
diff --git a/src/libs/7zip/unix/CPP/myWindows/StdAfx.h b/src/libs/7zip/unix/CPP/myWindows/StdAfx.h index 629529dcf..86ce117a9 100644 --- a/src/libs/7zip/unix/CPP/myWindows/StdAfx.h +++ b/src/libs/7zip/unix/CPP/myWindows/StdAfx.h @@ -6,6 +6,7 @@ #include "config.h" +#define MAXIMUM_WAIT_OBJECTS 64 #define NO_INLINE /* FIXME */ @@ -13,15 +14,16 @@ #include <pthread.h> #endif +#include "Common/Common.h" #include "Common/MyWindows.h" -#include "Common/Types.h" +#include "Common/MyTypes.h" -#include <windows.h> +#include "../include_windows/tchar.h" +#include "../include_windows/windows.h" #include <stdio.h> #include <stdlib.h> #include <time.h> -#include <tchar.h> #include <wchar.h> #include <stddef.h> #include <ctype.h> @@ -36,6 +38,13 @@ #undef CS /* fix for Solaris 10 x86 */ +#ifdef __cplusplus +# define EXTERN_C extern "C" +#else +# define EXTERN_C extern +#endif + + /***************************/ #ifndef ENV_HAVE_WCHAR__H @@ -87,6 +96,23 @@ typedef wxWindow *HWND; #define MessageBox MessageBoxW int MessageBoxW(wxWindow * parent, const TCHAR * mes, const TCHAR * title,int flag); + +// FIXME +#define IDCLOSE (5001) // wxID_CLOSE +#define IDEXIT (5006) // wxID_EXIT +#define IDOK (5100) // wxID_OK +#define IDCANCEL (5101) // wxID_CANCEL +#define IDABORT (5115) // wxID_ABORT +#define IDYES (5103) // wxID_YES +#define IDNO (5104) // wxID_NO +#define IDHELP (5009) // wxID_HELP + +// Show +#define SW_HIDE 0 +#define SW_SHOW 5 + + + typedef void *HINSTANCE; typedef int INT_PTR; // FIXME 64 bits ? @@ -101,8 +127,63 @@ typedef UINT_PTR WPARAM; typedef LONG_PTR LPARAM; typedef LONG_PTR LRESULT; + +#define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xFFFF)) +#define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16)) + + #define CALLBACK /* */ +#define ERROR_NEGATIVE_SEEK 0x100131 // FIXME +#define FACILITY_WIN32 7 // FIXME +#define __HRESULT_FROM_WIN32(x) ((HRESULT)(x) > 0 ? ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)) : (HRESULT)(x) ) // FIXME + +/************ Windows2.h ***********/ + +typedef void * WNDPROC; +typedef void * CREATESTRUCT; +typedef struct +{ + HWND hwndFrom; + + UINT code; +#define NM_DBLCLK 1 +#define LVN_ITEMCHANGED 2 +#define LVN_COLUMNCLICK 3 +#define CBEN_BEGINEDIT 10 +#define CBEN_ENDEDITW 11 + + +} NMHDR; +typedef NMHDR * LPNMHDR; + +typedef struct tagNMLISTVIEW +{ + NMHDR hdr; + INT iItem; + INT iSubItem; + UINT uNewState; + UINT uOldState; + // UINT uChanged; + // POINT ptAction; + LPARAM lParam; +} NMLISTVIEW, *LPNMLISTVIEW; + +typedef void * LPNMITEMACTIVATE; + +#define NM_RCLICK 1234 /* FIXME */ + +// FIXME +#define WM_CREATE 1 +#define WM_COMMAND 2 +#define WM_NOTIFY 3 +#define WM_DESTROY 4 +#define WM_CLOSE 5 + +#define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16)) +#define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xFFFF)) + + /************ LANG ***********/ typedef WORD LANGID; @@ -120,5 +201,5 @@ LANGID GetSystemDefaultLangID(void); #endif -#endif +#endif diff --git a/src/libs/7zip/unix/CPP/myWindows/config.h b/src/libs/7zip/unix/CPP/myWindows/config.h index 54332aad0..ee7d11882 100644 --- a/src/libs/7zip/unix/CPP/myWindows/config.h +++ b/src/libs/7zip/unix/CPP/myWindows/config.h @@ -24,14 +24,14 @@ #endif /* !ENV_MACOSX && !ENV_BEOS */ - #if !defined(ENV_BEOS) + #if !defined(ENV_BEOS) && !defined(ANDROID_NDK) + #define ENV_HAVE_GETPASS #if !defined(sun) #define ENV_HAVE_TIMEGM #endif - #endif /* lstat, readlink and S_ISLNK */ @@ -52,7 +52,8 @@ #define ENV_HAVE_PTHREAD #endif -#if defined(ENV_MACOSX) +/* ANDROID don't have wcstombs or mbstowcs ? */ +#if defined(ENV_MACOSX) || defined(ANDROID_NDK) #define LOCALE_IS_UTF8 #endif diff --git a/src/libs/7zip/unix/CPP/myWindows/myCommandLineParser.cpp b/src/libs/7zip/unix/CPP/myWindows/myCommandLineParser.cpp new file mode 100644 index 000000000..b4b444392 --- /dev/null +++ b/src/libs/7zip/unix/CPP/myWindows/myCommandLineParser.cpp @@ -0,0 +1,51 @@ +/************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ + +#include "../CPP/Common/MyString.h" + +#include <QStringList> + +namespace NCommandLineParser { + +void SplitCommandLine(const UString &s, UStringVector &parts) +{ + parts.Clear(); + + const QString cmdLine = QString::fromStdWString(static_cast<const wchar_t*>(s)); + const QStringList args = cmdLine.simplified().split(QLatin1Char(' '), QString::SkipEmptyParts); + foreach (const QString &arg, args) + parts.Add(arg.toStdWString().c_str()); +} + +} // namespace NCommandLineParser diff --git a/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp b/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp index b5520e58f..3411bc964 100644 --- a/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp +++ b/src/libs/7zip/unix/CPP/myWindows/myDateAndTime.cpp @@ -31,108 +31,150 @@ ** **************************************************************************/ -#include <QDebug> -#include <QDateTime> #include "windows.h" -void FileTimeToDateTime(const FILETIME *source, QDateTime *target) -{ - ULARGE_INTEGER store; - QDateTime tempDateTime(QDate(1601, 1, 1)); +#include <QDateTime> - store.QuadPart = source->dwHighDateTime; - store.QuadPart = store.QuadPart << 32; - store.QuadPart += source->dwLowDateTime; +#include <chrono> - *target = tempDateTime.addMSecs(store.QuadPart / 10000); -} +/* + MSDN description about FILETIME structure: -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(); -} + The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals + since January 1, 1601 (UTC). + The DeltaToEpochInMsec can be calculated like this: -BOOL WINAPI FileTimeToSystemTime(CONST FILETIME *source,SYSTEMTIME *target) + \code + quint64 delta = quint64(QDateTime(QDate(1601, 1, 1)).msecsTo(QDateTime(QDate(1970, 1, 1)))) + * 10000ULL; + \endcode + + But since the value is static, we use a precalculated number here. +*/ +static const ULONGLONG DeltaToEpochInMsec = 116444736000000000ULL; + +inline void LocalDateTimeToFileTime(const QDateTime &dt, ULONGLONG utcOffsetInMsec, FILETIME *ft) { - QDateTime tempDateTime; - FileTimeToDateTime(source, &tempDateTime); - DateTimeToSystemTime(&tempDateTime, target); + const ULONGLONG msec = dt.toMSecsSinceEpoch() + utcOffsetInMsec; + const ULONGLONG nano100 = (msec * 10000ULL) + DeltaToEpochInMsec; + + ft->dwLowDateTime = nano100; + ft->dwHighDateTime = nano100 >> 32; - return TRUE; } -BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME *source,FILETIME *target) +inline void UTCDateTimeToSystemTime(const QDateTime &dt, SYSTEMTIME *st) { - // TODO: Implementation! - // This doesn't seem to be called at all - - qDebug() << "SystemTimeToFileTime"; + const QDate date = dt.date(); + const QTime time = dt.time(); + + st->wYear = date.year(); + st->wMonth = date.month(); + st->wDayOfWeek = date.dayOfWeek(); + st->wDay = date.day(); + st->wHour = time.hour(); + st->wMinute = time.minute(); + st->wSecond = time.second(); + st->wMilliseconds = time.msec(); +} - target->dwHighDateTime = 0; - target->dwLowDateTime = 0; - qWarning() << Q_FUNC_INFO; +// -- WINAPI +BOOL WINAPI FileTimeToSystemTime(CONST FILETIME *source,SYSTEMTIME *target) +{ + const QDateTime dt = QDateTime(QDate(1601, 1, 1), QTime(0, 0, 0, 1), Qt::UTC).addMSecs + ((ULONGLONG(source->dwLowDateTime) + (ULONGLONG(source->dwHighDateTime) << 32)) / 10000ULL); + UTCDateTimeToSystemTime(dt.toUTC(), target); return TRUE; } BOOL WINAPI FileTimeToLocalFileTime(CONST FILETIME *source,FILETIME *target) { - target->dwHighDateTime = source->dwHighDateTime; - target->dwLowDateTime = source->dwLowDateTime; - - QDateTime tempDateTime; - FileTimeToDateTime(source, &tempDateTime); - - tempDateTime = tempDateTime.toLocalTime(); + const QDateTime dt = QDateTime(QDate(1601, 1, 1), QTime(0, 0, 0, 1), Qt::UTC).addMSecs + ((ULONGLONG(source->dwLowDateTime) + (ULONGLONG(source->dwHighDateTime) << 32)) / 10000ULL); + LocalDateTimeToFileTime(dt.toLocalTime(), ULONGLONG(QDateTime::currentDateTime() + .offsetFromUtc()) * 1000ULL, target); return TRUE; } BOOLEAN WINAPI RtlTimeToSecondsSince1970(const LARGE_INTEGER *Time, DWORD *Seconds) { - 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; + /* + MSDN suggests to implement the function like this: + + 1. Call SystemTimeToFileTime to copy the system time to a FILETIME structure. Call + GetSystemTime to get the current system time to pass to SystemTimeToFileTime. + 2. Copy the contents of the FILETIME structure to a ULARGE_INTEGER structure. + 3. Initialize a SYSTEMTIME structure with the date and time of the first second of + January 1, 1970. + 4. Call SystemTimeToFileTime, passing the SYSTEMTIME structure initialized in Step 3 + to the call. + 5. Copy the contents of the FILETIME structure returned by SystemTimeToFileTime in Step 4 + to a second ULARGE_INTEGER. The copied value should be less than or equal to the value + copied in Step 2. + 6. Subtract the 64-bit value in the ULARGE_INTEGER structure initialized in Step 5 + (January 1, 1970) from the 64-bit value of the ULARGE_INTEGER structure initialized + in Step 2 (the current system time). This produces a value in 100-nanosecond intervals + since January 1, 1970. To convert this value to seconds, divide by 10,000,000. + + We can omit step 1 and 2, cause we get the LARGE_INTEGER passed as function argument. + */ + SYSTEMTIME stFirstSecondOf1979; + stFirstSecondOf1979.wSecond = 1; + stFirstSecondOf1979.wMinute = 0; + stFirstSecondOf1979.wHour = 0; + stFirstSecondOf1979.wDay = 1; + stFirstSecondOf1979.wMonth = 1; + stFirstSecondOf1979.wYear = 1970; + stFirstSecondOf1979.wDayOfWeek = 4; + + FILETIME ftFirstSecondOf1979; + SystemTimeToFileTime(&stFirstSecondOf1979, &ftFirstSecondOf1979); + + LARGE_INTEGER liFirstSecondOf1979; + liFirstSecondOf1979.LowPart = ftFirstSecondOf1979.dwLowDateTime; + liFirstSecondOf1979.HighPart = ftFirstSecondOf1979.dwHighDateTime; + + const ULONGLONG diffNano100 = Time->QuadPart - liFirstSecondOf1979.QuadPart; + *Seconds = diffNano100 / 10000000ULL; return TRUE; } void WINAPI RtlSecondsSince1970ToFileTime(DWORD Seconds, FILETIME *ft) { - QDateTime fileTimeStartDate(QDate(1601, 1, 1)); - quint64 hnseconds = Seconds; - QDateTime sourceDateTime = QDateTime::fromMSecsSinceEpoch(hnseconds * 1000); + const ULONGLONG nano100 = (ULONGLONG(Seconds) * 10000000ULL) + DeltaToEpochInMsec; + ft->dwLowDateTime = nano100; + ft->dwHighDateTime = nano100 >> 32; +} + +VOID WINAPI GetSystemTime(SYSTEMTIME *st) +{ + UTCDateTimeToSystemTime(QDateTime::currentDateTimeUtc(), st); +} - hnseconds = fileTimeStartDate.msecsTo(sourceDateTime); - hnseconds *= 10000; +VOID WINAPI GetSystemTimeAsFileTime(FILETIME *time) +{ + SYSTEMTIME st; + GetSystemTime(&st); + SystemTimeToFileTime(&st, time); +} - ft->dwLowDateTime = hnseconds; - ft->dwHighDateTime = hnseconds >> 32; +DWORD WINAPI GetTickCount() +{ + using namespace std::chrono; + return duration_cast<milliseconds>(steady_clock::now().time_since_epoch()).count(); } -VOID WINAPI GetSystemTime(SYSTEMTIME *st) +BOOL WINAPI SystemTimeToFileTime(const SYSTEMTIME *lpSystemTime, FILETIME *lpFileTime) { - QDateTime nowDateTime = QDateTime::currentDateTimeUtc(); - DateTimeToSystemTime(&nowDateTime, st); + const QDateTime dt(QDate(lpSystemTime->wYear, lpSystemTime->wMonth, lpSystemTime->wDay), + QTime(lpSystemTime->wHour, lpSystemTime->wMinute, lpSystemTime->wSecond, + lpSystemTime->wMilliseconds), Qt::UTC); + + LocalDateTimeToFileTime(dt.toLocalTime(), 0ULL, lpFileTime); + return TRUE; } diff --git a/src/libs/7zip/unix/CPP/myWindows/myWindows.pri b/src/libs/7zip/unix/CPP/myWindows/myWindows.pri new file mode 100644 index 000000000..0875fdb1f --- /dev/null +++ b/src/libs/7zip/unix/CPP/myWindows/myWindows.pri @@ -0,0 +1,7 @@ +HEADERS += $$7ZIP_BASE/CPP/myWindows/StdAfx.h \ + $$7ZIP_BASE/CPP/myWindows/config.h \ + $$7ZIP_BASE/CPP/myWindows/initguid.h \ + $$7ZIP_BASE/CPP/myWindows/myPrivate.h + +SOURCES += $$7ZIP_BASE/CPP/myWindows/myDateAndTime.cpp \ + $$7ZIP_BASE/CPP/myWindows/myCommandLineParser.cpp |