From 5fe443cb1e9a057becd0d35fe0d4e505b560f658 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Fri, 7 Apr 2017 20:43:33 +0200 Subject: [PATCH] UpdateChecker: Use MCat tool instead of NC for connectivity test, which adds IPv6 support and even is a bit faster. --- include/MUtils/UpdateChecker.h | 4 ++-- src/UpdateChecker.cpp | 40 +++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/include/MUtils/UpdateChecker.h b/include/MUtils/UpdateChecker.h index 4bc866c..8673b05 100644 --- a/include/MUtils/UpdateChecker.h +++ b/include/MUtils/UpdateChecker.h @@ -81,7 +81,7 @@ namespace MUtils } update_status_t; - UpdateChecker(const QString &binWGet, const QString &binNC, 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 &binMCat, 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; } @@ -116,7 +116,7 @@ namespace MUtils const quint32 m_installedBuildNo; const QString m_binaryWGet; - const QString m_binaryNC; + const QString m_binaryMCat; const QString m_binaryGnuPG; const QString m_binaryKeys; diff --git a/src/UpdateChecker.cpp b/src/UpdateChecker.cpp index ca3cfa9..c36765b 100644 --- a/src/UpdateChecker.cpp +++ b/src/UpdateChecker.cpp @@ -298,11 +298,11 @@ bool UpdateCheckerInfo::isComplete(void) // Constructor & Destructor //////////////////////////////////////////////////////////// -UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binNC, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode) +UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binMCat, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode) : m_updateInfo(new UpdateCheckerInfo()), m_binaryWGet(binWGet), - m_binaryNC(binNC), + m_binaryMCat(binMCat), m_binaryGnuPG(binGnuPG), m_binaryKeys(binKeys), m_applicationId(applicationId), @@ -541,7 +541,7 @@ bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString log("", "Download okay, checking signature:"); if (checkSignature(outFileVers, outFileSign)) { - log("", "Signature okay, parsing info:"); + log("", "Signature okay, parsing info:", ""); success = parseVersionInfo(outFileVers, updateInfo); } else @@ -562,19 +562,19 @@ bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString bool UpdateChecker::getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign) { - log("Downloading update info:"); - if(!getFile(QString("%1%2" ).arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileVers)) + log("Downloading update info:", ""); + if(getFile(QString("%1%2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileVers)) { - return false; + if (!m_cancelled) + { + log("", "Downloading signature:", ""); + if (getFile(QString("%1%2.sig2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSign)) + { + return true; + } + } } - - log("", "Downloading signature:"); - if(!getFile(QString("%1%2.sig2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSign)) - { - return false; - } - - return true; + return false; } bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo) @@ -692,6 +692,10 @@ bool UpdateChecker::getFile(const QString &url, const QString &outFile, const un { return true; } + if (m_cancelled) + { + break; /*cancelled*/ + } } return false; } @@ -772,13 +776,13 @@ bool UpdateChecker::getFile(const QString &url, const bool forceIp4, const QStri bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMsec) { - log(QString("Connecting to host: %1").arg(hostname)); + log(QString("Connecting to host: %1").arg(hostname), ""); QProcess process; init_process(process, temp_folder()); QStringList args; - args << "-z" << hostname << QString::number(80); + args << "--retry" << QString::number(3) << hostname << QString::number(80); QEventLoop loop; connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit())); @@ -789,7 +793,7 @@ bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMs timer.setSingleShot(true); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - process.start(m_binaryNC, args); + process.start(m_binaryMCat, args); if (!process.waitForStarted()) { @@ -809,7 +813,7 @@ bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMs } if (bTimeOut || m_cancelled) { - qWarning("NC process timed out <-- killing!"); + qWarning("MCat process timed out <-- killing!"); process.kill(); process.waitForFinished(); log(bTimeOut ? "!!! TIMEOUT !!!" : "!!! CANCELLED !!!");