diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 2ac531ec..f06c53b4 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -442,50 +442,32 @@ void DownloadManager::refreshList() void DownloadManager::queryDownloadListInfo() { - TimeThis tt("DownloadManager::queryDownloadListInfos()"); - - log::info("Retrieving data from every download (if possible)..."); - - int incompleteInfos = 0; - - // Just go through all active downloads to query infos + int incompleteCount = 0; for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { if (isInfoIncomplete(i)) { - incompleteInfos++; + incompleteCount++; } } - if (incompleteInfos <= 5) { - // Fetch metadata for incomplete download infos + if (incompleteCount <= 5 || + QMessageBox::question( + m_ParentWidget, tr("Query Metadata"), + tr("There are %1 downloads with incomplete metadata.\n\n" + "Do you want to fetch all incomplete metadata?\n" + "API requests will be consumed, and Mod Organizer may stutter.") + .arg(incompleteCount), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + TimeThis tt("DownloadManager::queryDownloadListInfo()"); + log::info("Querying metadata for every download with incomplete info..."); startDisableDirWatcher(); for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { if (isInfoIncomplete(i)) { - queryInfoMd5(i); + queryInfoMd5(i, false); } } endDisableDirWatcher(); - } else { - - // Warn the user if the number of incomplete infos is over 5 - QString message = tr("There are %1 incomplete download meta files.\n\n" - "Do you want to fetch all incomplete metadata?\n" - "API uses will be consumed, and Mod Organizer may stutter."); - message = message.arg(incompleteInfos); - if (QMessageBox::question(m_ParentWidget, tr("Incomplete Download Infos"), message, - QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { - // Fetch metadata for incomplete download infos - startDisableDirWatcher(); - for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { - if (isInfoIncomplete(i)) { - queryInfoMd5(i); - } - } - endDisableDirWatcher(); - } - return; + log::info("Metadata has been retrieved successfully!"); } - - log::info("Metadata has been retrieved successfully!"); } bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID, @@ -1101,10 +1083,18 @@ void DownloadManager::queryInfo(int index) QString fileName = getFileName(index); QString ignore; NexusInterface::interpretNexusFileName(fileName, ignore, info->m_FileInfo->modID, - true); + info->m_AskIfNotFound); + if (!info->m_AskIfNotFound && (info->m_FileInfo->modID < 0) || + info->m_FileInfo->gameName.isEmpty()) { + // prevent re-querying (only possible with Nexus) + info->m_FileInfo->repository = ""; + setState(info, STATE_READY); + return; + } + if (info->m_FileInfo->modID < 0) { bool ok = false; - int modId = QInputDialog::getInt(nullptr, tr("Please enter the nexus mod id"), + int modId = QInputDialog::getInt(nullptr, tr("Please enter the Nexus mod ID"), tr("Mod ID:"), 1, 1, std::numeric_limits::max(), 1, &ok); // careful now: while the dialog was displayed, events were processed. @@ -1115,7 +1105,7 @@ void DownloadManager::queryInfo(int index) } } - if (info->m_FileInfo->gameName.size() == 0) { + if (info->m_FileInfo->gameName.isEmpty()) { SelectionDialog selection( tr("Please select the source game code for %1").arg(getFileName(index))); @@ -1138,7 +1128,7 @@ void DownloadManager::queryInfo(int index) setState(info, STATE_FETCHINGMODINFO); } -void DownloadManager::queryInfoMd5(int index) +void DownloadManager::queryInfoMd5(int index, bool askIfNotFound) { if ((index < 0) || (index >= m_ActiveDownloads.size())) { reportError(tr("query: invalid download index %1").arg(index)); @@ -1195,8 +1185,9 @@ void DownloadManager::queryInfoMd5(int index) progress.close(); downloadFile.close(); - info->m_Hash = hash.result(); - info->m_ReQueried = true; + info->m_Hash = hash.result(); + info->m_ReQueried = true; + info->m_AskIfNotFound = askIfNotFound; setState(info, STATE_FETCHINGMODINFO_MD5); } diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 549ac29a..2c804b77 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -108,6 +108,7 @@ class DownloadManager : public QObject int m_Tries; bool m_ReQueried; + bool m_AskIfNotFound; quint32 m_TaskProgressId; @@ -143,7 +144,7 @@ class DownloadManager : public QObject private: DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_HasData(false), - m_DownloadTimeLast(0), m_DownloadLast(0), + m_AskIfNotFound(true), m_DownloadTimeLast(0), m_DownloadLast(0), m_DownloadAcc(tag::rolling_window::window_size = 200), m_DownloadTimeAcc(tag::rolling_window::window_size = 200) {} @@ -498,7 +499,7 @@ public slots: void queryInfo(int index); - void queryInfoMd5(int index); + void queryInfoMd5(int index, bool askIfNotFound = true); void visitOnNexus(int index);