From 92720131035a86bf06a29d35ebccd980c0178e6b Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 17 Aug 2013 08:54:09 +0200 Subject: - bugfix: download manager will now properly pause all downloads on exiting the application - bugfix: resumed downloads now get their automatic-retry-count reset - fiddled with condition tests in fomod (not sure if it works right now) --- src/downloadmanager.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 3a2d26eb..07048ada 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -33,6 +33,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include using QtJson::Json; @@ -162,12 +163,41 @@ bool DownloadManager::downloadsInProgress() { for (QVector::iterator iter = m_ActiveDownloads.begin(); iter != m_ActiveDownloads.end(); ++iter) { if ((*iter)->m_State < STATE_READY) { -// return true; + return true; } } return false; } +void DownloadManager::pauseAll() +{ + // first loop: pause all downloads + for (int i = 0; i < m_ActiveDownloads.count(); ++i) { + if (m_ActiveDownloads[i]->m_State < STATE_READY) { + pauseDownload(i); + } + } + + ::Sleep(100); + + bool done = false; + // further loops: busy waiting for all downloads to complete. This could be neater... + while (!done) { + QCoreApplication::processEvents(); + done = true; + foreach (DownloadInfo *info, m_ActiveDownloads) { + if ((info->m_State < STATE_CANCELED) || + (info->m_State != STATE_FETCHINGFILEINFO) || (info->m_State != STATE_FETCHINGMODINFO)) { + done = false; + break; + } + } + if (!done) { + ::Sleep(100); + } + } +} + void DownloadManager::setOutputDirectory(const QString &outputDirectory) { @@ -456,8 +486,18 @@ void DownloadManager::pauseDownload(int index) } } - void DownloadManager::resumeDownload(int index) +{ + if ((index < 0) || (index >= m_ActiveDownloads.size())) { + reportError(tr("invalid index %1").arg(index)); + return; + } + DownloadInfo *info = m_ActiveDownloads[index]; + info->m_Tries = AUTOMATIC_RETRIES; + resumeDownloadInt(index); +} + +void DownloadManager::resumeDownloadInt(int index) { if ((index < 0) || (index >= m_ActiveDownloads.size())) { reportError(tr("invalid index %1").arg(index)); -- cgit v1.3.1