From f47e9c950d41337298ccf13c2b6208962b7bf13b Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sat, 19 Oct 2013 16:00:13 +0200 Subject: [PATCH] Better method to check the network status. --- LameXP_VS2013.vcxproj | 6 ++--- src/Dialog_Update.cpp | 57 +++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/LameXP_VS2013.vcxproj b/LameXP_VS2013.vcxproj index 28f4086b..a8c7f441 100644 --- a/LameXP_VS2013.vcxproj +++ b/LameXP_VS2013.vcxproj @@ -91,7 +91,7 @@ "/MANIFESTDEPENDENCY:type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27 processorArchitecture=%27*%27" %(AdditionalOptions) - QtCored4.lib;QtGuid4.lib;Winmm.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies) + QtCored4.lib;QtGuid4.lib;Winmm.lib;Shlwapi.lib;Sensapi.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies) $(QTDIR)\lib;$(QTDIR)\plugins\imageformats;$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\lib\Win32;$(SolutionDir)\etc\Prerequisites\keccak\lib\$(Configuration);%(AdditionalLibraryDirectories) true Windows @@ -150,7 +150,7 @@ copy /Y "$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\bin\Win32\*.manifes "/MANIFESTDEPENDENCY:type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27 processorArchitecture=%27*%27" %(AdditionalOptions) - QtCore4.lib;QtGui4.lib;Winmm.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies) + QtCore4.lib;QtGui4.lib;Winmm.lib;Shlwapi.lib;Sensapi.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies) LinkVerboseLib @@ -223,7 +223,7 @@ del "$(TargetDir)imageformats\q???d4.dll" "/MANIFESTDEPENDENCY:type=%27win32%27 name=%27Microsoft.Windows.Common-Controls%27 version=%276.0.0.0%27 publicKeyToken=%276595b64144ccf1df%27 language=%27*%27 processorArchitecture=%27*%27" %(AdditionalOptions) - QtCore.lib;QtGui.lib;QtSvg.lib;qtmain.lib;qsvg.lib;qico.lib;qtga.lib;Winmm.lib;imm32.lib;ws2_32.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;EncodePointer.lib;%(AdditionalDependencies) + QtCore.lib;QtGui.lib;QtSvg.lib;qtmain.lib;qsvg.lib;qico.lib;qtga.lib;Winmm.lib;imm32.lib;ws2_32.lib;Shlwapi.lib;Sensapi.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;EncodePointer.lib;%(AdditionalDependencies) LinkVerboseLib $(SolutionDir)\etc\Prerequisites\qt4_static.VS2013\lib;$(SolutionDir)\etc\Prerequisites\qt4_static.VS2013\plugins\imageformats;$(SolutionDir)\etc\Prerequisites\EncodePointer\lib;$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\lib\Win32;$(SolutionDir)\etc\Prerequisites\keccak\lib\$(Configuration);%(AdditionalLibraryDirectories) %(IgnoreSpecificDefaultLibraries) diff --git a/src/Dialog_Update.cpp b/src/Dialog_Update.cpp index a453bdc5..44f9712a 100644 --- a/src/Dialog_Update.cpp +++ b/src/Dialog_Update.cpp @@ -43,6 +43,7 @@ #include #include #include +#include /////////////////////////////////////////////////////////////////////////////// @@ -77,8 +78,6 @@ static const char *update_mirrors_prim[] = static const char *update_mirrors_back[] = { "http://mplayer.savedonthe.net/", - "http://www.rarewares.org/", - "http://lord_mulder.doom9.net/", NULL }; @@ -95,17 +94,19 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites "http://www.babylon.com/", "http://www.baidu.com/", "http://www.bbc.co.uk/", + "http://www.berlios.de/", "http://www.bing.com/", "http://www.cnet.com/", "http://cnzz.com/", "http://codecs.com/", + "http://www.codeplex.com/", "http://qt.digia.com/", "http://www.ebay.com/", "http://www.equation.com/", "http://fc2.com/", "http://www.ffmpeg.org/", "http://www.flickr.com/", - "http://www.gitorious.org/", + "http://blog.gitorious.org/", "http://git-scm.com/", "http://www.gnome.org/", "http://www.gnu.org/", @@ -117,7 +118,7 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites "http://www.imdb.com/", "http://www.imgburn.com/", "http://imgur.com/", - "http://en.jd.com/", //http://en.360buy.com/ + "http://en.jd.com/", "http://mirrors.kernel.org/", "http://www.libav.org/", "http://www.linkedin.com/", @@ -165,6 +166,18 @@ static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/201 /////////////////////////////////////////////////////////////////////////////// +template +T DO_ASYNC(T (*functionPointer)()) +{ + QFutureWatcher watcher; QEventLoop loop; + QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit())); + watcher.setFuture(QtConcurrent::run(functionPointer)); + loop.exec(QEventLoop::ExcludeUserInputEvents); + return watcher.result(); +} + +/////////////////////////////////////////////////////////////////////////////// + class UpdateInfo { public: @@ -339,7 +352,7 @@ void UpdateDialog::updateInit(void) { setMinimumSize(size()); setMaximumHeight(height()); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); checkForUpdates(); } @@ -364,7 +377,7 @@ void UpdateDialog::checkForUpdates(void) if(ui->hintIcon->isVisible()) ui->hintIcon->hide(); ui->frameAnimation->show(); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::setOverrideCursor(Qt::WaitCursor); // ----- Test Internet Connection ----- // @@ -374,13 +387,8 @@ void UpdateDialog::checkForUpdates(void) m_logFile->clear(); m_logFile->append("Checking internet connection..."); - QFuture connectedState = QtConcurrent::run(lamexp_get_connection_state); - while(!connectedState.isFinished()) - { - QApplication::processEvents(QEventLoop::WaitForMoreEvents); - } - - if(!connectedState.result()) + const int networkStatus = DO_ASYNC(lamexp_network_status); + if(networkStatus == lamexp_network_non) { m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!"); if(!ui->retryButton->isVisible()) ui->retryButton->show(); @@ -405,7 +413,7 @@ void UpdateDialog::checkForUpdates(void) } ui->progressBar->setValue(1); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); // ----- Test Known Hosts Connectivity ----- // @@ -428,14 +436,14 @@ void UpdateDialog::checkForUpdates(void) { connectionScore++; ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1)); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); lamexp_sleep(64); } if(httpOk) { connectionScore++; ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1)); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); lamexp_sleep(64); } QFile::remove(outFile); @@ -506,7 +514,7 @@ void UpdateDialog::checkForUpdates(void) } else { - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); lamexp_sleep(64); } } @@ -540,7 +548,7 @@ void UpdateDialog::checkForUpdates(void) ui->labelVersionLatest->setText(QString("%1 %2 (%3)").arg(tr("Build"), QString::number(m_updateInfo->m_buildNo), m_updateInfo->m_buildDate.toString(Qt::ISODate))); ui->infoLabel->show(); ui->infoLabel->setText(QString("%1
%2").arg(tr("More information available at:"), m_updateInfo->m_downloadSite)); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); if(m_updateInfo->m_buildNo > lamexp_version_build()) { @@ -869,7 +877,7 @@ void UpdateDialog::applyUpdate(void) int oldMax = ui->progressBar->maximum(); int oldMin = ui->progressBar->minimum(); ui->progressBar->setRange(0, 0); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QProcess process; QStringList args; @@ -956,7 +964,7 @@ void UpdateDialog::testKnownWebSites(void) if(ui->hintIcon->isVisible()) ui->hintIcon->hide(); ui->frameAnimation->show(); - QApplication::processEvents(); + QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); QApplication::setOverrideCursor(Qt::WaitCursor); // ----- Test Internet Connection ----- // @@ -966,13 +974,8 @@ void UpdateDialog::testKnownWebSites(void) m_logFile->clear(); m_logFile->append("Checking internet connection..."); - QFuture connectedState = QtConcurrent::run(lamexp_get_connection_state); - while(!connectedState.isFinished()) - { - QApplication::processEvents(QEventLoop::WaitForMoreEvents); - } - - if(!connectedState.result()) + const int networkStatus = DO_ASYNC(lamexp_network_status); + if(networkStatus == lamexp_network_non) { m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!"); if(!ui->retryButton->isVisible()) ui->retryButton->show();