diff options
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(); |
