From 4d9cd2d9ff0fc13bdaed6872fe974ca451cd1274 Mon Sep 17 00:00:00 2001 From: Syping Date: Thu, 5 Nov 2020 18:32:20 +0100 Subject: [PATCH] Qt6: Avoid timestamp string conversion --- ProfileInterface.cpp | 31 ++++++++++++++++++++++++++----- ProfileLoader.cpp | 4 ++-- SnapmaticPicture.cpp | 24 ++++++++++++++++++++---- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index c7dc7b8..d51847c 100644 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -61,6 +61,7 @@ #include #include +#include #include #include @@ -760,7 +761,11 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime } spJson.createdDateTime = importDateTime; #if QT_VERSION >= 0x060000 - spJson.createdTimestamp = QString::number(spJson.createdDateTime.toSecsSinceEpoch()).toUInt(); + quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); + if (timestamp > UINT32_MAX) { + timestamp = UINT32_MAX; + } + spJson.createdTimestamp = (quint32)timestamp; #else spJson.createdTimestamp = spJson.createdDateTime.toTime_t(); #endif @@ -818,7 +823,11 @@ bool ProfileInterface::importFile(QString selectedFile, QDateTime importDateTime } spJson.createdDateTime = importDateTime; #if QT_VERSION >= 0x060000 - spJson.createdTimestamp = QString::number(spJson.createdDateTime.toSecsSinceEpoch()).toUInt(); + quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); + if (timestamp > UINT32_MAX) { + timestamp = UINT32_MAX; + } + spJson.createdTimestamp = (quint32)timestamp; #else spJson.createdTimestamp = spJson.createdDateTime.toTime_t(); #endif @@ -1067,7 +1076,11 @@ bool ProfileInterface::importImage(QImage *snapmaticImage, QDateTime importDateT } spJson.createdDateTime = importDateTime; #if QT_VERSION >= 0x060000 - spJson.createdTimestamp = QString::number(spJson.createdDateTime.toSecsSinceEpoch()).toUInt(); + quint64 timestamp = spJson.createdDateTime.toSecsSinceEpoch(); + if (timestamp > UINT32_MAX) { + timestamp = UINT32_MAX; + } + spJson.createdTimestamp = (quint32)timestamp; #else spJson.createdTimestamp = spJson.createdDateTime.toTime_t(); #endif @@ -1115,7 +1128,11 @@ bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool wa snapmaticProperties.uid = getRandomUid(); snapmaticProperties.createdDateTime = QDateTime::currentDateTime(); #if QT_VERSION >= 0x060000 - snapmaticProperties.createdTimestamp = QString::number(snapmaticProperties.createdDateTime.toSecsSinceEpoch()).toUInt(); + quint64 timestamp = snapmaticProperties.createdDateTime.toSecsSinceEpoch(); + if (timestamp > UINT32_MAX) { + timestamp = UINT32_MAX; + } + snapmaticProperties.createdTimestamp = (quint32)timestamp; #else snapmaticProperties.createdTimestamp = snapmaticProperties.createdDateTime.toTime_t(); #endif @@ -1156,7 +1173,11 @@ bool ProfileInterface::importSnapmaticPicture(SnapmaticPicture *picture, bool wa snapmaticProperties.uid = getRandomUid(); snapmaticProperties.createdDateTime = QDateTime::currentDateTime(); #if QT_VERSION >= 0x060000 - snapmaticProperties.createdTimestamp = QString::number(snapmaticProperties.createdDateTime.toSecsSinceEpoch()).toUInt(); + quint64 timestamp = snapmaticProperties.createdDateTime.toSecsSinceEpoch(); + if (timestamp > UINT32_MAX) { + timestamp = UINT32_MAX; + } + snapmaticProperties.createdTimestamp = (quint32)timestamp; #else snapmaticProperties.createdTimestamp = snapmaticProperties.createdDateTime.toTime_t(); #endif diff --git a/ProfileLoader.cpp b/ProfileLoader.cpp index 2653338..9a290a0 100644 --- a/ProfileLoader.cpp +++ b/ProfileLoader.cpp @@ -41,10 +41,10 @@ void ProfileLoader::run() profileDir.setPath(profileFolder); // Seek pictures and savegames - profileDir.setNameFilters(QStringList("SGTA*")); + profileDir.setNameFilters(QStringList("SGTA5*")); QStringList SavegameFiles = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort); QStringList BackupFiles = SavegameFiles.filter(".bak", Qt::CaseInsensitive); - profileDir.setNameFilters(QStringList("PGTA*")); + profileDir.setNameFilters(QStringList("PGTA5*")); QStringList SnapmaticPics = profileDir.entryList(QDir::Files | QDir::NoDot, QDir::NoSort); BackupFiles += SnapmaticPics.filter(".bak", Qt::CaseInsensitive); diff --git a/SnapmaticPicture.cpp b/SnapmaticPicture.cpp index a98c182..ed5046b 100644 --- a/SnapmaticPicture.cpp +++ b/SnapmaticPicture.cpp @@ -998,7 +998,7 @@ void SnapmaticPicture::parseJsonContent() QDateTime createdTimestamp; localProperties.createdTimestamp = jsonMap["creat"].toUInt(×tampOk); #if QT_VERSION >= 0x060000 - createdTimestamp.setSecsSinceEpoch(QString::number(localProperties.createdTimestamp).toLongLong()); + createdTimestamp.setSecsSinceEpoch(localProperties.createdTimestamp); #else createdTimestamp.setTime_t(localProperties.createdTimestamp); #endif @@ -1280,9 +1280,25 @@ void SnapmaticPicture::setPicFilePath(const QString &picFilePath_) bool SnapmaticPicture::deletePicFile() { - if (!QFile::exists(picFilePath)) return true; - if (QFile::remove(picFilePath)) return true; - return false; + bool success = false; + if (!QFile::exists(picFilePath)) + { + success = true; + } + else if (QFile::remove(picFilePath)) + { + success = true; + } + if (isHidden()) + { + const QString picBakPath = QString(picFilePath).remove(picFilePath.length() - 7, 7) % ".bak"; + if (QFile::exists(picBakPath)) QFile::remove(picBakPath); + } + else { + const QString picBakPath = picFilePath % ".bak"; + if (QFile::exists(picBakPath)) QFile::remove(picBakPath); + } + return success; } // VISIBILITY