2016-03-19 06:57:51 +13:00
|
|
|
#include "./toonzqt/updatechecker.h"
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
2016-05-16 17:16:01 +12:00
|
|
|
UpdateChecker::UpdateChecker(QUrl const& updateUrl)
|
|
|
|
: manager_(new QNetworkAccessManager(this), &QNetworkAccessManager::deleteLater)
|
2016-03-19 06:57:51 +13:00
|
|
|
{
|
2016-05-16 17:16:01 +12:00
|
|
|
connect(manager_.data(), SIGNAL(finished(QNetworkReply*)),
|
|
|
|
this, SLOT(httpRequestFinished(QNetworkReply*)));
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-05-16 17:16:01 +12:00
|
|
|
manager_->get(QNetworkRequest(updateUrl));
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|
|
|
|
|
2016-05-16 17:16:01 +12:00
|
|
|
void UpdateChecker::httpRequestFinished(QNetworkReply *pReply)
|
2016-03-19 06:57:51 +13:00
|
|
|
{
|
2016-05-16 17:16:01 +12:00
|
|
|
QSharedPointer<QNetworkReply> reply(pReply, &QNetworkReply::deleteLater);
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-05-16 17:16:01 +12:00
|
|
|
// If there was an error, don't bother doing the check
|
|
|
|
if (reply->error() != QNetworkReply::NoError) {
|
|
|
|
emit done(true);
|
2016-03-19 06:57:51 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:16:01 +12:00
|
|
|
// Convert the response from a QByteArray into a QString
|
|
|
|
QString candidateVersion = QString(reply->readAll()).trimmed();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-05-16 17:16:01 +12:00
|
|
|
// TODO: Verify that the response was valid by ensuring we have a single line in the format x.x[.x]*
|
|
|
|
if (candidateVersion.indexOf(".") < 0) {
|
|
|
|
// There was some invalid response, so we'll ignore the check for now
|
|
|
|
emit done(true);
|
2016-03-19 06:57:51 +13:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:16:01 +12:00
|
|
|
// Completed with no errors
|
|
|
|
m_latestVersion = candidateVersion;
|
|
|
|
emit done(false);
|
2016-03-19 06:57:51 +13:00
|
|
|
}
|