From 08410deece846839b3e4e52e45d2d7b2264689e0 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Fri, 10 Jan 2020 16:51:41 -0700 Subject: Use the old query info logic when MD5 query is ambiguous An author accidentally uploaded a mod's files to a different mod. This resulted in querying info finding the wrong mod/file. --- src/downloadmanager.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index adfbc84d..fa2c959c 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1823,8 +1823,14 @@ void DownloadManager::nxmFileInfoFromMd5Available(QString gameName, QVariant use auto fileDetails = results["file_details"].toMap(); if (fileDetails["file_name"].toString().compare(info->m_FileName, Qt::CaseInsensitive) == 0) { - chosenIdx = i; - break; + if (chosenIdx < 0) { + chosenIdx = i; //intentional to not break in order to check other results + } + else { + log::debug("Multiple files with same name found during MD5 search."); + chosenIdx = -1; + break; + } } } } @@ -1839,7 +1845,7 @@ void DownloadManager::nxmFileInfoFromMd5Available(QString gameName, QVariant use if (chosenIdx < 0) { chosenIdx = i; //intentional to not break in order to check other results } else { - log::debug("Multiple active files found during MD5 search. Defaulting to time stamps..."); + log::debug("Multiple active files found during MD5 search."); chosenIdx = -1; break; } @@ -1847,24 +1853,14 @@ void DownloadManager::nxmFileInfoFromMd5Available(QString gameName, QVariant use } } - //Look for the most recent one + //Unable to determine the correct mod / file. Revert to the old method if (chosenIdx < 0) { - int mostRecentTime = INT_MIN; - for (int i = 0; i < resultlist.count(); i++) { - auto results = resultlist[i].toMap(); - auto fileDetails = results["file_details"].toMap(); - - int fileTime = fileDetails["uploaded_timestamp"].toInt(); - if (fileTime > mostRecentTime) { - chosenIdx = i; - mostRecentTime = fileTime; - } - } + //don't use the normal state set function as we don't want to create a meta file + info->m_State = DownloadManager::STATE_READY; + queryInfo(m_ActiveDownloads.indexOf(info)); + return; } - //If nothing is preferred, just use the first one - if (chosenIdx < 0) chosenIdx = 0; - auto results = resultlist[chosenIdx].toMap(); auto fileDetails = results["file_details"].toMap(); auto modDetails = results["mod"].toMap(); -- cgit v1.3.1 From 3cfa7bbe74e0f72a08a6f9f1c366f4ed21aca6d5 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Fri, 10 Jan 2020 16:55:19 -0700 Subject: Don't ask for the game when there's only one game --- src/downloadmanager.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index fa2c959c..34eebf0c 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -951,13 +951,20 @@ void DownloadManager::queryInfo(int index) SelectionDialog selection(tr("Please select the source game code for %1").arg(getFileName(index))); std::vector> choices = m_NexusInterface->getGameChoices(m_ManagedGame); - for (auto choice : choices) { - selection.addChoice(choice.first, choice.second, choice.first); + if (choices.size() == 1) + { + info->m_FileInfo->gameName = choices[0].first; } - if (selection.exec() == QDialog::Accepted) { - info->m_FileInfo->gameName = selection.getChoiceData().toString(); - } else { - info->m_FileInfo->gameName = m_ManagedGame->gameShortName(); + else { + for (auto choice : choices) { + selection.addChoice(choice.first, choice.second, choice.first); + } + if (selection.exec() == QDialog::Accepted) { + info->m_FileInfo->gameName = selection.getChoiceData().toString(); + } + else { + info->m_FileInfo->gameName = m_ManagedGame->gameShortName(); + } } } info->m_ReQueried = true; -- cgit v1.3.1 From 9fc7a1bf8530e76f4300d495400bba8a67ab45b1 Mon Sep 17 00:00:00 2001 From: Chris Bessent Date: Sat, 11 Jan 2020 09:24:23 -0700 Subject: Fix downloading files that have no file name Somehow some mods on the Nexus have no file name in certain API responses. Previously, MO assumed the last part of the URL is the file name. This worked until the Nexus started adding URL query stuff to the URL (?md5=xxx). Now, strip out all the URL query stuff to get a valid file name. --- src/downloadmanager.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/downloadmanager.cpp') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 34eebf0c..f5db53bf 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -432,6 +432,13 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs, } } + // baseName could be a URL at this point so strip out the URL query + int queryIndex = baseName.indexOf("?"); + if (queryIndex >= 0) + { + baseName.truncate(queryIndex); + } + startDisableDirWatcher(); newDownload->setName(getDownloadFileName(baseName), false); endDisableDirWatcher(); -- cgit v1.3.1