Skip to content

Commit

Permalink
Prevent re-querying and prompts to manually enter data
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanFeenstra committed Oct 6, 2024
1 parent b520b01 commit 968c044
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
67 changes: 29 additions & 38 deletions src/downloadmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<int>::max(), 1, &ok);
// careful now: while the dialog was displayed, events were processed.
Expand All @@ -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)));

Expand All @@ -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));
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 3 additions & 1 deletion src/downloadmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class DownloadManager : public QObject

int m_Tries;
bool m_ReQueried;
bool m_AskIfNotFound;

quint32 m_TaskProgressId;

Expand Down Expand Up @@ -143,6 +144,7 @@ class DownloadManager : public QObject
private:
DownloadInfo()
: m_TotalSize(0), m_ReQueried(false), m_Hidden(false), m_HasData(false),
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)
Expand Down Expand Up @@ -498,7 +500,7 @@ public slots:

void queryInfo(int index);

void queryInfoMd5(int index);
void queryInfoMd5(int index, bool askIfNotFound = true);

void visitOnNexus(int index);

Expand Down

0 comments on commit 968c044

Please sign in to comment.