From a9fd86dc881e8fded9d8858bb9a37d1373ac6d58 Mon Sep 17 00:00:00 2001 From: Deewens Date: Sun, 3 Sep 2023 19:13:16 +0200 Subject: [PATCH 01/10] Add a button to "Query Info" of every download in the list --- src/downloadmanager.cpp | 20 ++++++++++++++++++++ src/downloadmanager.h | 5 +++++ src/downloadstab.cpp | 10 +++++++++- src/downloadstab.h | 7 +++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 730803f6d..88f1d121b 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -440,6 +440,26 @@ void DownloadManager::refreshList() } } +void DownloadManager::queryDownloadListInfo() +{ + TimeThis tt("DownloadManager::queryDownloadListInfos()"); + + startDisableDirWatcher(); + + log::info("Retrieving infos from every download (if possible)..."); + + // Just go through all active downloads to query infos + for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { + if (isInfoIncomplete(i)) { + queryInfoMd5(i); + } + } + + log::info("Files infos have been retrived successfully!"); + + endDisableDirWatcher(); +} + bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID, int fileID, const ModRepositoryFileInfo* fileInfo) { diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 1e7a626ee..549ac29ae 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -402,6 +402,11 @@ class DownloadManager : public QObject */ void refreshList(); + /** + * @brief Query infos for every download in the list + */ + void queryDownloadListInfo(); + public: // IDownloadManager interface: int startDownloadURLs(const QStringList& urls); int startDownloadNexusFile(int modID, int fileID); diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp index bf3ea9ad0..d7aa74372 100644 --- a/src/downloadstab.cpp +++ b/src/downloadstab.cpp @@ -5,7 +5,7 @@ #include "ui_mainwindow.h" DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) - : m_core(core), ui{mwui->btnRefreshDownloads, mwui->downloadView, + : m_core(core), ui{mwui->btnRefreshDownloads, mwui->btnQueryDownloadsInfo, mwui->downloadView, mwui->showHiddenBox, mwui->downloadFilterEdit} { DownloadList* sourceModel = new DownloadList(m_core, ui.list); @@ -26,6 +26,9 @@ DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) connect(ui.refresh, &QPushButton::clicked, [&] { refresh(); }); + connect(ui.queryInfos, &QPushButton::clicked, [&] { + queryInfos(); + }); connect(ui.list, SIGNAL(installDownload(int)), &m_core, SLOT(installDownload(int))); connect(ui.list, SIGNAL(queryInfo(int)), m_core.downloadManager(), SLOT(queryInfo(int))); @@ -80,6 +83,11 @@ void DownloadsTab::refresh() m_core.downloadManager()->refreshList(); } +void DownloadsTab::queryInfos() +{ + m_core.downloadManager()->queryDownloadListInfo(); +} + void DownloadsTab::resumeDownload(int downloadIndex) { m_core.loggedInAction(ui.list, [this, downloadIndex] { diff --git a/src/downloadstab.h b/src/downloadstab.h index f0b85d918..1676ec761 100644 --- a/src/downloadstab.h +++ b/src/downloadstab.h @@ -23,6 +23,7 @@ class DownloadsTab : public QObject struct DownloadsTabUi { QPushButton* refresh; + QPushButton* queryInfos; DownloadListView* list; QCheckBox* showHidden; QLineEdit* filter; @@ -33,6 +34,12 @@ class DownloadsTab : public QObject MOBase::FilterWidget m_filter; void refresh(); + + /** + * @brief Handle click on the "Query infos" button + **/ + void queryInfos(); + void resumeDownload(int downloadIndex); }; From 7ed3a3be567e7707d509844bef05f8a86e49007c Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Sat, 27 Jul 2024 08:13:01 -0400 Subject: [PATCH 02/10] Update mainwindow.ui Added button to pr Update mainwindow.ui Update mainwindow.ui Added button to pr --- src/mainwindow.ui | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 7648f8a69..0e8e2bf63 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1345,6 +1345,26 @@ + + + + + 0 + 0 + + + + Qt::ContextMenuPolicy::DefaultContextMenu + + + Query Metadata + + + + :/MO/gui/resources/system-search.png:/MO/gui/resources/system-search.png + + + From b57deb217a48bc98c0b5ed3c26a92da7f8125eaa Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Sat, 27 Jul 2024 21:47:37 -0400 Subject: [PATCH 03/10] Fix linter Fixed clang formatting on downloadstab.cpp --- src/downloadstab.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp index d7aa74372..25dfa8e48 100644 --- a/src/downloadstab.cpp +++ b/src/downloadstab.cpp @@ -5,8 +5,9 @@ #include "ui_mainwindow.h" DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) - : m_core(core), ui{mwui->btnRefreshDownloads, mwui->btnQueryDownloadsInfo, mwui->downloadView, - mwui->showHiddenBox, mwui->downloadFilterEdit} + : m_core(core), + ui{mwui->btnRefreshDownloads, mwui->btnQueryDownloadsInfo, mwui->downloadView, + mwui->showHiddenBox, mwui->downloadFilterEdit} { DownloadList* sourceModel = new DownloadList(m_core, ui.list); @@ -27,7 +28,7 @@ DownloadsTab::DownloadsTab(OrganizerCore& core, Ui::MainWindow* mwui) refresh(); }); connect(ui.queryInfos, &QPushButton::clicked, [&] { - queryInfos(); + queryInfos(); }); connect(ui.list, SIGNAL(installDownload(int)), &m_core, SLOT(installDownload(int))); connect(ui.list, SIGNAL(queryInfo(int)), m_core.downloadManager(), @@ -83,7 +84,7 @@ void DownloadsTab::refresh() m_core.downloadManager()->refreshList(); } -void DownloadsTab::queryInfos() +void DownloadsTab::queryInfos() { m_core.downloadManager()->queryDownloadListInfo(); } From b78cd3c2a43260a0c08f50c52f2da3c322758932 Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Mon, 29 Jul 2024 11:32:30 -0400 Subject: [PATCH 04/10] Add warning message for dialog box --- src/downloadmanager.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 88f1d121b..af1ed9e4d 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -444,20 +444,38 @@ void DownloadManager::queryDownloadListInfo() { TimeThis tt("DownloadManager::queryDownloadListInfos()"); - startDisableDirWatcher(); - log::info("Retrieving infos from every download (if possible)..."); + int incompleteInfos = 0; + // Just go through all active downloads to query infos for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { if (isInfoIncomplete(i)) { - queryInfoMd5(i); + incompleteInfos++; } } - log::info("Files infos have been retrived successfully!"); + // Warn the user if the number of incomplete infos is over 5 + if (incompleteInfos > 5) { + QString message = tr("There %1 incomplete download meta files.\n\n" + "Do you want to fetch metadata for all incomplete downloads?\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; + } - endDisableDirWatcher(); + log::info("Files infos have been retrieved successfully!"); } bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID, From ae8d24f62651f221e63df42c0f66d05f799619a8 Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Mon, 29 Jul 2024 11:57:32 -0400 Subject: [PATCH 05/10] Fix oversight in new dialog box The new dialog box hijacked the function and skipped the fetch if there were less than 5 files. Now directly runs if there are 5 files or less, and shows the dialog if there are more than 5\ --- src/downloadmanager.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index af1ed9e4d..2dd3ea9c8 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -455,8 +455,18 @@ void DownloadManager::queryDownloadListInfo() } } - // Warn the user if the number of incomplete infos is over 5 - if (incompleteInfos > 5) { + if (incompleteInfos <= 5) { + // Fetch metadata for incomplete download infos + startDisableDirWatcher(); + for (size_t i = 0; i < m_ActiveDownloads.size(); i++) { + if (isInfoIncomplete(i)) { + queryInfoMd5(i); + } + } + endDisableDirWatcher(); + } else { + + // Warn the user if the number of incomplete infos is over 5 QString message = tr("There %1 incomplete download meta files.\n\n" "Do you want to fetch metadata for all incomplete downloads?\n" "API uses will be consumed, and Mod Organizer may stutter."); From 40bd80b53601a14826100856ef3dfbca70c6293a Mon Sep 17 00:00:00 2001 From: KenJyn76 Date: Mon, 29 Jul 2024 12:03:55 -0400 Subject: [PATCH 06/10] Grammar fixes in dialog box and logs --- src/downloadmanager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 2dd3ea9c8..2ac531ec5 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -444,7 +444,7 @@ void DownloadManager::queryDownloadListInfo() { TimeThis tt("DownloadManager::queryDownloadListInfos()"); - log::info("Retrieving infos from every download (if possible)..."); + log::info("Retrieving data from every download (if possible)..."); int incompleteInfos = 0; @@ -467,8 +467,8 @@ void DownloadManager::queryDownloadListInfo() } else { // Warn the user if the number of incomplete infos is over 5 - QString message = tr("There %1 incomplete download meta files.\n\n" - "Do you want to fetch metadata for all incomplete downloads?\n" + 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, @@ -485,7 +485,7 @@ void DownloadManager::queryDownloadListInfo() return; } - log::info("Files infos have been retrieved successfully!"); + log::info("Metadata has been retrieved successfully!"); } bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID, From ae49be5093f4bb6d939e1578de7f3e86a38b42ef Mon Sep 17 00:00:00 2001 From: Jonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com> Date: Sun, 6 Oct 2024 12:39:42 +0200 Subject: [PATCH 07/10] Prevent re-querying and prompts to manually enter data --- src/downloadmanager.cpp | 67 ++++++++++++++++++----------------------- src/downloadmanager.h | 5 +-- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 2ac531ec5..f06c53b4a 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 549ac29ae..2c804b778 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); From a32cb7751f9a37fe8fa31e895c78204c2d0fc31b Mon Sep 17 00:00:00 2001 From: Jonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com> Date: Sat, 14 Dec 2024 11:39:29 +0100 Subject: [PATCH 08/10] Prevent querying metadata with offline mode enabled --- src/downloadstab.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp index 25dfa8e48..c800275a9 100644 --- a/src/downloadstab.cpp +++ b/src/downloadstab.cpp @@ -86,6 +86,17 @@ void DownloadsTab::refresh() void DownloadsTab::queryInfos() { + if (m_core.settings().network().offlineMode()) { + if (QMessageBox::warning(nullptr, tr("Query Metadata"), + tr("Cannot query metadata while offline mode is enabled. " + "Do you want to disable it?"), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + m_core.settings().network().setOfflineMode(false); + } else { + return; + } + } + m_core.downloadManager()->queryDownloadListInfo(); } From a44c0f89d3161c12bc54e104f899873aadc1026e Mon Sep 17 00:00:00 2001 From: Jonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com> Date: Sat, 14 Dec 2024 16:25:03 +0100 Subject: [PATCH 09/10] Only create empty meta file if Nexus error code is 404 --- src/downloadmanager.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index f06c53b4a..186314724 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -1084,14 +1084,6 @@ void DownloadManager::queryInfo(int index) QString ignore; NexusInterface::interpretNexusFileName(fileName, ignore, info->m_FileInfo->modID, 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"), @@ -1106,6 +1098,12 @@ void DownloadManager::queryInfo(int index) } if (info->m_FileInfo->gameName.isEmpty()) { + if (!info->m_AskIfNotFound) { + // in case the info couldn't be retrieved from Nexus due to connection issues, + // don't create a meta file so you can query again after the issues are resolved. + return; + } + SelectionDialog selection( tr("Please select the source game code for %1").arg(getFileName(index))); @@ -2172,6 +2170,11 @@ void DownloadManager::nxmRequestFailed(QString gameName, int modID, int fileID, info->m_GamesToQuery.pop_front(); setState(info, STATE_FETCHINGMODINFO_MD5); return; + } else if (errorCode == 404 && !info->m_AskIfNotFound) { + // prevent re-querying (only possible with repository = "Nexus") + info->m_FileInfo->repository = ""; + setState(info, STATE_READY); + return; } else { info->m_State = STATE_READY; queryInfo(index); From 074fde5bc3f6129b32a959ab14a055c00c3b4c4d Mon Sep 17 00:00:00 2001 From: Jonathan Feenstra <26406078+JonathanFeenstra@users.noreply.github.com> Date: Sat, 21 Dec 2024 13:44:14 +0100 Subject: [PATCH 10/10] Clarify offline mode question Co-authored-by: Al <26797547+Al12rs@users.noreply.github.com> --- src/downloadstab.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/downloadstab.cpp b/src/downloadstab.cpp index c800275a9..958efbd59 100644 --- a/src/downloadstab.cpp +++ b/src/downloadstab.cpp @@ -89,7 +89,7 @@ void DownloadsTab::queryInfos() if (m_core.settings().network().offlineMode()) { if (QMessageBox::warning(nullptr, tr("Query Metadata"), tr("Cannot query metadata while offline mode is enabled. " - "Do you want to disable it?"), + "Do you want to disable offline mode?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { m_core.settings().network().setOfflineMode(false); } else {