MUtilities development repository
修订版 | 2eac767ad2e256248223055bbd8d34379b1eab54 (tree) |
---|---|
时间 | 2015-08-16 23:27:43 |
作者 | ![]() |
Commiter | LoRd_MuldeR |
UpdateChecker: Parse and forward the new "DownloadChecksum" entry from update info file.
@@ -39,6 +39,7 @@ namespace MUtils | ||
39 | 39 | public: |
40 | 40 | UpdateCheckerInfo(void); |
41 | 41 | void resetInfo(void); |
42 | + bool isComplete(void); | |
42 | 43 | |
43 | 44 | const quint32 &getBuildNo(void) const { return m_buildNo; } |
44 | 45 | const QDate &getBuildDate(void) const { return m_buildDate; } |
@@ -46,6 +47,7 @@ namespace MUtils | ||
46 | 47 | const QString &getDownloadAddress(void) const { return m_downloadAddress; } |
47 | 48 | const QString &getDownloadFilename(void) const { return m_downloadFilename; } |
48 | 49 | const QString &getDownloadFilecode(void) const { return m_downloadFilecode; } |
50 | + const QString &getDownloadChecksum(void) const { return m_downloadChecksum; } | |
49 | 51 | |
50 | 52 | private: |
51 | 53 | quint32 m_buildNo; |
@@ -54,6 +56,7 @@ namespace MUtils | ||
54 | 56 | QString m_downloadAddress; |
55 | 57 | QString m_downloadFilename; |
56 | 58 | QString m_downloadFilecode; |
59 | + QString m_downloadChecksum; | |
57 | 60 | }; |
58 | 61 | |
59 | 62 | // ---------------------------------------------------------------- |
@@ -80,11 +83,11 @@ namespace MUtils | ||
80 | 83 | UpdateChecker(const QString &binWGet, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false); |
81 | 84 | ~UpdateChecker(void); |
82 | 85 | |
83 | - const int getUpdateStatus(void) const { return m_status; } | |
84 | - const bool getSuccess(void) const { return m_success; }; | |
85 | - const int getMaximumProgress(void) const { return m_maxProgress; }; | |
86 | - const int getCurrentProgress(void) const { return m_progress; }; | |
87 | - const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo; } | |
86 | + const int getUpdateStatus(void) const { return m_status; } | |
87 | + const bool getSuccess(void) const { return m_success; }; | |
88 | + const int getMaximumProgress(void) const { return m_maxProgress; }; | |
89 | + const int getCurrentProgress(void) const { return m_progress; }; | |
90 | + const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); } | |
88 | 91 | |
89 | 92 | protected: |
90 | 93 | void run(void); |
@@ -98,7 +101,7 @@ namespace MUtils | ||
98 | 101 | |
99 | 102 | private: |
100 | 103 | const int m_maxProgress; |
101 | - UpdateCheckerInfo *const m_updateInfo; | |
104 | + QScopedPointer<UpdateCheckerInfo> m_updateInfo; | |
102 | 105 | |
103 | 106 | const bool m_betaUpdates; |
104 | 107 | const bool m_testMode; |
@@ -207,6 +207,20 @@ void UpdateCheckerInfo::resetInfo(void) | ||
207 | 207 | m_downloadAddress.clear(); |
208 | 208 | m_downloadFilename.clear(); |
209 | 209 | m_downloadFilecode.clear(); |
210 | + m_downloadChecksum.clear(); | |
211 | +} | |
212 | + | |
213 | +bool UpdateCheckerInfo::isComplete(void) | |
214 | +{ | |
215 | + if(this->m_buildNo < 1) return false; | |
216 | + if(this->m_buildDate.year() < 2010) return false; | |
217 | + if(this->m_downloadSite.isEmpty()) return false; | |
218 | + if(this->m_downloadAddress.isEmpty()) return false; | |
219 | + if(this->m_downloadFilename.isEmpty()) return false; | |
220 | + if(this->m_downloadFilecode.isEmpty()) return false; | |
221 | + if(this->m_downloadChecksum.isEmpty()) return false; | |
222 | + | |
223 | + return true; | |
210 | 224 | } |
211 | 225 | |
212 | 226 | //////////////////////////////////////////////////////////// |
@@ -237,7 +251,6 @@ UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binGnuPG, co | ||
237 | 251 | |
238 | 252 | UpdateChecker::~UpdateChecker(void) |
239 | 253 | { |
240 | - delete m_updateInfo; | |
241 | 254 | } |
242 | 255 | |
243 | 256 | //////////////////////////////////////////////////////////// |
@@ -340,7 +353,7 @@ void UpdateChecker::checkForUpdates(void) | ||
340 | 353 | setProgress(m_progress + 1); |
341 | 354 | if(!m_success) |
342 | 355 | { |
343 | - if(tryUpdateMirror(m_updateInfo, currentMirror)) | |
356 | + if(tryUpdateMirror(m_updateInfo.data(), currentMirror)) | |
344 | 357 | { |
345 | 358 | m_success = true; |
346 | 359 | } |
@@ -669,12 +682,12 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd | ||
669 | 682 | if(value.cap(1).compare("BuildNo", Qt::CaseInsensitive) == 0) |
670 | 683 | { |
671 | 684 | bool ok = false; |
672 | - unsigned int temp = value.cap(2).toUInt(&ok); | |
685 | + const unsigned int temp = value.cap(2).toUInt(&ok); | |
673 | 686 | if(ok) updateInfo->m_buildNo = temp; |
674 | 687 | } |
675 | 688 | else if(value.cap(1).compare("BuildDate", Qt::CaseInsensitive) == 0) |
676 | 689 | { |
677 | - QDate temp = QDate::fromString(value.cap(2).trimmed(), Qt::ISODate); | |
690 | + const QDate temp = QDate::fromString(value.cap(2).trimmed(), Qt::ISODate); | |
678 | 691 | if(temp.isValid()) updateInfo->m_buildDate = temp; |
679 | 692 | } |
680 | 693 | else if(value.cap(1).compare("DownloadSite", Qt::CaseInsensitive) == 0) |
@@ -693,6 +706,10 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd | ||
693 | 706 | { |
694 | 707 | updateInfo->m_downloadFilecode = value.cap(2).trimmed(); |
695 | 708 | } |
709 | + else if(value.cap(1).compare("DownloadChecksum", Qt::CaseInsensitive) == 0) | |
710 | + { | |
711 | + updateInfo->m_downloadChecksum = value.cap(2).trimmed(); | |
712 | + } | |
696 | 713 | } |
697 | 714 | if(inHdr && (value.indexIn(line) >= 0)) |
698 | 715 | { |
@@ -724,22 +741,14 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd | ||
724 | 741 | log("Version info is from the future, take care!"); |
725 | 742 | qWarning("Version info is from the future, take care!"); |
726 | 743 | } |
727 | - | |
728 | - bool complete = true; | |
729 | - | |
730 | - if(!(updateInfo->m_buildNo > 0)) complete = false; | |
731 | - if(!(updateInfo->m_buildDate.year() >= 2010)) complete = false; | |
732 | - if(updateInfo->m_downloadSite.isEmpty()) complete = false; | |
733 | - if(updateInfo->m_downloadAddress.isEmpty()) complete = false; | |
734 | - if(updateInfo->m_downloadFilename.isEmpty()) complete = false; | |
735 | - if(updateInfo->m_downloadFilecode.isEmpty()) complete = false; | |
736 | 744 | |
737 | - if(!complete) | |
745 | + if(!updateInfo->isComplete()) | |
738 | 746 | { |
739 | 747 | log("WARNING: Version info is incomplete!"); |
748 | + return false; | |
740 | 749 | } |
741 | 750 | |
742 | - return complete; | |
751 | + return true; | |
743 | 752 | } |
744 | 753 | |
745 | 754 | //////////////////////////////////////////////////////////// |