From decbbb611edf002bc1458a651c331d1832ed2a6a Mon Sep 17 00:00:00 2001 From: Silarn Date: Sun, 13 May 2018 18:32:59 -0500 Subject: Download resume fixes for restarting MO, hung downloads --- src/downloadmanager.cpp | 19 ++++++++++++++++++- src/downloadmanager.h | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index bfc4de3e..55801e81 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -70,6 +70,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const Mo info->m_Tries = AUTOMATIC_RETRIES; info->m_State = STATE_STARTED; info->m_TaskProgressId = TaskProgressManager::instance().getId(); + info->m_Reply = nullptr; return info; } @@ -136,6 +137,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta(con info->m_FileInfo->fileCategory = metaFile.value("fileCategory", 0).toInt(); info->m_FileInfo->repository = metaFile.value("repository", "Nexus").toString(); info->m_FileInfo->userData = metaFile.value("userData").toMap(); + info->m_Reply = nullptr; return info; } @@ -182,6 +184,9 @@ DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent m_DateExpression("/Date\\((\\d+)\\)/") { connect(&m_DirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); + m_TimeoutTimer.setSingleShot(false); + connect(&m_TimeoutTimer, SIGNAL(timeout()), this, SLOT(checkDownloadTimeout())); + m_TimeoutTimer.start(5 * 1000); } @@ -695,7 +700,7 @@ void DownloadManager::resumeDownloadInt(int index) DownloadInfo *info = m_ActiveDownloads[index]; // Check for finished download; - if (info->m_TotalSize <= info->m_Output.size()) { + if (info->m_TotalSize <= info->m_Output.size() && info->m_Reply != nullptr) { setState(info, STATE_DOWNLOADING); downloadFinished(index); return; @@ -1632,3 +1637,15 @@ void DownloadManager::managedGameChanged(MOBase::IPluginGame const *managedGame) { m_ManagedGame = managedGame; } + +void DownloadManager::checkDownloadTimeout() +{ + for (int i = 0; i < m_ActiveDownloads.size(); ++i) { + if (m_ActiveDownloads[i]->m_StartTime.elapsed() - std::get<3>(m_ActiveDownloads[i]->m_SpeedDiff) > 5 * 1000 && + m_ActiveDownloads[i]->m_State == STATE_DOWNLOADING) { + pauseDownload(i); + downloadFinished(i); + resumeDownload(i); + } + } +} \ No newline at end of file diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 98f5e468..17ae8a35 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -29,6 +29,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #include #include #include @@ -443,6 +444,7 @@ private slots: void downloadError(QNetworkReply::NetworkError error); void metaDataChanged(); void directoryChanged(const QString &dirctory); + void checkDownloadTimeout(); private: @@ -524,6 +526,8 @@ private: QRegExp m_DateExpression; MOBase::IPluginGame const *m_ManagedGame; + + QTimer m_TimeoutTimer; }; -- cgit v1.3.1