diff options
| author | Tannin <devnull@localhost> | 2013-08-17 08:54:09 +0200 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2013-08-17 08:54:09 +0200 |
| commit | 92720131035a86bf06a29d35ebccd980c0178e6b (patch) | |
| tree | 4359f7b48b570d9a7a73e2ffdd3c95f0f621958f /src/downloadmanager.cpp | |
| parent | d0f2c4fcf79222d5c6f3c17188a811b0a47833c6 (diff) | |
- 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)
Diffstat (limited to 'src/downloadmanager.cpp')
| -rw-r--r-- | src/downloadmanager.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
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 <http://www.gnu.org/licenses/>. #include <boost/bind.hpp> #include <regex> #include <QMessageBox> +#include <QCoreApplication> using QtJson::Json; @@ -162,12 +163,41 @@ bool DownloadManager::downloadsInProgress() { for (QVector<DownloadInfo*>::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,7 +486,6 @@ void DownloadManager::pauseDownload(int index) } } - void DownloadManager::resumeDownload(int index) { if ((index < 0) || (index >= m_ActiveDownloads.size())) { @@ -464,6 +493,17 @@ void DownloadManager::resumeDownload(int 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)); + return; + } + DownloadInfo *info = m_ActiveDownloads[index]; if (info->isPausedState()) { if (info->m_State == STATE_ERROR) { info->m_CurrentUrl = (info->m_CurrentUrl + 1) % info->m_Urls.count(); |
