diff options
Diffstat (limited to 'src/downloadmanager.cpp')
| -rw-r--r-- | src/downloadmanager.cpp | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 856ca79c..b803d170 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -331,7 +331,9 @@ bool DownloadManager::addDownload(const QStringList &URLs, fileName = "unknown";
}
- QNetworkRequest request(URLs.first());
+ QUrl preferredUrl = QUrl::fromEncoded(URLs.first().toLocal8Bit());
+ qDebug("selected download url: %s", qPrintable(preferredUrl.toString()));
+ QNetworkRequest request(preferredUrl);
return addDownload(m_NexusInterface->getAccessManager()->get(request), URLs, fileName, modID, fileID, fileInfo);
}
@@ -606,7 +608,7 @@ void DownloadManager::pauseDownload(int index) DownloadInfo *info = m_ActiveDownloads.at(index);
if (info->m_State == STATE_DOWNLOADING) {
- if (info->m_Reply->isRunning()) {
+ if ((info->m_Reply != NULL) && (info->m_Reply->isRunning())) {
setState(info, STATE_PAUSING);
} else {
setState(info, STATE_PAUSED);
@@ -644,7 +646,7 @@ void DownloadManager::resumeDownloadInt(int index) info->m_CurrentUrl = (info->m_CurrentUrl + 1) % info->m_Urls.count();
}
qDebug("request resume from url %s", qPrintable(info->currentURL()));
- QNetworkRequest request(info->currentURL());
+ QNetworkRequest request(QUrl::fromEncoded(info->currentURL().toLocal8Bit()));
info->m_ResumePos = info->m_Output.size();
qDebug("resume at %lld bytes", info->m_ResumePos);
QByteArray rangeHeader = "bytes=" + QByteArray::number(info->m_ResumePos) + "-";
@@ -685,7 +687,7 @@ void DownloadManager::queryInfo(int index) return;
}
- if (info->m_FileInfo->modID == 0UL) {
+ if (info->m_FileInfo->modID <= 0) {
QString fileName = getFileName(index);
QString ignore;
NexusInterface::interpretNexusFileName(fileName, ignore, info->m_FileInfo->modID, true);
@@ -1198,47 +1200,34 @@ void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant userD m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(test), QString()));
}
-
-// sort function to sort by best download server
-bool DownloadManager::ServerByPreference(const std::map<QString, int> &preferredServers, const QVariant &LHS, const QVariant &RHS)
+int evaluateFileInfoMap(const QVariantMap &map, const std::map<QString, int> &preferredServers)
{
- int LHSVal = 0;
- int RHSVal = 0;
+ int result = 0;
- QVariantMap LHSMap = LHS.toMap();
- QVariantMap RHSMap = RHS.toMap();
-
- int LHSUsers = LHSMap["ConnectedUsers"].toInt();
- int RHSUsers = RHSMap["ConnectedUsers"].toInt();
+ int users = map["ConnectedUsers"].toInt();
// 0 users is probably a sign that the server is offline. Since there is currently no
// mechanism to try a different server, we avoid those without users
- if (LHSUsers == 0) {
- LHSVal -= 500;
- } else {
- LHSVal -= LHSUsers;
- }
- if (RHSUsers == 0) {
- RHSVal -= 500;
+ if (users == 0) {
+ result -= 500;
} else {
- RHSVal -= RHSUsers;
+ result -= users;
}
- // user preference. This is a bit silly because the more servers on the preferred list the higher the boost
- auto LHSPreference = preferredServers.find(LHSMap["Name"].toString());
- auto RHSPreference = preferredServers.find(RHSMap["Name"].toString());
+ auto preference = preferredServers.find(map["Name"].toString());
- if (LHSPreference != preferredServers.end()) {
- LHSVal += 100 + LHSPreference->second * 20;
- }
- if (RHSPreference != preferredServers.end()) {
- RHSVal += 100 + RHSPreference->second * 20;
+ if (preference != preferredServers.end()) {
+ result += 100 + preference->second * 20;
}
- // premium isn't valued high because premium servers already get a massive boost for having few users online
- if (LHSMap["IsPremium"].toBool()) LHSVal += 5;
- if (RHSMap["IsPremium"].toBool()) RHSVal += 5;
+ if (map["IsPremium"].toBool()) result += 5;
+
+ return result;
+}
- return RHSVal < LHSVal;
+// sort function to sort by best download server
+bool DownloadManager::ServerByPreference(const std::map<QString, int> &preferredServers, const QVariant &LHS, const QVariant &RHS)
+{
+ return evaluateFileInfoMap(LHS.toMap(), preferredServers) > evaluateFileInfoMap(RHS.toMap(), preferredServers);
}
int DownloadManager::startDownloadURLs(const QStringList &urls)
|
