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 | |
| 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)
| -rw-r--r-- | src/downloadmanager.cpp | 44 | ||||
| -rw-r--r-- | src/downloadmanager.h | 3 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 11 | ||||
| -rw-r--r-- | src/shared/directoryentry.cpp | 5 |
4 files changed, 56 insertions, 7 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(); diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 623dda7a..4d493085 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -288,6 +288,7 @@ public: */ int indexByName(const QString &fileName) const; + void pauseAll(); signals: void aboutToUpdate(); @@ -357,10 +358,10 @@ private slots: private: void createMetaFile(DownloadInfo *info); -// QString getOutputPath(const QUrl &url, const QString &fileName) const; QString getDownloadFileName(const QString &baseName) const; void startDownload(QNetworkReply *reply, DownloadInfo *newDownload, bool resume); + void resumeDownloadInt(int index); /** * @brief start a download from a url diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 99b37feb..bf6c89c6 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -710,12 +710,15 @@ void MainWindow::showEvent(QShowEvent *event) void MainWindow::closeEvent(QCloseEvent* event) { - if (m_DownloadManager.downloadsInProgress() && - QMessageBox::question(this, tr("Downloads in progress"), + if (m_DownloadManager.downloadsInProgress()) { + if (QMessageBox::question(this, tr("Downloads in progress"), tr("There are still downloads in progress, do you really want to quit?"), QMessageBox::Yes | QMessageBox::Cancel) == QMessageBox::Cancel) { - event->ignore(); - return; + event->ignore(); + return; + } else { + m_DownloadManager.pauseAll(); + } } setCursor(Qt::WaitCursor); diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index ceba113d..76912b66 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -54,6 +54,11 @@ public: LEAK_TRACE;
}
+ ~OriginConnection()
+ {
+ LEAK_UNTRACE;
+ }
+
FilesOrigin& createOrigin(const std::wstring &originName, const std::wstring &directory, int priority,
boost::shared_ptr<FileRegister> fileRegister, boost::shared_ptr<OriginConnection> originConnection) {
int newID = createID();
|
