OSDN Git Service

Updated the mirror URL.
[mutilities/MUtilities.git] / src / UpdateChecker.cpp
index 158fba5..d0fdcd7 100644 (file)
@@ -53,7 +53,7 @@ static const char *update_mirrors[] =
        "http://muldersoft.com/",
        "http://mulder.bplaced.net/",
        "http://mulder.6te.net/",
-       "http://mulder.webuda.com/",
+       "http://mulder.000webhostapp.com/",     //"http://mulder.webuda.com/",
        "http://mulder.pe.hu/",
        "http://muldersoft.square7.ch/",
        "http://muldersoft.co.nf/",
@@ -224,9 +224,9 @@ static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/2010
 
 #define CHECK_CANCELLED() do \
 { \
-       if(m_cancelled) \
+       if(MUTILS_BOOLIFY(m_cancelled)) \
        { \
-               m_success = false; \
+               m_success.fetchAndStoreOrdered(0); \
                log("", "Update check has been cancelled by user!"); \
                setProgress(m_maxProgress); \
                setStatus(UpdateStatus_CancelledByUser); \
@@ -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),
@@ -311,7 +311,6 @@ UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binNC, const
        m_testMode(testMode),
        m_maxProgress(getMaxProgress())
 {
-       m_success = m_cancelled = false;
        m_status = UpdateStatus_NotStartedYet;
        m_progress = 0;
 
@@ -331,7 +330,8 @@ UpdateChecker::~UpdateChecker(void)
 
 void UpdateChecker::start(Priority priority)
 {
-       m_cancelled = m_success = false;
+       m_success.fetchAndStoreOrdered(0);
+       m_cancelled.fetchAndStoreOrdered(0);
        QThread::start(priority);
 }
 
@@ -374,7 +374,7 @@ void UpdateChecker::checkForUpdates(void)
        int connectionScore = 0;
        QStringList mirrorList = buildRandomList(known_hosts);
 
-       for(int connectionTimout = 125; connectionTimout <= MAX_CONN_TIMEOUT; connectionTimout *= 2)
+       for(int connectionTimout = 250; connectionTimout <= MAX_CONN_TIMEOUT; connectionTimout *= 2)
        {
                QElapsedTimer elapsedTimer;
                elapsedTimer.start();
@@ -425,7 +425,7 @@ endLoop:
                const bool isQuick = (mirrorCount++ < QUICK_MIRRORS);
                if(tryUpdateMirror(m_updateInfo.data(), currentMirror, isQuick))
                {
-                       m_success = true; /*success*/
+                       m_success.ref(); /*success*/
                        break;
                }
                if (isQuick)
@@ -445,7 +445,7 @@ endLoop:
 
        // ----- Generate final result ----- //
 
-       if(m_success)
+       if(MUTILS_BOOLIFY(m_success))
        {
                if(m_updateInfo->m_buildNo > m_installedBuildNo)
                {
@@ -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;
-       }
-
-       log("", "Downloading signature:");
-       if(!getFile(QString("%1%2.sig2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSign))
-       {
-               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;
+                       }
+               }
        }
-
-       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 (MUTILS_BOOLIFY(m_cancelled))
+               {
+                       break; /*cancelled*/
+               }
        }
        return false;
 }
@@ -753,7 +757,7 @@ bool UpdateChecker::getFile(const QString &url, const bool forceIp4, const QStri
                        const QString line = QString::fromLatin1(process.readLine()).simplified();
                        log(line);
                }
-               if (bTimeOut || m_cancelled)
+               if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
                {
                        qWarning("WGet process timed out <-- killing!");
                        process.kill();
@@ -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())
        {
@@ -807,9 +811,9 @@ bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMs
                        QString line = QString::fromLatin1(process.readLine()).simplified();
                        log(line);
                }
-               if (bTimeOut || m_cancelled)
+               if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
                {
-                       qWarning("NC process timed out <-- killing!");
+                       qWarning("MCat process timed out <-- killing!");
                        process.kill();
                        process.waitForFinished();
                        log(bTimeOut ? "!!! TIMEOUT !!!" : "!!! CANCELLED !!!");