diff options
author | Thomas Preud'homme <robotux@celest.fr> | 2017-11-24 23:24:09 +0000 |
---|---|---|
committer | Thomas Preud'homme <robotux@celest.fr> | 2017-11-24 23:24:09 +0000 |
commit | b3c8bdcc0d1e4b2ab298847a7902b6d60410a5bc (patch) | |
tree | 8fce8a51adfb245db8ab2a76831661780c0c713e /InternetUpdater.cpp | |
parent | e297dbd8052ef4e66f069e2dd1865ae7fa8af28e (diff) |
New upstream version 1.2.3.6
Diffstat (limited to 'InternetUpdater.cpp')
-rw-r--r-- | InternetUpdater.cpp | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/InternetUpdater.cpp b/InternetUpdater.cpp new file mode 100644 index 0000000..de23424 --- /dev/null +++ b/InternetUpdater.cpp @@ -0,0 +1,112 @@ +#include "InternetUpdater.h" +#include "EventDispatcher.h" +#include "OptionEngine.h" + +#ifdef ULTRACOPIER_INTERNET_SUPPORT + +#include <QNetworkRequest> +#include <QUrl> + +#include "PluginsManager.h" + +InternetUpdater::InternetUpdater(QObject *parent) : + QObject(parent) +{ + connect(&newUpdateTimer,&QTimer::timeout,this,&InternetUpdater::downloadFile); + connect(&firstUpdateTimer,&QTimer::timeout,this,&InternetUpdater::downloadFile); + newUpdateTimer.start(1000*3600); + firstUpdateTimer.setSingleShot(true); + firstUpdateTimer.start(1000*60); +} + +void InternetUpdater::downloadFile() +{ + if(!OptionEngine::optionEngine->getOptionValue(QStringLiteral("Ultracopier"),QStringLiteral("checkTheUpdate")).toBool()) + return; + #ifdef ULTRACOPIER_MODE_SUPERCOPIER + QString name=QStringLiteral("Supercopier"); + #else + QString name=QStringLiteral("Ultracopier"); + #endif + QString ultracopierVersion; + #ifdef ULTRACOPIER_VERSION_ULTIMATE + ultracopierVersion=QStringLiteral("%1 Ultimate/%2").arg(name).arg(ULTRACOPIER_VERSION); + #else + ultracopierVersion=QStringLiteral("%1/%2").arg(name).arg(ULTRACOPIER_VERSION); + #endif + #ifdef ULTRACOPIER_VERSION_PORTABLE + #ifdef ULTRACOPIER_PLUGIN_ALL_IN_ONE + ultracopierVersion+=QStringLiteral(" portable/all-in-one"); + #else + ultracopierVersion+=QStringLiteral(" portable"); + #endif + #else + #ifdef ULTRACOPIER_PLUGIN_ALL_IN_ONE + ultracopierVersion+=QStringLiteral(" all-in-one"); + #endif + #endif + #ifdef ULTRACOPIER_CGMINER + ultracopierVersion+=QStringLiteral(" miner"); + #endif + #if defined(Q_OS_WIN32) || defined(Q_OS_MAC) + ultracopierVersion+=QStringLiteral(" (OS: %1)").arg(EventDispatcher::GetOSDisplayString()); + #endif + ultracopierVersion+=QStringLiteral(" ")+ULTRACOPIER_PLATFORM_CODE; + QNetworkRequest networkRequest(QStringLiteral(ULTRACOPIER_UPDATER_URL)); + networkRequest.setHeader(QNetworkRequest::UserAgentHeader,ultracopierVersion); + networkRequest.setRawHeader("Connection", "Close"); + reply = qnam.get(networkRequest); + connect(reply, &QNetworkReply::finished, this, &InternetUpdater::httpFinished); +} + +void InternetUpdater::httpFinished() +{ + QVariant redirectionTarget = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); + if (!reply->isFinished()) + { + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("get the new update failed: not finished")); + reply->deleteLater(); + return; + } + else if (reply->error()) + { + newUpdateTimer.stop(); + newUpdateTimer.start(1000*3600*24); + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("get the new update failed: %1").arg(reply->errorString())); + reply->deleteLater(); + return; + } else if (!redirectionTarget.isNull()) { + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Notice,QStringLiteral("redirection denied to: %1").arg(redirectionTarget.toUrl().toString())); + reply->deleteLater(); + return; + } + QString newVersion=QString::fromUtf8(reply->readAll()); + if(newVersion.isEmpty()) + { + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QStringLiteral("version string is empty")); + reply->deleteLater(); + return; + } + newVersion.remove("\n"); + if(!newVersion.contains(QRegularExpression(QLatin1Literal("^[0-9]+(\\.[0-9]+)+$")))) + { + ULTRACOPIER_DEBUGCONSOLE(Ultracopier::DebugLevel_Critical,QStringLiteral("version string don't match: %1").arg(newVersion)); + reply->deleteLater(); + return; + } + if(newVersion==ULTRACOPIER_VERSION) + { + reply->deleteLater(); + return; + } + if(PluginsManager::compareVersion(newVersion,QStringLiteral("<="),ULTRACOPIER_VERSION)) + { + reply->deleteLater(); + return; + } + newUpdateTimer.stop(); + emit newUpdate(newVersion); + reply->deleteLater(); +} + +#endif |