summaryrefslogtreecommitdiff
path: root/src/downloadmanager.cpp
diff options
context:
space:
mode:
authorTannin <devnull@localhost>2014-09-29 20:35:35 +0200
committerTannin <devnull@localhost>2014-09-29 20:35:35 +0200
commitdb0e278817cf5a36e15f1945c52e73726598e8d9 (patch)
treed11067e844c680a3f1c907cfd624a39dd731e290 /src/downloadmanager.cpp
parent2ce135e0bf7ce2c801b1a8d57fe10b099b9007aa (diff)
- moved the hook-recursion-protection to tls
- some code cleanup and consolidation - hook.dll will now report all of its own exceptions - some more logging during startup - changed the way urls are encoded for download requests - now displaying (one of the) process name(s) while waiting for a program to end - bugfix: spawned processes were forced to leave the job
Diffstat (limited to 'src/downloadmanager.cpp')
-rw-r--r--src/downloadmanager.cpp50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index bc31adf4..b3b18a38 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -331,7 +331,8 @@ bool DownloadManager::addDownload(const QStringList &URLs,
fileName = "unknown";
}
- QNetworkRequest request(URLs.first());
+ QUrl preferredUrl = QUrl::fromEncoded(URLs.first().toLocal8Bit());
+ QNetworkRequest request(preferredUrl);
return addDownload(m_NexusInterface->getAccessManager()->get(request), URLs, fileName, modID, fileID, fileInfo);
}
@@ -1198,47 +1199,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)