From 05d01e39fa15bfd3395ac89ea6a1f2acb9a4dea6 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Thu, 16 Dec 2021 22:04:41 -0600 Subject: Download status improvements - Better speed calculation - Add download time estimate --- src/downloadmanager.cpp | 31 ++++++------ src/downloadmanager.h | 14 +++++- src/organizer_en.ts | 124 +++++++++++++++++++++++++++++------------------- 3 files changed, 102 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 1b097bdb..67086d01 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -942,11 +942,10 @@ void DownloadManager::resumeDownloadInt(int index) QByteArray rangeHeader = "bytes=" + QByteArray::number(info->m_ResumePos) + "-"; request.setRawHeader("Range", rangeHeader); } - std::get<0>(info->m_SpeedDiff) = 0; - std::get<1>(info->m_SpeedDiff) = 0; - std::get<2>(info->m_SpeedDiff) = 0; - std::get<3>(info->m_SpeedDiff) = 0; - std::get<4>(info->m_SpeedDiff) = 0; + info->m_DownloadLast = 0; + info->m_DownloadTimeLast = 0; + info->m_DownloadAcc = accumulator_set>(tag::rolling_window::window_size = 500); + info->m_DownloadTimeAcc = accumulator_set>(tag::rolling_window::window_size = 500); log::debug("resume at {} bytes", info->m_ResumePos); startDownload(m_NexusInterface->getAccessManager()->get(request), info, true); } @@ -1568,20 +1567,20 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) info->m_Progress.first = ((info->m_ResumePos + bytesReceived) * 100) / (info->m_ResumePos + bytesTotal); int elapsed = info->m_StartTime.elapsed(); - std::get<0>(info->m_SpeedDiff) = bytesReceived - std::get<2>(info->m_SpeedDiff); - std::get<1>(info->m_SpeedDiff) = elapsed - std::get<3>(info->m_SpeedDiff); - std::get<2>(info->m_SpeedDiff) = bytesReceived; - std::get<3>(info->m_SpeedDiff) = elapsed; - - double calc = ((double)std::get<0>(info->m_SpeedDiff)) / (((double)(std::get<1>(info->m_SpeedDiff)) / 5000.0)); - std::get<4>(info->m_SpeedDiff) = ((calc*0.5) + (std::get<4>(info->m_SpeedDiff)*1.5)) / 2; + info->m_DownloadAcc(bytesReceived - info->m_DownloadLast); + info->m_DownloadLast = bytesReceived; + info->m_DownloadTimeAcc(elapsed - info->m_DownloadTimeLast); + info->m_DownloadTimeLast = elapsed; // calculate the download speed - const double speed = (std::get<4>(info->m_SpeedDiff) * 1000.0) / (5 * 1000); + const double speed = rolling_mean(info->m_DownloadAcc) / (rolling_mean(info->m_DownloadTimeAcc) / 1000.0);; + + const int remaining = (bytesTotal - bytesReceived) / speed * 1000; - info->m_Progress.second = QString::fromLatin1("%1% - %2") + info->m_Progress.second = tr("%1% - %2 - ~%3") .arg(info->m_Progress.first) - .arg(MOBase::localizedByteSpeed(speed)); + .arg(MOBase::localizedByteSpeed(speed)) + .arg(MOBase::localizedTimeRemaining(remaining)); TaskProgressManager::instance().updateProgress(info->m_TaskProgressId, bytesReceived, bytesTotal); emit update(index); @@ -2227,7 +2226,7 @@ void DownloadManager::managedGameChanged(MOBase::IPluginGame const *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 && + if (m_ActiveDownloads[i]->m_StartTime.elapsed() - m_ActiveDownloads[i]->m_DownloadTimeLast > 5 * 1000 && m_ActiveDownloads[i]->m_State == STATE_DOWNLOADING && m_ActiveDownloads[i]->m_Reply != nullptr && m_ActiveDownloads[i]->m_Reply->isOpen()) { pauseDownload(i); diff --git a/src/downloadmanager.h b/src/downloadmanager.h index ba9f4b5c..86dc17b9 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -38,6 +38,10 @@ along with Mod Organizer. If not, see . #include #include #include +#include +#include +#include +using namespace boost::accumulators; namespace MOBase { class IPluginGame; } @@ -75,6 +79,10 @@ private: struct DownloadInfo { ~DownloadInfo() { delete m_FileInfo; } + accumulator_set> m_DownloadAcc; + accumulator_set> m_DownloadTimeAcc; + int m_DownloadLast; + int m_DownloadTimeLast; unsigned int m_DownloadID; QString m_FileName; QFile m_Output; @@ -82,7 +90,6 @@ private: QElapsedTimer m_StartTime; qint64 m_PreResumeSize; std::pair m_Progress; - std::tuple m_SpeedDiff; bool m_HasData; DownloadState m_State; int m_CurrentUrl; @@ -126,7 +133,10 @@ private: private: static unsigned int s_NextDownloadID; private: - DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_SpeedDiff(std::tuple(0,0,0,0,0)), m_HasData(false) {} + DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_HasData(false), + m_DownloadTimeLast(0), m_DownloadLast(0), + m_DownloadAcc(tag::rolling_window::window_size = 500), + m_DownloadTimeAcc(tag::rolling_window::window_size = 500) {} }; friend class DownloadManagerProxy; diff --git a/src/organizer_en.ts b/src/organizer_en.ts index ffaa1fdd..cf43861c 100644 --- a/src/organizer_en.ts +++ b/src/organizer_en.ts @@ -1099,231 +1099,236 @@ File %3: %4 - - + + query: invalid download index %1 - + Please enter the nexus mod id - + Mod ID: - + Please select the source game code for %1 - + Hashing download file '%1' - + Cancel - + VisitNexus: invalid download index %1 - + Nexus ID for this Mod is unknown - + OpenFile: invalid download index %1 - + OpenFileInDownloadsFolder: invalid download index %1 - + get pending: invalid download index %1 - + get path: invalid download index %1 - + Main - + Update - + Optional - + Old - + Miscellaneous - + Deleted - + Archived - + Unknown - + display name: invalid download index %1 - + file name: invalid download index %1 - + file time: invalid download index %1 - + file size: invalid download index %1 - + progress: invalid download index %1 - + state: invalid download index %1 - + infocomplete: invalid download index %1 - - - + + + mod id: invalid download index %1 - + ishidden: invalid download index %1 - + file info: invalid download index %1 - + mark installed: invalid download index %1 - + mark uninstalled: invalid download index %1 - + + %1% - %2 - ~%3 + + + + Memory allocation error (in processing progress event). - + Memory allocation error (in processing downloaded data). - + Information updated - - + + No matching file found on Nexus! Maybe this file is no longer available or it was renamed? - + No file on Nexus matches the selected file by name. Please manually choose the correct one. - + No download server available. Please try again later. - + Failed to request file info from nexus: %1 - + Warning: Content type is: %1 - + Download header content length: %1 downloaded file size: %2 - + Download failed: %1 (%2) - + We were unable to download the file due to errors after four retries. There may be an issue with the Nexus servers. - + failed to re-open %1 - + Unable to write download to drive (return %1). Check the drive's available storage. @@ -9332,4 +9337,25 @@ On Windows XP: + + uibase + + + h + Time remaining hours + + + + + m + Time remaining minutes + + + + + s + Time remaining seconds + + + -- cgit v1.3.1