summaryrefslogtreecommitdiff
path: root/src/downloadmanager.cpp
diff options
context:
space:
mode:
authorSilarn <jrim@rimpo.org>2019-02-16 18:27:00 -0600
committerSilarn <jrim@rimpo.org>2019-02-18 21:31:22 -0600
commit70a9cf9429ba5f782400d215a61de0e3e35116e0 (patch)
treec18d1c88629fa9b06abb647a09d7ab8d591f1073 /src/downloadmanager.cpp
parent61842daf93a89ade712986265017c296ec0a097c (diff)
Coalesce code for identifying game short name from nexus name
Diffstat (limited to 'src/downloadmanager.cpp')
-rw-r--r--src/downloadmanager.cpp38
1 files changed, 14 insertions, 24 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp
index 348acbe2..a92dc09c 100644
--- a/src/downloadmanager.cpp
+++ b/src/downloadmanager.cpp
@@ -447,9 +447,19 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs,
void DownloadManager::removePending(QString gameName, int modID, int fileID)
{
+ QString gameShortName = gameName;
+ QStringList games(m_ManagedGame->validShortNames());
+ games += m_ManagedGame->gameShortName();
+ for (auto game : games) {
+ MOBase::IPluginGame *gamePlugin = m_OrganizerCore->getGame(game);
+ if (gamePlugin->gameNexusName().compare(gameName, Qt::CaseInsensitive) == 0) {
+ gameShortName = gamePlugin->gameShortName();
+ break;
+ }
+ }
emit aboutToUpdate();
for (auto iter : m_PendingDownloads) {
- if (gameName.compare(std::get<0>(iter), Qt::CaseInsensitive) == 0 && (std::get<1>(iter) == modID) && (std::get<2>(iter) == fileID)) {
+ if (gameShortName.compare(std::get<0>(iter), Qt::CaseInsensitive) == 0 && (std::get<1>(iter) == modID) && (std::get<2>(iter) == fileID)) {
m_PendingDownloads.removeAt(m_PendingDownloads.indexOf(iter));
break;
}
@@ -1612,21 +1622,10 @@ void DownloadManager::nxmDownloadURLsAvailable(QString gameName, int modID, int
m_RequestIDs.erase(idIter);
}
- QString gameShortName;
- QStringList games(m_ManagedGame->validShortNames());
- games += m_ManagedGame->gameShortName();
- for (auto game : games) {
- MOBase::IPluginGame *gamePlugin = m_OrganizerCore->getGame(game);
- if (gamePlugin->gameNexusName() == gameName) {
- gameShortName = gamePlugin->gameShortName();
- break;
- }
- }
-
ModRepositoryFileInfo *info = qobject_cast<ModRepositoryFileInfo*>(qvariant_cast<QObject*>(userData));
QVariantList resultList = resultData.toList();
if (resultList.length() == 0) {
- removePending(gameShortName, modID, fileID);
+ removePending(gameName, modID, fileID);
emit showMessage(tr("No download server available. Please try again later."));
return;
}
@@ -1640,7 +1639,7 @@ void DownloadManager::nxmDownloadURLsAvailable(QString gameName, int modID, int
foreach (const QVariant &server, resultList) {
URLs.append(server.toMap()["URI"].toString());
}
- addDownload(URLs, gameShortName, modID, fileID, info);
+ addDownload(URLs, gameName, modID, fileID, info);
}
@@ -1669,16 +1668,7 @@ void DownloadManager::nxmRequestFailed(QString gameName, int modID, int fileID,
}
}
- QString gameRealName;
- QStringList games(m_ManagedGame->validShortNames());
- games += m_ManagedGame->gameShortName();
- for (auto game : games) {
- MOBase::IPluginGame *gamePlugin = m_OrganizerCore->getGame(game);
- if (gamePlugin->gameNexusName().compare(gameName, Qt::CaseInsensitive) == 0) {
- gameRealName = gamePlugin->gameShortName();
- }
- }
- removePending(gameRealName, modID, fileID);
+ removePending(gameName, modID, fileID);
emit showMessage(tr("Failed to request file info from nexus: %1").arg(errorString));
}