Better method to check the network status.

This commit is contained in:
LoRd_MuldeR 2013-10-19 16:00:13 +02:00
parent e13e6b7fec
commit f47e9c950d
2 changed files with 33 additions and 30 deletions

View File

@ -91,7 +91,7 @@
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalOptions>"/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)</AdditionalOptions> <AdditionalOptions>"/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)</AdditionalOptions>
<AdditionalDependencies>QtCored4.lib;QtGuid4.lib;Winmm.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>QtCored4.lib;QtGuid4.lib;Winmm.lib;Shlwapi.lib;Sensapi.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(QTDIR)\lib;$(QTDIR)\plugins\imageformats;$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\lib\Win32;$(SolutionDir)\etc\Prerequisites\keccak\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(QTDIR)\lib;$(QTDIR)\plugins\imageformats;$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\lib\Win32;$(SolutionDir)\etc\Prerequisites\keccak\lib\$(Configuration);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Windows</SubSystem> <SubSystem>Windows</SubSystem>
@ -150,7 +150,7 @@ copy /Y "$(SolutionDir)\etc\Prerequisites\VisualLeakDetector\bin\Win32\*.manifes
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalOptions>"/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)</AdditionalOptions> <AdditionalOptions>"/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)</AdditionalOptions>
<AdditionalDependencies>QtCore4.lib;QtGui4.lib;Winmm.lib;Shlwapi.lib;Wininet.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>QtCore4.lib;QtGui4.lib;Winmm.lib;Shlwapi.lib;Sensapi.lib;PowrProf.lib;psapi.lib;QKeccakHash_VS2013.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress> <ShowProgress>LinkVerboseLib</ShowProgress>
<Version> <Version>
</Version> </Version>
@ -223,7 +223,7 @@ del "$(TargetDir)imageformats\q???d4.dll"
</ClCompile> </ClCompile>
<Link> <Link>
<AdditionalOptions>"/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)</AdditionalOptions> <AdditionalOptions>"/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)</AdditionalOptions>
<AdditionalDependencies>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)</AdditionalDependencies> <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)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress> <ShowProgress>LinkVerboseLib</ShowProgress>
<AdditionalLibraryDirectories>$(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)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(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)</AdditionalLibraryDirectories>
<IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries> <IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>

View File

@ -43,6 +43,7 @@
#include <QCloseEvent> #include <QCloseEvent>
#include <QMovie> #include <QMovie>
#include <QtConcurrentRun> #include <QtConcurrentRun>
#include <QFutureWatcher>
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -77,8 +78,6 @@ static const char *update_mirrors_prim[] =
static const char *update_mirrors_back[] = static const char *update_mirrors_back[] =
{ {
"http://mplayer.savedonthe.net/", "http://mplayer.savedonthe.net/",
"http://www.rarewares.org/",
"http://lord_mulder.doom9.net/",
NULL NULL
}; };
@ -95,17 +94,19 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites
"http://www.babylon.com/", "http://www.babylon.com/",
"http://www.baidu.com/", "http://www.baidu.com/",
"http://www.bbc.co.uk/", "http://www.bbc.co.uk/",
"http://www.berlios.de/",
"http://www.bing.com/", "http://www.bing.com/",
"http://www.cnet.com/", "http://www.cnet.com/",
"http://cnzz.com/", "http://cnzz.com/",
"http://codecs.com/", "http://codecs.com/",
"http://www.codeplex.com/",
"http://qt.digia.com/", "http://qt.digia.com/",
"http://www.ebay.com/", "http://www.ebay.com/",
"http://www.equation.com/", "http://www.equation.com/",
"http://fc2.com/", "http://fc2.com/",
"http://www.ffmpeg.org/", "http://www.ffmpeg.org/",
"http://www.flickr.com/", "http://www.flickr.com/",
"http://www.gitorious.org/", "http://blog.gitorious.org/",
"http://git-scm.com/", "http://git-scm.com/",
"http://www.gnome.org/", "http://www.gnome.org/",
"http://www.gnu.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.imdb.com/",
"http://www.imgburn.com/", "http://www.imgburn.com/",
"http://imgur.com/", "http://imgur.com/",
"http://en.jd.com/", //http://en.360buy.com/ "http://en.jd.com/",
"http://mirrors.kernel.org/", "http://mirrors.kernel.org/",
"http://www.libav.org/", "http://www.libav.org/",
"http://www.linkedin.com/", "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 <class T>
T DO_ASYNC(T (*functionPointer)())
{
QFutureWatcher<T> 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 class UpdateInfo
{ {
public: public:
@ -339,7 +352,7 @@ void UpdateDialog::updateInit(void)
{ {
setMinimumSize(size()); setMinimumSize(size());
setMaximumHeight(height()); setMaximumHeight(height());
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
checkForUpdates(); checkForUpdates();
} }
@ -364,7 +377,7 @@ void UpdateDialog::checkForUpdates(void)
if(ui->hintIcon->isVisible()) ui->hintIcon->hide(); if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
ui->frameAnimation->show(); ui->frameAnimation->show();
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
// ----- Test Internet Connection ----- // // ----- Test Internet Connection ----- //
@ -374,13 +387,8 @@ void UpdateDialog::checkForUpdates(void)
m_logFile->clear(); m_logFile->clear();
m_logFile->append("Checking internet connection..."); m_logFile->append("Checking internet connection...");
QFuture<bool> connectedState = QtConcurrent::run(lamexp_get_connection_state); const int networkStatus = DO_ASYNC(lamexp_network_status);
while(!connectedState.isFinished()) if(networkStatus == lamexp_network_non)
{
QApplication::processEvents(QEventLoop::WaitForMoreEvents);
}
if(!connectedState.result())
{ {
m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!"); m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!");
if(!ui->retryButton->isVisible()) ui->retryButton->show(); if(!ui->retryButton->isVisible()) ui->retryButton->show();
@ -405,7 +413,7 @@ void UpdateDialog::checkForUpdates(void)
} }
ui->progressBar->setValue(1); ui->progressBar->setValue(1);
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
// ----- Test Known Hosts Connectivity ----- // // ----- Test Known Hosts Connectivity ----- //
@ -428,14 +436,14 @@ void UpdateDialog::checkForUpdates(void)
{ {
connectionScore++; connectionScore++;
ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1)); ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
lamexp_sleep(64); lamexp_sleep(64);
} }
if(httpOk) if(httpOk)
{ {
connectionScore++; connectionScore++;
ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1)); ui->progressBar->setValue(qBound(1, connectionScore + 1, MIN_CONNSCORE + 1));
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
lamexp_sleep(64); lamexp_sleep(64);
} }
QFile::remove(outFile); QFile::remove(outFile);
@ -506,7 +514,7 @@ void UpdateDialog::checkForUpdates(void)
} }
else else
{ {
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
lamexp_sleep(64); 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->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->show();
ui->infoLabel->setText(QString("%1<br><a href=\"%2\">%2</a>").arg(tr("More information available at:"), m_updateInfo->m_downloadSite)); ui->infoLabel->setText(QString("%1<br><a href=\"%2\">%2</a>").arg(tr("More information available at:"), m_updateInfo->m_downloadSite));
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
if(m_updateInfo->m_buildNo > lamexp_version_build()) if(m_updateInfo->m_buildNo > lamexp_version_build())
{ {
@ -869,7 +877,7 @@ void UpdateDialog::applyUpdate(void)
int oldMax = ui->progressBar->maximum(); int oldMax = ui->progressBar->maximum();
int oldMin = ui->progressBar->minimum(); int oldMin = ui->progressBar->minimum();
ui->progressBar->setRange(0, 0); ui->progressBar->setRange(0, 0);
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QProcess process; QProcess process;
QStringList args; QStringList args;
@ -956,7 +964,7 @@ void UpdateDialog::testKnownWebSites(void)
if(ui->hintIcon->isVisible()) ui->hintIcon->hide(); if(ui->hintIcon->isVisible()) ui->hintIcon->hide();
ui->frameAnimation->show(); ui->frameAnimation->show();
QApplication::processEvents(); QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
// ----- Test Internet Connection ----- // // ----- Test Internet Connection ----- //
@ -966,13 +974,8 @@ void UpdateDialog::testKnownWebSites(void)
m_logFile->clear(); m_logFile->clear();
m_logFile->append("Checking internet connection..."); m_logFile->append("Checking internet connection...");
QFuture<bool> connectedState = QtConcurrent::run(lamexp_get_connection_state); const int networkStatus = DO_ASYNC(lamexp_network_status);
while(!connectedState.isFinished()) if(networkStatus == lamexp_network_non)
{
QApplication::processEvents(QEventLoop::WaitForMoreEvents);
}
if(!connectedState.result())
{ {
m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!"); m_logFile->append(QStringList() << "" << "Operating system reports that the computer is currently offline !!!");
if(!ui->retryButton->isVisible()) ui->retryButton->show(); if(!ui->retryButton->isVisible()) ui->retryButton->show();