From 2eac767ad2e256248223055bbd8d34379b1eab54 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 16 Aug 2015 16:27:43 +0200 Subject: [PATCH] UpdateChecker: Parse and forward the new "DownloadChecksum" entry from update info file. --- include/MUtils/UpdateChecker.h | 15 +++++++++------ src/UpdateChecker.cpp | 39 ++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/include/MUtils/UpdateChecker.h b/include/MUtils/UpdateChecker.h index c9915a6..ffbaf1c 100644 --- a/include/MUtils/UpdateChecker.h +++ b/include/MUtils/UpdateChecker.h @@ -39,6 +39,7 @@ namespace MUtils public: UpdateCheckerInfo(void); void resetInfo(void); + bool isComplete(void); const quint32 &getBuildNo(void) const { return m_buildNo; } const QDate &getBuildDate(void) const { return m_buildDate; } @@ -46,6 +47,7 @@ namespace MUtils const QString &getDownloadAddress(void) const { return m_downloadAddress; } const QString &getDownloadFilename(void) const { return m_downloadFilename; } const QString &getDownloadFilecode(void) const { return m_downloadFilecode; } + const QString &getDownloadChecksum(void) const { return m_downloadChecksum; } private: quint32 m_buildNo; @@ -54,6 +56,7 @@ namespace MUtils QString m_downloadAddress; QString m_downloadFilename; QString m_downloadFilecode; + QString m_downloadChecksum; }; // ---------------------------------------------------------------- @@ -80,11 +83,11 @@ namespace MUtils UpdateChecker(const QString &binWGet, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false); ~UpdateChecker(void); - const int getUpdateStatus(void) const { return m_status; } - const bool getSuccess(void) const { return m_success; }; - const int getMaximumProgress(void) const { return m_maxProgress; }; - const int getCurrentProgress(void) const { return m_progress; }; - const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo; } + const int getUpdateStatus(void) const { return m_status; } + const bool getSuccess(void) const { return m_success; }; + const int getMaximumProgress(void) const { return m_maxProgress; }; + const int getCurrentProgress(void) const { return m_progress; }; + const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); } protected: void run(void); @@ -98,7 +101,7 @@ namespace MUtils private: const int m_maxProgress; - UpdateCheckerInfo *const m_updateInfo; + QScopedPointer m_updateInfo; const bool m_betaUpdates; const bool m_testMode; diff --git a/src/UpdateChecker.cpp b/src/UpdateChecker.cpp index ddb352b..9942c77 100644 --- a/src/UpdateChecker.cpp +++ b/src/UpdateChecker.cpp @@ -207,6 +207,20 @@ void UpdateCheckerInfo::resetInfo(void) m_downloadAddress.clear(); m_downloadFilename.clear(); m_downloadFilecode.clear(); + m_downloadChecksum.clear(); +} + +bool UpdateCheckerInfo::isComplete(void) +{ + if(this->m_buildNo < 1) return false; + if(this->m_buildDate.year() < 2010) return false; + if(this->m_downloadSite.isEmpty()) return false; + if(this->m_downloadAddress.isEmpty()) return false; + if(this->m_downloadFilename.isEmpty()) return false; + if(this->m_downloadFilecode.isEmpty()) return false; + if(this->m_downloadChecksum.isEmpty()) return false; + + return true; } //////////////////////////////////////////////////////////// @@ -237,7 +251,6 @@ UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binGnuPG, co UpdateChecker::~UpdateChecker(void) { - delete m_updateInfo; } //////////////////////////////////////////////////////////// @@ -340,7 +353,7 @@ void UpdateChecker::checkForUpdates(void) setProgress(m_progress + 1); if(!m_success) { - if(tryUpdateMirror(m_updateInfo, currentMirror)) + if(tryUpdateMirror(m_updateInfo.data(), currentMirror)) { m_success = true; } @@ -669,12 +682,12 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd if(value.cap(1).compare("BuildNo", Qt::CaseInsensitive) == 0) { bool ok = false; - unsigned int temp = value.cap(2).toUInt(&ok); + const unsigned int temp = value.cap(2).toUInt(&ok); if(ok) updateInfo->m_buildNo = temp; } else if(value.cap(1).compare("BuildDate", Qt::CaseInsensitive) == 0) { - QDate temp = QDate::fromString(value.cap(2).trimmed(), Qt::ISODate); + const QDate temp = QDate::fromString(value.cap(2).trimmed(), Qt::ISODate); if(temp.isValid()) updateInfo->m_buildDate = temp; } else if(value.cap(1).compare("DownloadSite", Qt::CaseInsensitive) == 0) @@ -693,6 +706,10 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd { updateInfo->m_downloadFilecode = value.cap(2).trimmed(); } + else if(value.cap(1).compare("DownloadChecksum", Qt::CaseInsensitive) == 0) + { + updateInfo->m_downloadChecksum = value.cap(2).trimmed(); + } } if(inHdr && (value.indexIn(line) >= 0)) { @@ -724,22 +741,14 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd log("Version info is from the future, take care!"); qWarning("Version info is from the future, take care!"); } - - bool complete = true; - - if(!(updateInfo->m_buildNo > 0)) complete = false; - if(!(updateInfo->m_buildDate.year() >= 2010)) complete = false; - if(updateInfo->m_downloadSite.isEmpty()) complete = false; - if(updateInfo->m_downloadAddress.isEmpty()) complete = false; - if(updateInfo->m_downloadFilename.isEmpty()) complete = false; - if(updateInfo->m_downloadFilecode.isEmpty()) complete = false; - if(!complete) + if(!updateInfo->isComplete()) { log("WARNING: Version info is incomplete!"); + return false; } - return complete; + return true; } //////////////////////////////////////////////////////////// -- 2.11.4.GIT