always use the pending path set to avoid task duplication.

Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
Rachel Powers 2022-11-11 16:33:52 -07:00
parent b9e2c3524c
commit 51c27e2748

View File

@ -168,12 +168,8 @@ void BlockedModsDialog::scanPath(QString path, bool start_task)
/// @param path the path to the local file being hashed /// @param path the path to the local file being hashed
void BlockedModsDialog::addHashTask(QString path) void BlockedModsDialog::addHashTask(QString path)
{ {
if (m_hashing_task->isRunning()) { qDebug() << "[Blocked Mods Dialog] adding a Hash task for" << path << "to the pending set.";
qDebug() << "[Blocked Mods Dialog] adding a Hash task for" << path << "to the pending set."; m_pending_hash_paths.insert(path);
m_pending_hash_paths.insert(path);
} else {
buildHashTask(path);
}
} }
/// @brief add a hashing task for the file located at path and connect it to check that hash against /// @brief add a hashing task for the file located at path and connect it to check that hash against
@ -252,6 +248,8 @@ void BlockedModsDialog::validateMatchedMods()
if (mod.matched) { if (mod.matched) {
QFileInfo file = QFileInfo(mod.localPath); QFileInfo file = QFileInfo(mod.localPath);
if (!file.exists() || !file.isFile()) { if (!file.exists() || !file.isFile()) {
qDebug() << "[Blocked Mods Dialog] File" << mod.localPath << "for mod" << mod.name
<< "has vanshed! marking as not matched.";
mod.localPath = ""; mod.localPath = "";
mod.matched = false; mod.matched = false;
changed = true; changed = true;
@ -268,7 +266,18 @@ void BlockedModsDialog::runHashTask()
{ {
if (!m_hashing_task->isRunning()) { if (!m_hashing_task->isRunning()) {
m_rehash_pending = false; m_rehash_pending = false;
m_hashing_task->start();
if (!m_pending_hash_paths.isEmpty()) {
qDebug() << "[Blocked Mods Dialog] there are pending hash tasks, building and running tasks";
auto path = m_pending_hash_paths.begin();
while (path != m_pending_hash_paths.end()) {
buildHashTask(*path);
path = m_pending_hash_paths.erase(path);
}
m_hashing_task->start();
}
} else { } else {
qDebug() << "[Blocked Mods Dialog] queueing another run of the hashing task"; qDebug() << "[Blocked Mods Dialog] queueing another run of the hashing task";
qDebug() << "[Blocked Mods Dialog] pending hash tasks:" << m_pending_hash_paths; qDebug() << "[Blocked Mods Dialog] pending hash tasks:" << m_pending_hash_paths;
@ -280,14 +289,7 @@ void BlockedModsDialog::hashTaskFinished()
{ {
qDebug() << "[Blocked Mods Dialog] All hash tasks finished"; qDebug() << "[Blocked Mods Dialog] All hash tasks finished";
if (m_rehash_pending) { if (m_rehash_pending) {
qDebug() << "[Blocked Mods Dialog] there was a pending rehash, building and running tasks"; qDebug() << "[Blocked Mods Dialog] task finished with a rehash pending, rerunning";
auto path = m_pending_hash_paths.begin();
while (path != m_pending_hash_paths.end()) {
buildHashTask(*path);
path = m_pending_hash_paths.erase(path);
}
runHashTask(); runHashTask();
} }
} }