2022-11-23 19:24:04 +05:30
|
|
|
// SPDX-FileCopyrightText: 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
// SPDX-FileCopyrightText: 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
|
|
|
// SPDX-FileCopyrightText: 2022 kumquat-ir <66188216+kumquat-ir@users.noreply.github.com>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Prism Launcher - Minecraft Launcher
|
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
* Copyright (C) 2022 Rachel Powers <508861+Ryex@users.noreply.github.com>
|
|
|
|
* Copyright (C) 2022 kumquat-ir <66188216+kumquat-ir@users.noreply.github.com>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-07-17 04:44:54 +05:30
|
|
|
#include "BlockedModsDialog.h"
|
2022-11-01 19:36:36 +05:30
|
|
|
#include "ui_BlockedModsDialog.h"
|
2022-07-17 04:44:54 +05:30
|
|
|
|
2022-11-02 03:15:15 +05:30
|
|
|
#include "Application.h"
|
2022-11-23 18:59:23 +05:30
|
|
|
#include "modplatform/helpers/HashUtils.h"
|
2022-11-02 03:15:15 +05:30
|
|
|
|
2022-10-24 16:38:38 +05:30
|
|
|
#include <QDebug>
|
2022-11-02 03:15:15 +05:30
|
|
|
#include <QDesktopServices>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QDirIterator>
|
2022-11-12 02:40:45 +05:30
|
|
|
#include <QDragEnterEvent>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFileInfo>
|
2022-11-02 03:15:15 +05:30
|
|
|
#include <QMimeData>
|
|
|
|
#include <QPushButton>
|
2022-11-12 04:37:57 +05:30
|
|
|
#include <QStandardPaths>
|
2022-07-17 04:44:54 +05:30
|
|
|
|
2022-11-01 19:36:36 +05:30
|
|
|
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
|
2022-11-12 04:15:40 +05:30
|
|
|
: QDialog(parent), ui(new Ui::BlockedModsDialog), m_mods(mods)
|
2022-11-01 19:36:36 +05:30
|
|
|
{
|
2022-11-12 04:15:40 +05:30
|
|
|
m_hashing_task = shared_qobject_ptr<ConcurrentTask>(new ConcurrentTask(this, "MakeHashesTask", 10));
|
|
|
|
connect(m_hashing_task.get(), &Task::finished, this, &BlockedModsDialog::hashTaskFinished);
|
2022-11-12 04:37:57 +05:30
|
|
|
|
2022-07-17 04:44:54 +05:30
|
|
|
ui->setupUi(this);
|
|
|
|
|
2022-11-23 18:59:23 +05:30
|
|
|
m_openMissingButton = ui->buttonBox->addButton(tr("Open Missing"), QDialogButtonBox::ActionRole);
|
|
|
|
connect(m_openMissingButton, &QPushButton::clicked, this, [this]() { openAll(true); });
|
2022-07-17 04:44:54 +05:30
|
|
|
|
2022-11-12 02:40:45 +05:30
|
|
|
auto downloadFolderButton = ui->buttonBox->addButton(tr("Add Download Folder"), QDialogButtonBox::ActionRole);
|
|
|
|
connect(downloadFolderButton, &QPushButton::clicked, this, &BlockedModsDialog::addDownloadFolder);
|
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged);
|
2022-10-25 13:49:19 +05:30
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] Mods List: " << mods;
|
2022-10-24 16:38:38 +05:30
|
|
|
|
2022-10-25 13:49:19 +05:30
|
|
|
setupWatch();
|
2022-10-26 08:48:14 +05:30
|
|
|
scanPaths();
|
2022-10-25 13:49:19 +05:30
|
|
|
|
2022-07-17 04:44:54 +05:30
|
|
|
this->setWindowTitle(title);
|
2022-11-12 06:35:19 +05:30
|
|
|
ui->labelDescription->setText(text);
|
2022-11-23 17:55:17 +05:30
|
|
|
|
|
|
|
// force all URL handling as external
|
2022-11-12 07:02:11 +05:30
|
|
|
connect(ui->textBrowserWatched, &QTextBrowser::anchorClicked, this, [](const QUrl url) { QDesktopServices::openUrl(url); });
|
|
|
|
|
2022-11-12 02:40:45 +05:30
|
|
|
setAcceptDrops(true);
|
|
|
|
|
2022-10-24 16:38:38 +05:30
|
|
|
update();
|
2022-07-17 04:44:54 +05:30
|
|
|
}
|
|
|
|
|
2022-11-01 19:36:36 +05:30
|
|
|
BlockedModsDialog::~BlockedModsDialog()
|
|
|
|
{
|
2022-07-17 04:44:54 +05:30
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::dragEnterEvent(QDragEnterEvent* e)
|
|
|
|
{
|
2022-11-12 02:40:45 +05:30
|
|
|
if (e->mimeData()->hasUrls()) {
|
|
|
|
e->acceptProposedAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::dropEvent(QDropEvent* e)
|
2022-11-12 02:40:45 +05:30
|
|
|
{
|
2022-12-10 05:51:40 +05:30
|
|
|
for (QUrl& url : e->mimeData()->urls()) {
|
2023-03-21 23:37:20 +05:30
|
|
|
if (url.scheme().isEmpty()) { // ensure isLocalFile() works correctly
|
2022-12-10 05:51:40 +05:30
|
|
|
url.setScheme("file");
|
|
|
|
}
|
2022-12-15 03:52:27 +05:30
|
|
|
|
2023-03-21 23:37:20 +05:30
|
|
|
if (!url.isLocalFile()) { // can't drop external files here.
|
2022-12-10 05:51:40 +05:30
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
QString filePath = url.toLocalFile();
|
|
|
|
qDebug() << "[Blocked Mods Dialog] Dropped file:" << filePath;
|
|
|
|
addHashTask(filePath);
|
|
|
|
|
|
|
|
// watch for changes
|
|
|
|
QFileInfo file = QFileInfo(filePath);
|
|
|
|
QString path = file.dir().absolutePath();
|
|
|
|
qDebug() << "[Blocked Mods Dialog] Adding watch path:" << path;
|
|
|
|
m_watcher.addPath(path);
|
2022-11-12 02:40:45 +05:30
|
|
|
}
|
2022-11-12 04:15:40 +05:30
|
|
|
scanPaths();
|
|
|
|
update();
|
2022-11-12 02:40:45 +05:30
|
|
|
}
|
|
|
|
|
2022-12-06 01:57:23 +05:30
|
|
|
void BlockedModsDialog::done(int r)
|
|
|
|
{
|
|
|
|
QDialog::done(r);
|
|
|
|
disconnect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged);
|
|
|
|
}
|
|
|
|
|
2022-11-23 18:59:23 +05:30
|
|
|
void BlockedModsDialog::openAll(bool missingOnly)
|
2022-11-01 19:36:36 +05:30
|
|
|
{
|
2022-11-12 04:15:40 +05:30
|
|
|
for (auto& mod : m_mods) {
|
2022-11-23 18:59:23 +05:30
|
|
|
if (!missingOnly || !mod.matched) {
|
|
|
|
QDesktopServices::openUrl(mod.websiteUrl);
|
|
|
|
}
|
2022-07-17 04:44:54 +05:30
|
|
|
}
|
|
|
|
}
|
2022-10-24 16:38:38 +05:30
|
|
|
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::addDownloadFolder()
|
|
|
|
{
|
|
|
|
QString dir =
|
|
|
|
QFileDialog::getExistingDirectory(this, tr("Select directory where you downloaded the mods"),
|
|
|
|
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation), QFileDialog::ShowDirsOnly);
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] Adding watch path:" << dir;
|
|
|
|
m_watcher.addPath(dir);
|
|
|
|
scanPath(dir, true);
|
|
|
|
update();
|
2022-11-12 02:40:45 +05:30
|
|
|
}
|
|
|
|
|
2022-10-26 08:48:14 +05:30
|
|
|
/// @brief update UI with current status of the blocked mod detection
|
2022-11-01 19:36:36 +05:30
|
|
|
void BlockedModsDialog::update()
|
|
|
|
{
|
2022-10-24 16:38:38 +05:30
|
|
|
QString text;
|
|
|
|
QString span;
|
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
for (auto& mod : m_mods) {
|
2022-10-24 16:38:38 +05:30
|
|
|
if (mod.matched) {
|
|
|
|
// ✔ -> html for HEAVY CHECK MARK : ✔
|
2022-10-31 11:09:12 +05:30
|
|
|
span = QString(tr("<span style=\"color:green\"> ✔ Found at %1 </span>")).arg(mod.localPath);
|
2022-10-24 16:38:38 +05:30
|
|
|
} else {
|
|
|
|
// ✘ -> html for HEAVY BALLOT X : ✘
|
2022-10-31 11:09:12 +05:30
|
|
|
span = QString(tr("<span style=\"color:red\"> ✘ Not Found </span>"));
|
2022-10-24 16:38:38 +05:30
|
|
|
}
|
2022-10-31 11:09:12 +05:30
|
|
|
text += QString(tr("%1: <a href='%2'>%2</a> <p>Hash: %3 %4</p> <br/>")).arg(mod.name, mod.websiteUrl, mod.hash, span);
|
2022-10-24 16:38:38 +05:30
|
|
|
}
|
|
|
|
|
2022-11-12 06:35:19 +05:30
|
|
|
ui->textBrowserModsListing->setText(text);
|
|
|
|
|
|
|
|
QString watching;
|
|
|
|
for (auto& dir : m_watcher.directories()) {
|
2022-11-12 07:02:11 +05:30
|
|
|
watching += QString("<a href=\"%1\">%1</a><br/>").arg(dir);
|
2022-11-12 06:35:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
ui->textBrowserWatched->setText(watching);
|
2022-10-25 23:29:37 +05:30
|
|
|
|
|
|
|
if (allModsMatched()) {
|
2022-11-18 00:16:14 +05:30
|
|
|
ui->labelModsFound->setText("<span style=\"color:green\">✔</span>" + tr("All mods found"));
|
2022-11-23 18:59:23 +05:30
|
|
|
m_openMissingButton->setDisabled(true);
|
2022-10-25 23:29:37 +05:30
|
|
|
} else {
|
2022-10-31 11:09:12 +05:30
|
|
|
ui->labelModsFound->setText(tr("Please download the missing mods."));
|
2022-11-23 18:59:23 +05:30
|
|
|
m_openMissingButton->setDisabled(false);
|
2022-10-25 23:29:37 +05:30
|
|
|
}
|
2022-10-24 16:38:38 +05:30
|
|
|
}
|
|
|
|
|
2023-03-21 23:37:20 +05:30
|
|
|
/// @brief Signal fired when a watched directory has changed
|
2022-10-26 08:48:14 +05:30
|
|
|
/// @param path the path to the changed directory
|
2022-11-01 19:36:36 +05:30
|
|
|
void BlockedModsDialog::directoryChanged(QString path)
|
|
|
|
{
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] Directory changed: " << path;
|
2022-11-12 02:40:45 +05:30
|
|
|
validateMatchedMods();
|
2022-11-12 04:15:40 +05:30
|
|
|
scanPath(path, true);
|
2022-10-25 13:49:19 +05:30
|
|
|
}
|
|
|
|
|
2022-10-26 08:48:14 +05:30
|
|
|
/// @brief add the user downloads folder and the global mods folder to the filesystem watcher
|
2022-11-01 19:36:36 +05:30
|
|
|
void BlockedModsDialog::setupWatch()
|
|
|
|
{
|
2023-03-13 21:07:45 +05:30
|
|
|
const QString downloadsFolder = APPLICATION->settings()->get("DownloadsDir").toString();
|
2022-10-25 13:49:19 +05:30
|
|
|
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
|
2023-03-21 23:37:20 +05:30
|
|
|
watchPath(downloadsFolder, true);
|
|
|
|
watchPath(modsFolder, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlockedModsDialog::watchPath(QString path, bool watch_subdirectories)
|
|
|
|
{
|
|
|
|
m_watcher.addPath(path);
|
|
|
|
|
|
|
|
if (!watch_subdirectories)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QDirIterator it(path, QDirIterator::Subdirectories);
|
|
|
|
while (it.hasNext()) {
|
|
|
|
QString dir = it.next();
|
|
|
|
watchPath(it.next(), watch_subdirectories);
|
|
|
|
}
|
2022-10-25 13:49:19 +05:30
|
|
|
}
|
|
|
|
|
2022-10-26 08:48:14 +05:30
|
|
|
/// @brief scan all watched folder
|
2022-11-01 19:36:36 +05:30
|
|
|
void BlockedModsDialog::scanPaths()
|
|
|
|
{
|
2022-11-12 04:15:40 +05:30
|
|
|
for (auto& dir : m_watcher.directories()) {
|
|
|
|
scanPath(dir, false);
|
2022-10-25 13:49:19 +05:30
|
|
|
}
|
2022-11-12 04:15:40 +05:30
|
|
|
runHashTask();
|
2022-10-25 13:49:19 +05:30
|
|
|
}
|
|
|
|
|
2022-11-01 19:36:36 +05:30
|
|
|
/// @brief Scan the directory at path, skip paths that do not contain a file name
|
2022-10-26 08:48:14 +05:30
|
|
|
/// of a blocked mod we are looking for
|
|
|
|
/// @param path the directory to scan
|
2022-11-12 04:15:40 +05:30
|
|
|
void BlockedModsDialog::scanPath(QString path, bool start_task)
|
2022-11-01 19:36:36 +05:30
|
|
|
{
|
2022-10-25 13:49:19 +05:30
|
|
|
QDir scan_dir(path);
|
|
|
|
QDirIterator scan_it(path, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::NoIteratorFlags);
|
|
|
|
while (scan_it.hasNext()) {
|
|
|
|
QString file = scan_it.next();
|
|
|
|
|
|
|
|
if (!checkValidPath(file)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-11-12 02:40:45 +05:30
|
|
|
addHashTask(file);
|
|
|
|
}
|
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
if (start_task) {
|
|
|
|
runHashTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 23:37:20 +05:30
|
|
|
/// @brief add a hashing task for the file located at path, add the path to the pending set if the hashing task is already running
|
2022-11-12 04:15:40 +05:30
|
|
|
/// @param path the path to the local file being hashed
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::addHashTask(QString path)
|
|
|
|
{
|
2022-11-12 05:03:52 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] adding a Hash task for" << path << "to the pending set.";
|
|
|
|
m_pending_hash_paths.insert(path);
|
2022-11-12 02:40:45 +05:30
|
|
|
}
|
2022-10-25 13:49:19 +05:30
|
|
|
|
2022-11-12 04:37:57 +05:30
|
|
|
/// @brief add a hashing task for the file located at path and connect it to check that hash against
|
2022-11-12 02:40:45 +05:30
|
|
|
/// our blocked mods list
|
|
|
|
/// @param path the path to the local file being hashed
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::buildHashTask(QString path)
|
|
|
|
{
|
2022-11-25 17:53:46 +05:30
|
|
|
auto hash_task = Hashing::createBlockedModHasher(path, ModPlatform::ResourceProvider::FLAME, "sha1");
|
2022-10-25 13:49:19 +05:30
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] Creating Hash task for path: " << path;
|
2022-11-01 19:36:36 +05:30
|
|
|
|
2022-11-12 06:35:19 +05:30
|
|
|
connect(hash_task.get(), &Task::succeeded, this, [this, hash_task, path] { checkMatchHash(hash_task->getResult(), path); });
|
|
|
|
connect(hash_task.get(), &Task::failed, this, [path] { qDebug() << "Failed to hash path: " << path; });
|
2022-10-25 13:49:19 +05:30
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
m_hashing_task->addTask(hash_task);
|
2022-10-25 13:49:19 +05:30
|
|
|
}
|
|
|
|
|
2022-10-31 11:09:12 +05:30
|
|
|
/// @brief check if the computed hash for the provided path matches a blocked
|
2022-10-26 08:48:14 +05:30
|
|
|
/// mod we are looking for
|
|
|
|
/// @param hash the computed hash for the provided path
|
|
|
|
/// @param path the path to the local file being compared
|
2022-11-01 19:36:36 +05:30
|
|
|
void BlockedModsDialog::checkMatchHash(QString hash, QString path)
|
|
|
|
{
|
2022-10-25 13:49:19 +05:30
|
|
|
bool match = false;
|
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] Checking for match on hash: " << hash << "| From path:" << path;
|
2022-10-25 13:49:19 +05:30
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
for (auto& mod : m_mods) {
|
2022-10-25 13:49:19 +05:30
|
|
|
if (mod.matched) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (mod.hash.compare(hash, Qt::CaseInsensitive) == 0) {
|
|
|
|
mod.matched = true;
|
|
|
|
mod.localPath = path;
|
|
|
|
match = true;
|
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] Hash match found:" << mod.name << hash << "| From path:" << path;
|
2022-10-25 13:49:19 +05:30
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-31 11:09:12 +05:30
|
|
|
/// @brief Check if the name of the file at path matches the name of a blocked mod we are searching for
|
2022-10-26 08:48:14 +05:30
|
|
|
/// @param path the path to check
|
|
|
|
/// @return boolean: did the path match the name of a blocked mod?
|
2022-11-01 19:36:36 +05:30
|
|
|
bool BlockedModsDialog::checkValidPath(QString path)
|
|
|
|
{
|
2022-11-23 18:24:50 +05:30
|
|
|
const QFileInfo file = QFileInfo(path);
|
|
|
|
const QString filename = file.fileName();
|
|
|
|
QString laxFilename(filename);
|
|
|
|
laxFilename.replace('+', ' ');
|
|
|
|
|
|
|
|
auto compare = [](QString fsfilename, QString metadataFilename) {
|
|
|
|
return metadataFilename.compare(fsfilename, Qt::CaseInsensitive) == 0;
|
|
|
|
};
|
2022-10-25 13:49:19 +05:30
|
|
|
|
2022-11-12 04:15:40 +05:30
|
|
|
for (auto& mod : m_mods) {
|
2022-11-23 18:24:50 +05:30
|
|
|
if (compare(filename, mod.name)) {
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] Name match found:" << mod.name << "| From path:" << path;
|
2022-10-25 13:49:19 +05:30
|
|
|
return true;
|
|
|
|
}
|
2022-11-23 18:24:50 +05:30
|
|
|
if (compare(laxFilename, mod.name)) {
|
|
|
|
qDebug() << "[Blocked Mods Dialog] Lax name match found:" << mod.name << "| From path:" << path;
|
|
|
|
return true;
|
|
|
|
}
|
2022-10-25 13:49:19 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-11-01 19:36:36 +05:30
|
|
|
bool BlockedModsDialog::allModsMatched()
|
|
|
|
{
|
2022-11-12 04:15:40 +05:30
|
|
|
return std::all_of(m_mods.begin(), m_mods.end(), [](auto const& mod) { return mod.matched; });
|
2022-10-25 13:49:19 +05:30
|
|
|
}
|
|
|
|
|
2022-11-12 02:40:45 +05:30
|
|
|
/// @brief ensure matched file paths still exist
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::validateMatchedMods()
|
|
|
|
{
|
2022-11-12 02:40:45 +05:30
|
|
|
bool changed = false;
|
2022-11-12 04:15:40 +05:30
|
|
|
for (auto& mod : m_mods) {
|
2022-11-12 02:40:45 +05:30
|
|
|
if (mod.matched) {
|
|
|
|
QFileInfo file = QFileInfo(mod.localPath);
|
|
|
|
if (!file.exists() || !file.isFile()) {
|
2022-11-12 05:03:52 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] File" << mod.localPath << "for mod" << mod.name
|
|
|
|
<< "has vanshed! marking as not matched.";
|
2022-11-12 02:40:45 +05:30
|
|
|
mod.localPath = "";
|
|
|
|
mod.matched = false;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 23:37:20 +05:30
|
|
|
/// @brief run hash task or mark a pending run if it is already running
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::runHashTask()
|
|
|
|
{
|
2022-11-12 04:15:40 +05:30
|
|
|
if (!m_hashing_task->isRunning()) {
|
|
|
|
m_rehash_pending = false;
|
2022-11-12 05:03:52 +05:30
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
2022-11-12 04:15:40 +05:30
|
|
|
} else {
|
|
|
|
qDebug() << "[Blocked Mods Dialog] queueing another run of the hashing task";
|
|
|
|
qDebug() << "[Blocked Mods Dialog] pending hash tasks:" << m_pending_hash_paths;
|
|
|
|
m_rehash_pending = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-12 04:37:57 +05:30
|
|
|
void BlockedModsDialog::hashTaskFinished()
|
|
|
|
{
|
2022-11-12 04:15:40 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] All hash tasks finished";
|
|
|
|
if (m_rehash_pending) {
|
2022-11-12 05:03:52 +05:30
|
|
|
qDebug() << "[Blocked Mods Dialog] task finished with a rehash pending, rerunning";
|
2022-11-12 04:15:40 +05:30
|
|
|
runHashTask();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-26 08:48:14 +05:30
|
|
|
/// qDebug print support for the BlockedMod struct
|
2022-11-01 19:36:36 +05:30
|
|
|
QDebug operator<<(QDebug debug, const BlockedMod& m)
|
|
|
|
{
|
2022-10-24 16:38:38 +05:30
|
|
|
QDebugStateSaver saver(debug);
|
|
|
|
|
2022-11-01 19:36:36 +05:30
|
|
|
debug.nospace() << "{ name: " << m.name << ", websiteUrl: " << m.websiteUrl << ", hash: " << m.hash << ", matched: " << m.matched
|
|
|
|
<< ", localPath: " << m.localPath << "}";
|
2022-10-24 16:38:38 +05:30
|
|
|
|
|
|
|
return debug;
|
2022-10-26 08:48:14 +05:30
|
|
|
}
|