From 3a7129cbf437c17569fe97d74e98dad2fd9ed94d Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sun, 10 Jul 2011 21:46:43 +0200 Subject: [PATCH] Check InternetGetConnectedState() in an asynchronous way + update list of mirrors. --- src/Config.h | 4 ++-- src/Dialog_Update.cpp | 55 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/Config.h b/src/Config.h index 9f434a73..3767bcb5 100644 --- a/src/Config.h +++ b/src/Config.h @@ -29,8 +29,8 @@ #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_TYPE Alpha -#define VER_LAMEXP_PATCH 2 -#define VER_LAMEXP_BUILD 595 +#define VER_LAMEXP_PATCH 3 +#define VER_LAMEXP_BUILD 599 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Dialog_Update.cpp b/src/Dialog_Update.cpp index a1118c2c..a32d9c0d 100644 --- a/src/Dialog_Update.cpp +++ b/src/Dialog_Update.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -54,14 +55,20 @@ static const char *mirror_url_postfix[] = NULL }; -static const char *update_mirrors[] = +static const char *update_mirrors_prim[] = { - "http://mulder.dummwiedeutsch.de/", "http://mulder.brhack.net/", + "http://mulder.bplaced.net/", "http://lamexp.sourceforge.net/", "http://free.pages.at/borschdfresser/", + NULL +}; + +static const char *update_mirrors_back[] = +{ "http://mplayer.savedonthe.net/", "http://www.tricksoft.de/", + "http://mulder.dummwiedeutsch.de/", "http://mplayer.somestuff.org/", NULL }; @@ -110,6 +117,13 @@ static const int MIN_CONNSCORE = 3; static const int VERSION_INFO_EXPIRES_MONTHS = 6; static char *USER_AGENT_STR = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.12) Gecko/20101101 IceCat/3.6.12 (like Firefox/3.6.12)"; +static BOOL getInternetConnectedState(void) +{ + DWORD lpdwFlags = NULL; + BOOL result = InternetGetConnectedState(&lpdwFlags, NULL); + return result; +} + /////////////////////////////////////////////////////////////////////////////// class UpdateInfo @@ -218,7 +232,8 @@ void UpdateDialog::showEvent(QShowEvent *event) int counter = 2; for(int i = 0; known_hosts[i]; i++) counter++; - for(int i = 0; update_mirrors[i]; i++) counter++; + for(int i = 0; update_mirrors_prim[i]; i++) counter++; + for(int i = 0; update_mirrors_back[i]; i++) counter++; progressBar->setMaximum(counter); progressBar->setValue(0); @@ -262,6 +277,8 @@ void UpdateDialog::checkForUpdates(void) bool success = false; int connectionScore = 0; + // ----- Initialization ----- // + m_updateInfo = new UpdateInfo; progressBar->setValue(0); @@ -279,13 +296,20 @@ void UpdateDialog::checkForUpdates(void) QApplication::processEvents(); QApplication::setOverrideCursor(Qt::WaitCursor); + // ----- Test Internet Connection ----- // + statusLabel->setText(tr("Testing your internet connection, please wait...")); m_logFile->clear(); m_logFile->append("Checking internet connection..."); + + QFuture connectedState = QtConcurrent::run(getInternetConnectedState); + while(!connectedState.isFinished()) + { + QApplication::processEvents(QEventLoop::WaitForMoreEvents); + } - DWORD inetFlags = NULL; - if(!InternetGetConnectedState(&inetFlags, NULL)) + if(!connectedState.result()) { m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!"); if(!retryButton->isVisible()) retryButton->show(); @@ -309,6 +333,8 @@ void UpdateDialog::checkForUpdates(void) return; } + // ----- Test Known Hosts Connectivity ----- // + QStringList hostList; for(int i = 0; known_hosts[i]; i++) { @@ -360,21 +386,30 @@ void UpdateDialog::checkForUpdates(void) return; } + // ----- Build Mirror List ----- // + statusLabel->setText(tr("Checking for new updates online, please wait...")); m_logFile->append(QStringList() << "" << "----" << "" << "Checking for updates online..."); QStringList mirrorList; - for(int i = 0; update_mirrors[i]; i++) + for(int index = 0; update_mirrors_prim[index]; index++) { - mirrorList << QString::fromLatin1(update_mirrors[i]); + mirrorList << QString::fromLatin1(update_mirrors_prim[index]); } qsrand(time(NULL)); - for(int i = 0; i < 16; i++) + for(int i = 0; i < 64; i++) { - mirrorList.swap(i % 4, qrand() % 4); + mirrorList.swap(i % mirrorList.count(), qrand() % mirrorList.count()); } + for(int index = 0; update_mirrors_back[index]; index++) + { + mirrorList << QString::fromLatin1(update_mirrors_back[index]); + } + + // ----- Fetch Update Info From Server ----- // + while(!mirrorList.isEmpty()) { QString currentMirror = mirrorList.takeFirst(); @@ -417,6 +452,8 @@ void UpdateDialog::checkForUpdates(void) return; } + // ----- Download New Program Version ----- // + labelVersionLatest->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(m_updateInfo->m_buildNo), m_updateInfo->m_buildDate.toString(Qt::ISODate))); infoLabel->show(); infoLabel->setText(QString("%1
%2").arg(tr("More information available at:"), m_updateInfo->m_downloadSite));