msecsTo() replacement for Qt < 4.7
This commit is contained in:
parent
a3cd3640b4
commit
b8726ee5c9
3 changed files with 38 additions and 6 deletions
|
@ -239,7 +239,15 @@ static void setNTFSTime(QByteArray &extra, const QDateTime &time, int position,
|
|||
extra[timesPos + 3] = static_cast<char>(ntfsTimesLength >> 8);
|
||||
}
|
||||
QDateTime base(QDate(1601, 1, 1), QTime(0, 0), Qt::UTC);
|
||||
#if (QT_VERSION >= 0x040700)
|
||||
quint64 ticks = base.msecsTo(time) * 10000 + fineTicks;
|
||||
#else
|
||||
QDateTime utc = time.toUTC();
|
||||
quint64 ticks = (static_cast<qint64>(base.date().daysTo(utc.date()))
|
||||
* Q_INT64_C(86400000)
|
||||
+ static_cast<qint64>(base.time().msecsTo(utc.time())))
|
||||
* Q_INT64_C(10000) + fineTicks;
|
||||
#endif
|
||||
extra[timesPos + 4 + position] = static_cast<char>(ticks);
|
||||
extra[timesPos + 5 + position] = static_cast<char>(ticks >> 8);
|
||||
extra[timesPos + 6 + position] = static_cast<char>(ticks >> 16);
|
||||
|
|
|
@ -39,9 +39,21 @@ void TestQuaZipFileInfo::getNTFSTime()
|
|||
QuaZip zip(zipName);
|
||||
QVERIFY(zip.open(QuaZip::mdCreate));
|
||||
QuaZipFile zipFile(&zip);
|
||||
mTicks = base.msecsTo(fileInfo.lastModified()) * 10000;
|
||||
aTicks = base.msecsTo(fileInfo.lastRead()) * 10000;
|
||||
cTicks = base.msecsTo(fileInfo.created()) * 10000;
|
||||
QDateTime lm = fileInfo.lastModified().toUTC();
|
||||
QDateTime lr = fileInfo.lastRead().toUTC();
|
||||
QDateTime cr = fileInfo.created().toUTC();
|
||||
mTicks = (static_cast<qint64>(base.date().daysTo(lm.date()))
|
||||
* Q_UINT64_C(86400000)
|
||||
+ static_cast<qint64>(base.time().msecsTo(lm.time())))
|
||||
* Q_UINT64_C(10000);
|
||||
aTicks = (static_cast<qint64>(base.date().daysTo(lr.date()))
|
||||
* Q_UINT64_C(86400000)
|
||||
+ static_cast<qint64>(base.time().msecsTo(lr.time())))
|
||||
* Q_UINT64_C(10000);
|
||||
cTicks = (static_cast<qint64>(base.date().daysTo(cr.date()))
|
||||
* Q_UINT64_C(86400000)
|
||||
+ static_cast<qint64>(base.time().msecsTo(cr.time())))
|
||||
* Q_UINT64_C(10000);
|
||||
QuaZipNewInfo newInfo("test.txt", "tmp/test.txt");
|
||||
QByteArray extra(36, 0);
|
||||
extra[0] = 0x0A; // magic
|
||||
|
|
|
@ -37,9 +37,21 @@ void TestQuaZipNewInfo::setFileNTFSTimes()
|
|||
QVERIFY(zip.open(QuaZip::mdCreate));
|
||||
QuaZipFile zipFile(&zip);
|
||||
QFileInfo fileInfo("tmp/test.txt");
|
||||
mTicks = base.msecsTo(fileInfo.lastModified()) * 10000;
|
||||
aTicks = base.msecsTo(fileInfo.lastRead()) * 10000;
|
||||
cTicks = base.msecsTo(fileInfo.created()) * 10000;
|
||||
QDateTime lm = fileInfo.lastModified().toUTC();
|
||||
QDateTime lr = fileInfo.lastRead().toUTC();
|
||||
QDateTime cr = fileInfo.created().toUTC();
|
||||
mTicks = (static_cast<qint64>(base.date().daysTo(lm.date()))
|
||||
* Q_UINT64_C(86400000)
|
||||
+ static_cast<qint64>(base.time().msecsTo(lm.time())))
|
||||
* Q_UINT64_C(10000);
|
||||
aTicks = (static_cast<qint64>(base.date().daysTo(lr.date()))
|
||||
* Q_UINT64_C(86400000)
|
||||
+ static_cast<qint64>(base.time().msecsTo(lr.time())))
|
||||
* Q_UINT64_C(10000);
|
||||
cTicks = (static_cast<qint64>(base.date().daysTo(cr.date()))
|
||||
* Q_UINT64_C(86400000)
|
||||
+ static_cast<qint64>(base.time().msecsTo(cr.time())))
|
||||
* Q_UINT64_C(10000);
|
||||
QuaZipNewInfo newInfo("test.txt", "tmp/test.txt");
|
||||
newInfo.setFileNTFSTimes("tmp/test.txt");
|
||||
QVERIFY(zipFile.open(QIODevice::WriteOnly, newInfo));
|
||||
|
|
Loading…
Reference in a new issue