properly handle a currently running hashing task
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
5909af9878
commit
3f6cc17818
@ -396,7 +396,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop)
|
|||||||
tr("The following files are not available for download in third party launchers.<br/>"
|
tr("The following files are not available for download in third party launchers.<br/>"
|
||||||
"You will need to manually download them and add them to the instance.<br/><br/>"
|
"You will need to manually download them and add them to the instance.<br/><br/>"
|
||||||
"Your configured global mods folder and default downloads folder<br/>"
|
"Your configured global mods folder and default downloads folder<br/>"
|
||||||
"are automatically checked for the downloaded mods.<br/>"
|
"are automatically checked for the downloaded mods and they will be copied to the instance if found.<br/>"
|
||||||
"Optionally, you may drag and drop the downloaded mods onto this dialog or add a folder to watch<br/>"
|
"Optionally, you may drag and drop the downloaded mods onto this dialog or add a folder to watch<br/>"
|
||||||
"if you did not download the mods to a default location."),
|
"if you did not download the mods to a default location."),
|
||||||
blocked_mods);
|
blocked_mods);
|
||||||
|
@ -214,7 +214,7 @@ void PackInstallTask::onResolveModsSucceeded()
|
|||||||
tr("The following files are not available for download in third party launchers.<br/>"
|
tr("The following files are not available for download in third party launchers.<br/>"
|
||||||
"You will need to manually download them and add them to the instance.<br/><br/>"
|
"You will need to manually download them and add them to the instance.<br/><br/>"
|
||||||
"Your configured global mods folder and default downloads folder<br/>"
|
"Your configured global mods folder and default downloads folder<br/>"
|
||||||
"are automatically checked for the downloaded mods.<br/>"
|
"are automatically checked for the downloaded mods and they will be copied to the instance if found.<br/>"
|
||||||
"Optionally, you may drag and drop the downloaded mods onto this dialog or add a folder to watch<br/>"
|
"Optionally, you may drag and drop the downloaded mods onto this dialog or add a folder to watch<br/>"
|
||||||
"if you did not download the mods to a default location."),
|
"if you did not download the mods to a default location."),
|
||||||
m_blocked_mods);
|
m_blocked_mods);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "BlockedModsDialog.h"
|
#include "BlockedModsDialog.h"
|
||||||
|
#include <qfileinfo.h>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
@ -13,9 +14,10 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
|
||||||
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
|
BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList<BlockedMod>& mods)
|
||||||
: QDialog(parent), ui(new Ui::BlockedModsDialog), mods(mods)
|
: QDialog(parent), ui(new Ui::BlockedModsDialog), m_mods(mods)
|
||||||
{
|
{
|
||||||
hashing_task = shared_qobject_ptr<ConcurrentTask>(new ConcurrentTask(this, "MakeHashesTask", 10));
|
m_hashing_task = shared_qobject_ptr<ConcurrentTask>(new ConcurrentTask(this, "MakeHashesTask", 10));
|
||||||
|
connect(m_hashing_task.get(), &Task::finished, this, &BlockedModsDialog::hashTaskFinished);
|
||||||
|
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
@ -25,11 +27,11 @@ BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, cons
|
|||||||
auto downloadFolderButton = ui->buttonBox->addButton(tr("Add Download Folder"), QDialogButtonBox::ActionRole);
|
auto downloadFolderButton = ui->buttonBox->addButton(tr("Add Download Folder"), QDialogButtonBox::ActionRole);
|
||||||
connect(downloadFolderButton, &QPushButton::clicked, this, &BlockedModsDialog::addDownloadFolder);
|
connect(downloadFolderButton, &QPushButton::clicked, this, &BlockedModsDialog::addDownloadFolder);
|
||||||
|
|
||||||
connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged);
|
connect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
qDebug() << "Mods List: " << mods;
|
qDebug() << "[Blocked Mods Dialog] Mods List: " << mods;
|
||||||
|
|
||||||
setupWatch();
|
setupWatch();
|
||||||
scanPaths();
|
scanPaths();
|
||||||
@ -57,16 +59,23 @@ void BlockedModsDialog::dragEnterEvent(QDragEnterEvent *e) {
|
|||||||
void BlockedModsDialog::dropEvent(QDropEvent *e)
|
void BlockedModsDialog::dropEvent(QDropEvent *e)
|
||||||
{
|
{
|
||||||
foreach (const QUrl &url, e->mimeData()->urls()) {
|
foreach (const QUrl &url, e->mimeData()->urls()) {
|
||||||
QString file = url.toLocalFile();
|
QString filePath = url.toLocalFile();
|
||||||
qDebug() << "Dropped file:" << file;
|
qDebug() << "[Blocked Mods Dialog] Dropped file:" << filePath;
|
||||||
addHashTask(file);
|
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);
|
||||||
}
|
}
|
||||||
hashing_task->start();
|
scanPaths();
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BlockedModsDialog::openAll()
|
void BlockedModsDialog::openAll()
|
||||||
{
|
{
|
||||||
for (auto& mod : mods) {
|
for (auto& mod : m_mods) {
|
||||||
QDesktopServices::openUrl(mod.websiteUrl);
|
QDesktopServices::openUrl(mod.websiteUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,8 +86,10 @@ void BlockedModsDialog::addDownloadFolder() {
|
|||||||
tr("Select directory where you downloaded the mods"),
|
tr("Select directory where you downloaded the mods"),
|
||||||
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
|
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation),
|
||||||
QFileDialog::ShowDirsOnly);
|
QFileDialog::ShowDirsOnly);
|
||||||
watcher.addPath(dir);
|
qDebug() << "[Blocked Mods Dialog] Adding watch path:" << dir;
|
||||||
scanPath(dir);
|
m_watcher.addPath(dir);
|
||||||
|
scanPath(dir, true);
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief update UI with current status of the blocked mod detection
|
/// @brief update UI with current status of the blocked mod detection
|
||||||
@ -87,7 +98,7 @@ void BlockedModsDialog::update()
|
|||||||
QString text;
|
QString text;
|
||||||
QString span;
|
QString span;
|
||||||
|
|
||||||
for (auto& mod : mods) {
|
for (auto& mod : m_mods) {
|
||||||
if (mod.matched) {
|
if (mod.matched) {
|
||||||
// ✔ -> html for HEAVY CHECK MARK : ✔
|
// ✔ -> html for HEAVY CHECK MARK : ✔
|
||||||
span = QString(tr("<span style=\"color:green\"> ✔ Found at %1 </span>")).arg(mod.localPath);
|
span = QString(tr("<span style=\"color:green\"> ✔ Found at %1 </span>")).arg(mod.localPath);
|
||||||
@ -111,9 +122,9 @@ void BlockedModsDialog::update()
|
|||||||
/// @param path the path to the changed directory
|
/// @param path the path to the changed directory
|
||||||
void BlockedModsDialog::directoryChanged(QString path)
|
void BlockedModsDialog::directoryChanged(QString path)
|
||||||
{
|
{
|
||||||
qDebug() << "Directory changed: " << path;
|
qDebug() << "[Blocked Mods Dialog] Directory changed: " << path;
|
||||||
validateMatchedMods();
|
validateMatchedMods();
|
||||||
scanPath(path);
|
scanPath(path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief add the user downloads folder and the global mods folder to the filesystem watcher
|
/// @brief add the user downloads folder and the global mods folder to the filesystem watcher
|
||||||
@ -121,22 +132,23 @@ void BlockedModsDialog::setupWatch()
|
|||||||
{
|
{
|
||||||
const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
|
||||||
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
|
const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString();
|
||||||
watcher.addPath(downloadsFolder);
|
m_watcher.addPath(downloadsFolder);
|
||||||
watcher.addPath(modsFolder);
|
m_watcher.addPath(modsFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief scan all watched folder
|
/// @brief scan all watched folder
|
||||||
void BlockedModsDialog::scanPaths()
|
void BlockedModsDialog::scanPaths()
|
||||||
{
|
{
|
||||||
for (auto& dir : watcher.directories()) {
|
for (auto& dir : m_watcher.directories()) {
|
||||||
scanPath(dir);
|
scanPath(dir, false);
|
||||||
}
|
}
|
||||||
|
runHashTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Scan the directory at path, skip paths that do not contain a file name
|
/// @brief Scan the directory at path, skip paths that do not contain a file name
|
||||||
/// of a blocked mod we are looking for
|
/// of a blocked mod we are looking for
|
||||||
/// @param path the directory to scan
|
/// @param path the directory to scan
|
||||||
void BlockedModsDialog::scanPath(QString path)
|
void BlockedModsDialog::scanPath(QString path, bool start_task)
|
||||||
{
|
{
|
||||||
QDir scan_dir(path);
|
QDir scan_dir(path);
|
||||||
QDirIterator scan_it(path, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::NoIteratorFlags);
|
QDirIterator scan_it(path, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::NoIteratorFlags);
|
||||||
@ -150,21 +162,35 @@ void BlockedModsDialog::scanPath(QString path)
|
|||||||
addHashTask(file);
|
addHashTask(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
hashing_task->start();
|
if (start_task) {
|
||||||
|
runHashTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// @brief add a hashing task for the file located at path, add the path to the pending set if the hasing task is already running
|
||||||
|
/// @param path the path to the local file being hashed
|
||||||
|
void BlockedModsDialog::addHashTask(QString path) {
|
||||||
|
if (m_hashing_task->isRunning()) {
|
||||||
|
qDebug() << "[Blocked Mods Dialog] adding a Hash task for" << path << "to the pending set.";
|
||||||
|
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
|
||||||
/// our blocked mods list
|
/// our blocked mods list
|
||||||
/// @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::buildHashTask(QString path) {
|
||||||
auto hash_task = Hashing::createBlockedModHasher(path, ModPlatform::Provider::FLAME, "sha1");
|
auto hash_task = Hashing::createBlockedModHasher(path, ModPlatform::Provider::FLAME, "sha1");
|
||||||
|
|
||||||
qDebug() << "Creating Hash task for path: " << path;
|
qDebug() << "[Blocked Mods Dialog] Creating Hash task for path: " << path;
|
||||||
|
|
||||||
connect(hash_task.get(), &Task::succeeded, [this, hash_task, path] { checkMatchHash(hash_task->getResult(), path); });
|
connect(hash_task.get(), &Task::succeeded, [this, hash_task, path] { checkMatchHash(hash_task->getResult(), path); });
|
||||||
connect(hash_task.get(), &Task::failed, [path] { qDebug() << "Failed to hash path: " << path; });
|
connect(hash_task.get(), &Task::failed, [path] { qDebug() << "Failed to hash path: " << path; });
|
||||||
|
|
||||||
hashing_task->addTask(hash_task);
|
m_hashing_task->addTask(hash_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief check if the computed hash for the provided path matches a blocked
|
/// @brief check if the computed hash for the provided path matches a blocked
|
||||||
@ -175,9 +201,9 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path)
|
|||||||
{
|
{
|
||||||
bool match = false;
|
bool match = false;
|
||||||
|
|
||||||
qDebug() << "Checking for match on hash: " << hash << "| From path:" << path;
|
qDebug() << "[Blocked Mods Dialog] Checking for match on hash: " << hash << "| From path:" << path;
|
||||||
|
|
||||||
for (auto& mod : mods) {
|
for (auto& mod : m_mods) {
|
||||||
if (mod.matched) {
|
if (mod.matched) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -186,7 +212,7 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path)
|
|||||||
mod.localPath = path;
|
mod.localPath = path;
|
||||||
match = true;
|
match = true;
|
||||||
|
|
||||||
qDebug() << "Hash match found:" << mod.name << hash << "| From path:" << path;
|
qDebug() << "[Blocked Mods Dialog] Hash match found:" << mod.name << hash << "| From path:" << path;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -205,9 +231,9 @@ bool BlockedModsDialog::checkValidPath(QString path)
|
|||||||
QFileInfo file = QFileInfo(path);
|
QFileInfo file = QFileInfo(path);
|
||||||
QString filename = file.fileName();
|
QString filename = file.fileName();
|
||||||
|
|
||||||
for (auto& mod : mods) {
|
for (auto& mod : m_mods) {
|
||||||
if (mod.name.compare(filename, Qt::CaseInsensitive) == 0) {
|
if (mod.name.compare(filename, Qt::CaseInsensitive) == 0) {
|
||||||
qDebug() << "Name match found:" << mod.name << "| From path:" << path;
|
qDebug() << "[Blocked Mods Dialog] Name match found:" << mod.name << "| From path:" << path;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,13 +243,13 @@ bool BlockedModsDialog::checkValidPath(QString path)
|
|||||||
|
|
||||||
bool BlockedModsDialog::allModsMatched()
|
bool BlockedModsDialog::allModsMatched()
|
||||||
{
|
{
|
||||||
return std::all_of(mods.begin(), mods.end(), [](auto const& mod) { return mod.matched; });
|
return std::all_of(m_mods.begin(), m_mods.end(), [](auto const& mod) { return mod.matched; });
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief ensure matched file paths still exist
|
/// @brief ensure matched file paths still exist
|
||||||
void BlockedModsDialog::validateMatchedMods() {
|
void BlockedModsDialog::validateMatchedMods() {
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
for (auto& mod : mods) {
|
for (auto& mod : m_mods) {
|
||||||
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()) {
|
||||||
@ -238,6 +264,33 @@ void BlockedModsDialog::validateMatchedMods() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @brief run hast task or mark a pending run if it is already runing
|
||||||
|
void BlockedModsDialog::runHashTask() {
|
||||||
|
if (!m_hashing_task->isRunning()) {
|
||||||
|
m_rehash_pending = false;
|
||||||
|
m_hashing_task->start();
|
||||||
|
} 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BlockedModsDialog::hashTaskFinished() {
|
||||||
|
qDebug() << "[Blocked Mods Dialog] All hash tasks finished";
|
||||||
|
if (m_rehash_pending) {
|
||||||
|
qDebug() << "[Blocked Mods Dialog] there was a pending rehash, 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
runHashTask();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// qDebug print support for the BlockedMod struct
|
/// qDebug print support for the BlockedMod struct
|
||||||
QDebug operator<<(QDebug debug, const BlockedMod& m)
|
QDebug operator<<(QDebug debug, const BlockedMod& m)
|
||||||
{
|
{
|
||||||
|
@ -39,9 +39,11 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::BlockedModsDialog *ui;
|
Ui::BlockedModsDialog *ui;
|
||||||
QList<BlockedMod> &mods;
|
QList<BlockedMod> &m_mods;
|
||||||
QFileSystemWatcher watcher;
|
QFileSystemWatcher m_watcher;
|
||||||
shared_qobject_ptr<ConcurrentTask> hashing_task;
|
shared_qobject_ptr<ConcurrentTask> m_hashing_task;
|
||||||
|
QSet<QString> m_pending_hash_paths;
|
||||||
|
bool m_rehash_pending;
|
||||||
|
|
||||||
void openAll();
|
void openAll();
|
||||||
void addDownloadFolder();
|
void addDownloadFolder();
|
||||||
@ -49,10 +51,13 @@ private:
|
|||||||
void directoryChanged(QString path);
|
void directoryChanged(QString path);
|
||||||
void setupWatch();
|
void setupWatch();
|
||||||
void scanPaths();
|
void scanPaths();
|
||||||
void scanPath(QString path);
|
void scanPath(QString path, bool start_task);
|
||||||
void addHashTask(QString path);
|
void addHashTask(QString path);
|
||||||
|
void buildHashTask(QString path);
|
||||||
void checkMatchHash(QString hash, QString path);
|
void checkMatchHash(QString hash, QString path);
|
||||||
void validateMatchedMods();
|
void validateMatchedMods();
|
||||||
|
void runHashTask();
|
||||||
|
void hashTaskFinished();
|
||||||
|
|
||||||
bool checkValidPath(QString path);
|
bool checkValidPath(QString path);
|
||||||
bool allModsMatched();
|
bool allModsMatched();
|
||||||
|
Loading…
Reference in New Issue
Block a user