Skip to content

Commit 968c044

Browse files
Prevent re-querying and prompts to manually enter data
1 parent b520b01 commit 968c044

File tree

2 files changed

+32
-39
lines changed

2 files changed

+32
-39
lines changed

src/downloadmanager.cpp

+29-38
Original file line numberDiff line numberDiff line change
@@ -442,50 +442,32 @@ void DownloadManager::refreshList()
442442

443443
void DownloadManager::queryDownloadListInfo()
444444
{
445-
TimeThis tt("DownloadManager::queryDownloadListInfos()");
446-
447-
log::info("Retrieving data from every download (if possible)...");
448-
449-
int incompleteInfos = 0;
450-
451-
// Just go through all active downloads to query infos
445+
int incompleteCount = 0;
452446
for (size_t i = 0; i < m_ActiveDownloads.size(); i++) {
453447
if (isInfoIncomplete(i)) {
454-
incompleteInfos++;
448+
incompleteCount++;
455449
}
456450
}
457451

458-
if (incompleteInfos <= 5) {
459-
// Fetch metadata for incomplete download infos
452+
if (incompleteCount <= 5 ||
453+
QMessageBox::question(
454+
m_ParentWidget, tr("Query Metadata"),
455+
tr("There are %1 downloads with incomplete metadata.\n\n"
456+
"Do you want to fetch all incomplete metadata?\n"
457+
"API requests will be consumed, and Mod Organizer may stutter.")
458+
.arg(incompleteCount),
459+
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
460+
TimeThis tt("DownloadManager::queryDownloadListInfo()");
461+
log::info("Querying metadata for every download with incomplete info...");
460462
startDisableDirWatcher();
461463
for (size_t i = 0; i < m_ActiveDownloads.size(); i++) {
462464
if (isInfoIncomplete(i)) {
463-
queryInfoMd5(i);
465+
queryInfoMd5(i, false);
464466
}
465467
}
466468
endDisableDirWatcher();
467-
} else {
468-
469-
// Warn the user if the number of incomplete infos is over 5
470-
QString message = tr("There are %1 incomplete download meta files.\n\n"
471-
"Do you want to fetch all incomplete metadata?\n"
472-
"API uses will be consumed, and Mod Organizer may stutter.");
473-
message = message.arg(incompleteInfos);
474-
if (QMessageBox::question(m_ParentWidget, tr("Incomplete Download Infos"), message,
475-
QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) {
476-
// Fetch metadata for incomplete download infos
477-
startDisableDirWatcher();
478-
for (size_t i = 0; i < m_ActiveDownloads.size(); i++) {
479-
if (isInfoIncomplete(i)) {
480-
queryInfoMd5(i);
481-
}
482-
}
483-
endDisableDirWatcher();
484-
}
485-
return;
469+
log::info("Metadata has been retrieved successfully!");
486470
}
487-
488-
log::info("Metadata has been retrieved successfully!");
489471
}
490472

491473
bool DownloadManager::addDownload(const QStringList& URLs, QString gameName, int modID,
@@ -1101,10 +1083,18 @@ void DownloadManager::queryInfo(int index)
11011083
QString fileName = getFileName(index);
11021084
QString ignore;
11031085
NexusInterface::interpretNexusFileName(fileName, ignore, info->m_FileInfo->modID,
1104-
true);
1086+
info->m_AskIfNotFound);
1087+
if (!info->m_AskIfNotFound && (info->m_FileInfo->modID < 0) ||
1088+
info->m_FileInfo->gameName.isEmpty()) {
1089+
// prevent re-querying (only possible with Nexus)
1090+
info->m_FileInfo->repository = "";
1091+
setState(info, STATE_READY);
1092+
return;
1093+
}
1094+
11051095
if (info->m_FileInfo->modID < 0) {
11061096
bool ok = false;
1107-
int modId = QInputDialog::getInt(nullptr, tr("Please enter the nexus mod id"),
1097+
int modId = QInputDialog::getInt(nullptr, tr("Please enter the Nexus mod ID"),
11081098
tr("Mod ID:"), 1, 1,
11091099
std::numeric_limits<int>::max(), 1, &ok);
11101100
// careful now: while the dialog was displayed, events were processed.
@@ -1115,7 +1105,7 @@ void DownloadManager::queryInfo(int index)
11151105
}
11161106
}
11171107

1118-
if (info->m_FileInfo->gameName.size() == 0) {
1108+
if (info->m_FileInfo->gameName.isEmpty()) {
11191109
SelectionDialog selection(
11201110
tr("Please select the source game code for %1").arg(getFileName(index)));
11211111

@@ -1138,7 +1128,7 @@ void DownloadManager::queryInfo(int index)
11381128
setState(info, STATE_FETCHINGMODINFO);
11391129
}
11401130

1141-
void DownloadManager::queryInfoMd5(int index)
1131+
void DownloadManager::queryInfoMd5(int index, bool askIfNotFound)
11421132
{
11431133
if ((index < 0) || (index >= m_ActiveDownloads.size())) {
11441134
reportError(tr("query: invalid download index %1").arg(index));
@@ -1195,8 +1185,9 @@ void DownloadManager::queryInfoMd5(int index)
11951185
progress.close();
11961186
downloadFile.close();
11971187

1198-
info->m_Hash = hash.result();
1199-
info->m_ReQueried = true;
1188+
info->m_Hash = hash.result();
1189+
info->m_ReQueried = true;
1190+
info->m_AskIfNotFound = askIfNotFound;
12001191
setState(info, STATE_FETCHINGMODINFO_MD5);
12011192
}
12021193

src/downloadmanager.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class DownloadManager : public QObject
108108

109109
int m_Tries;
110110
bool m_ReQueried;
111+
bool m_AskIfNotFound;
111112

112113
quint32 m_TaskProgressId;
113114

@@ -143,6 +144,7 @@ class DownloadManager : public QObject
143144
private:
144145
DownloadInfo()
145146
: m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_HasData(false),
147+
m_AskIfNotFound(true),
146148
m_DownloadTimeLast(0), m_DownloadLast(0),
147149
m_DownloadAcc(tag::rolling_window::window_size = 200),
148150
m_DownloadTimeAcc(tag::rolling_window::window_size = 200)
@@ -498,7 +500,7 @@ public slots:
498500

499501
void queryInfo(int index);
500502

501-
void queryInfoMd5(int index);
503+
void queryInfoMd5(int index, bool askIfNotFound = true);
502504

503505
void visitOnNexus(int index);
504506

0 commit comments

Comments
 (0)