"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/",
"www.citizeninsomniac.com",
"www.cnet.com",
"cnzz.com",
+ "www.cuhk.edu.hk",
"www.codeplex.com",
"www.codeproject.com",
"www.der-postillon.com",
"haali.su",
"www.harvard.edu",
"www.heise.de",
+ "www.helmholtz.de",
"www.huffingtonpost.co.uk",
"www.hu-berlin.de",
"www.iana.org",
"www.imdb.com",
"www.imgburn.com",
"imgur.com",
+ "www.iuj.ac.jp",
"www.jd.com",
"www.jiscdigitalmedia.ac.uk",
"kannmanumdieuhrzeitschonnbierchentrinken.de",
"www.msn.com",
"wiki.multimedia.cx",
"www.nch.com.au",
+ "neocities.org",
"mirror.netcologne.de",
"oss.netfarm.it",
"blog.netflix.com",
};
static const int MIN_CONNSCORE = 5;
-static const int MAX_CONN_TIMEOUT = 8000;
+static const int QUICK_MIRRORS = 3;
+static const int MAX_CONN_TIMEOUT = 8000;
static const int DOWNLOAD_TIMEOUT = 30000;
static const int VERSION_INFO_EXPIRES_MONTHS = 6;
static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0"; /*use something innocuous*/
+#define CHECK_CANCELLED() do \
+{ \
+ if(MUTILS_BOOLIFY(m_cancelled)) \
+ { \
+ m_success.fetchAndStoreOrdered(0); \
+ log("", "Update check has been cancelled by user!"); \
+ setProgress(m_maxProgress); \
+ setStatus(UpdateStatus_CancelledByUser); \
+ return; \
+ } \
+} \
+while(0)
+
////////////////////////////////////////////////////////////
// Helper Functions
////////////////////////////////////////////////////////////
static int getMaxProgress(void)
{
- int counter = MIN_CONNSCORE + 2;
- for(int i = 0; update_mirrors[i]; i++) counter++;
- return counter;
+ int counter = 0;
+ while (update_mirrors[counter])
+ {
+ counter++;
+ }
+ counter += MIN_CONNSCORE + QUICK_MIRRORS + 2;
+ return counter; ;
}
static QStringList buildRandomList(const char *const values[])
// 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),
m_testMode(testMode),
m_maxProgress(getMaxProgress())
{
- m_success = false;
m_status = UpdateStatus_NotStartedYet;
m_progress = 0;
}
////////////////////////////////////////////////////////////
+// Public slots
+////////////////////////////////////////////////////////////
+
+void UpdateChecker::start(Priority priority)
+{
+ m_success.fetchAndStoreOrdered(0);
+ m_cancelled.fetchAndStoreOrdered(0);
+ QThread::start(priority);
+}
+
+////////////////////////////////////////////////////////////
// Protected functions
////////////////////////////////////////////////////////////
{
// ----- Initialization ----- //
- m_success = false;
m_updateInfo->resetInfo();
setProgress(0);
// ----- Test Known Hosts Connectivity ----- //
- int connectionScore = 0, connectionTimout = 125;
- QStringList hostList = buildRandomList(known_hosts);
+ int connectionScore = 0;
+ QStringList mirrorList = buildRandomList(known_hosts);
- while (connectionScore < MIN_CONNSCORE)
+ for(int connectionTimout = 250; connectionTimout <= MAX_CONN_TIMEOUT; connectionTimout *= 2)
{
- connectionTimout *= 2;
- if (connectionTimout > MAX_CONN_TIMEOUT)
- {
- break;
- }
QElapsedTimer elapsedTimer;
- const int globalTimout = 250 + (13 * connectionTimout);
elapsedTimer.start();
+ const int globalTimout = 2 * MIN_CONNSCORE * connectionTimout;
while (!elapsedTimer.hasExpired(globalTimout))
{
- const QString hostName = hostList.takeFirst();
+ const QString hostName = mirrorList.takeFirst();
if (tryContactHost(hostName, connectionTimout))
{
connectionScore += 1;
elapsedTimer.restart();
if (connectionScore >= MIN_CONNSCORE)
{
- break; /*success*/
+ goto endLoop; /*success*/
}
}
else
{
- hostList.append(hostName); /*re-schedule*/
+ mirrorList.append(hostName); /*re-schedule*/
}
+ CHECK_CANCELLED();
msleep(1);
}
}
+endLoop:
if(connectionScore < MIN_CONNSCORE)
{
log("", "Connectivity test has failed: Internet connection appears to be broken!");
log("----", "", "Checking for updates online...");
setStatus(UpdateStatus_FetchingUpdates);
- QStringList mirrorList = buildRandomList(update_mirrors);
+ int mirrorCount = 0;
+ mirrorList = buildRandomList(update_mirrors);
+
while(!mirrorList.isEmpty())
{
- QString currentMirror = mirrorList.takeFirst();
setProgress(m_progress + 1);
- if(!m_success)
+ const QString currentMirror = mirrorList.takeFirst();
+ const bool isQuick = (mirrorCount++ < QUICK_MIRRORS);
+ if(tryUpdateMirror(m_updateInfo.data(), currentMirror, isQuick))
{
- if(tryUpdateMirror(m_updateInfo.data(), currentMirror))
- {
- m_success = true;
- }
+ m_success.ref(); /*success*/
+ break;
}
- else
+ if (isQuick)
{
- msleep(25);
+ mirrorList.append(currentMirror); /*re-schedule*/
}
+ CHECK_CANCELLED();
+ msleep(1);
}
- setProgress(m_maxProgress);
+ while (m_progress < m_maxProgress)
+ {
+ msleep(16);
+ setProgress(m_progress + 1);
+ CHECK_CANCELLED();
+ }
+
+ // ----- Generate final result ----- //
- if(m_success)
+ if(MUTILS_BOOLIFY(m_success))
{
if(m_updateInfo->m_buildNo > m_installedBuildNo)
{
if(!str4.isNull()) emit messageLogged(str4);
}
-bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url)
+bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url, const bool &quick)
{
bool success = false;
log("", "Trying mirror:", url, "");
- if (!tryContactHost(QUrl(url).host(), MAX_CONN_TIMEOUT))
+ if (!tryContactHost(QUrl(url).host(), quick ? (MAX_CONN_TIMEOUT / 10) : MAX_CONN_TIMEOUT))
{
- log("", "Mirror is unreachable!");
+ log("", quick ? "Mirror is too slow!" :"Mirror is unreachable!");
return false;
}
log("", "Download okay, checking signature:");
if (checkSignature(outFileVers, outFileSign))
{
- log("", "Signature okay, parsing info:");
+ log("", "Signature okay, parsing info:", "");
success = parseVersionInfo(outFileVers, updateInfo);
}
else
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)
{
return true;
}
+ if (MUTILS_BOOLIFY(m_cancelled))
+ {
+ break; /*cancelled*/
+ }
}
return false;
}
const QString line = QString::fromLatin1(process.readLine()).simplified();
log(line);
}
- if (bTimeOut)
+ if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
{
qWarning("WGet process timed out <-- killing!");
process.kill();
process.waitForFinished();
- log("!!! TIMEOUT !!!");
+ log(bTimeOut ? "!!! TIMEOUT !!!": "!!! CANCELLED !!!");
return false;
}
}
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()));
timer.setSingleShot(true);
connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
- process.start(m_binaryNC, args);
+ process.start(m_binaryMCat, args);
if (!process.waitForStarted())
{
QString line = QString::fromLatin1(process.readLine()).simplified();
log(line);
}
- if (bTimeOut)
+ if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
{
- qWarning("NC process timed out <-- killing!");
+ qWarning("MCat process timed out <-- killing!");
process.kill();
process.waitForFinished();
- log("!!! TIMEOUT !!!");
+ log(bTimeOut ? "!!! TIMEOUT !!!" : "!!! CANCELLED !!!");
return false;
}
}