summaryrefslogtreecommitdiff
path: root/src/downloadmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/downloadmanager.cpp')
-rw-r--r--src/downloadmanager.cpp48
1 files changed, 26 insertions, 22 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 73e6abde..b3a34d7b 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -37,13 +37,13 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QTimer>
#include <QFileInfo>
-#include <QRegExp>
#include <QDirIterator>
#include <QDesktopServices>
#include <QInputDialog>
#include <QMessageBox>
#include <QCoreApplication>
#include <QTextDocument>
+#include <QHttp2Configuration>
#include <boost/bind/bind.hpp>
#include <regex>
@@ -435,8 +435,12 @@ bool DownloadManager::addDownload(const QStringList &URLs, QString gameName,
QUrl preferredUrl = QUrl::fromEncoded(URLs.first().toLocal8Bit());
log::debug("selected download url: {}", preferredUrl.toString());
+ QHttp2Configuration h2Conf;
+ h2Conf.setSessionReceiveWindowSize(16777215); // 16 MiB, based on Chrome and Firefox values
+ h2Conf.setStreamReceiveWindowSize(16777215);
QNetworkRequest request(preferredUrl);
request.setHeader(QNetworkRequest::UserAgentHeader, m_NexusInterface->getAccessManager()->userAgent());
+ request.setHttp2Configuration(h2Conf);
return addDownload(m_NexusInterface->getAccessManager()->get(request), URLs, fileName, gameName, modID, fileID, fileInfo);
}
@@ -533,7 +537,7 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl
}
connect(newDownload->m_Reply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
- connect(newDownload->m_Reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
+ connect(newDownload->m_Reply, SIGNAL(errorOccurred(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
connect(newDownload->m_Reply, SIGNAL(readyRead()), this, SLOT(downloadReadyRead()));
connect(newDownload->m_Reply, SIGNAL(metaDataChanged()), this, SLOT(metaDataChanged()));
@@ -943,11 +947,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<int, stats<tag::rolling_mean>>(tag::rolling_window::window_size = 200);
+ info->m_DownloadTimeAcc = accumulator_set<int, stats<tag::rolling_mean>>(tag::rolling_window::window_size = 200);
log::debug("resume at {} bytes", info->m_ResumePos);
startDownload(m_NexusInterface->getAccessManager()->get(request), info, true);
}
@@ -1569,20 +1572,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);
@@ -1684,9 +1687,10 @@ void DownloadManager::nxmFilesAvailable(QString, int, QVariant userData, QVarian
// this may muck up the file name comparison
QString alternativeLocalName = info->m_FileName;
- QRegExp expression("^\\d_(.*)$");
- if (expression.indexIn(alternativeLocalName) == 0) {
- alternativeLocalName = expression.cap(1);
+ QRegularExpression expression("^\\d_(.*)$");
+ auto match = expression.match(alternativeLocalName);
+ if (match.hasMatch()) {
+ alternativeLocalName = match.captured(1);
}
bool found = false;
@@ -2020,7 +2024,7 @@ void DownloadManager::nxmFileInfoFromMd5Available(QString gameName, QVariant use
}
-void DownloadManager::nxmRequestFailed(QString gameName, int modID, int fileID, QVariant userData, int requestID, QNetworkReply::NetworkError error, const QString &errorString)
+void DownloadManager::nxmRequestFailed(QString gameName, int modID, int fileID, QVariant userData, int requestID, int errorCode, const QString &errorString)
{
std::set<int>::iterator idIter = m_RequestIDs.find(requestID);
if (idIter == m_RequestIDs.end()) {
@@ -2227,7 +2231,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);