UpdateChecker: Parse and forward the new "DownloadChecksum" entry from update info file.

This commit is contained in:
LoRd_MuldeR 2015-08-16 16:27:43 +02:00
parent 4bc32e75c6
commit 2eac767ad2
2 changed files with 33 additions and 21 deletions

View File

@ -39,6 +39,7 @@ namespace MUtils
public: public:
UpdateCheckerInfo(void); UpdateCheckerInfo(void);
void resetInfo(void); void resetInfo(void);
bool isComplete(void);
const quint32 &getBuildNo(void) const { return m_buildNo; } const quint32 &getBuildNo(void) const { return m_buildNo; }
const QDate &getBuildDate(void) const { return m_buildDate; } const QDate &getBuildDate(void) const { return m_buildDate; }
@ -46,6 +47,7 @@ namespace MUtils
const QString &getDownloadAddress(void) const { return m_downloadAddress; } const QString &getDownloadAddress(void) const { return m_downloadAddress; }
const QString &getDownloadFilename(void) const { return m_downloadFilename; } const QString &getDownloadFilename(void) const { return m_downloadFilename; }
const QString &getDownloadFilecode(void) const { return m_downloadFilecode; } const QString &getDownloadFilecode(void) const { return m_downloadFilecode; }
const QString &getDownloadChecksum(void) const { return m_downloadChecksum; }
private: private:
quint32 m_buildNo; quint32 m_buildNo;
@ -54,6 +56,7 @@ namespace MUtils
QString m_downloadAddress; QString m_downloadAddress;
QString m_downloadFilename; QString m_downloadFilename;
QString m_downloadFilecode; 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(const QString &binWGet, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false);
~UpdateChecker(void); ~UpdateChecker(void);
const int getUpdateStatus(void) const { return m_status; } const int getUpdateStatus(void) const { return m_status; }
const bool getSuccess(void) const { return m_success; }; const bool getSuccess(void) const { return m_success; };
const int getMaximumProgress(void) const { return m_maxProgress; }; const int getMaximumProgress(void) const { return m_maxProgress; };
const int getCurrentProgress(void) const { return m_progress; }; const int getCurrentProgress(void) const { return m_progress; };
const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo; } const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); }
protected: protected:
void run(void); void run(void);
@ -98,7 +101,7 @@ namespace MUtils
private: private:
const int m_maxProgress; const int m_maxProgress;
UpdateCheckerInfo *const m_updateInfo; QScopedPointer<UpdateCheckerInfo> m_updateInfo;
const bool m_betaUpdates; const bool m_betaUpdates;
const bool m_testMode; const bool m_testMode;

View File

@ -207,6 +207,20 @@ void UpdateCheckerInfo::resetInfo(void)
m_downloadAddress.clear(); m_downloadAddress.clear();
m_downloadFilename.clear(); m_downloadFilename.clear();
m_downloadFilecode.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) UpdateChecker::~UpdateChecker(void)
{ {
delete m_updateInfo;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -340,7 +353,7 @@ void UpdateChecker::checkForUpdates(void)
setProgress(m_progress + 1); setProgress(m_progress + 1);
if(!m_success) if(!m_success)
{ {
if(tryUpdateMirror(m_updateInfo, currentMirror)) if(tryUpdateMirror(m_updateInfo.data(), currentMirror))
{ {
m_success = true; m_success = true;
} }
@ -669,12 +682,12 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd
if(value.cap(1).compare("BuildNo", Qt::CaseInsensitive) == 0) if(value.cap(1).compare("BuildNo", Qt::CaseInsensitive) == 0)
{ {
bool ok = false; 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; if(ok) updateInfo->m_buildNo = temp;
} }
else if(value.cap(1).compare("BuildDate", Qt::CaseInsensitive) == 0) 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; if(temp.isValid()) updateInfo->m_buildDate = temp;
} }
else if(value.cap(1).compare("DownloadSite", Qt::CaseInsensitive) == 0) 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(); 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)) if(inHdr && (value.indexIn(line) >= 0))
{ {
@ -725,21 +742,13 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd
qWarning("Version info is from the future, take care!"); qWarning("Version info is from the future, take care!");
} }
bool complete = true; if(!updateInfo->isComplete())
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)
{ {
log("WARNING: Version info is incomplete!"); log("WARNING: Version info is incomplete!");
return false;
} }
return complete; return true;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////