From 028e086960402f685e07163def36d6b5eee1b796 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Mon, 24 Oct 2022 04:08:38 -0700 Subject: [PATCH 01/10] send blocked mod info to dialog & prototype UI Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- .../flame/FlameInstanceCreationTask.cpp | 18 +++++--- .../modpacksch/FTBPackInstallTask.cpp | 22 ++++++---- launcher/ui/dialogs/BlockedModsDialog.cpp | 42 +++++++++++++++++-- launcher/ui/dialogs/BlockedModsDialog.h | 16 ++++++- 4 files changed, 78 insertions(+), 20 deletions(-) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 48ac02e0..15e660a9 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -372,13 +372,20 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) auto results = m_mod_id_resolver->getResults(); // first check for blocked mods - QString text; - QList urls; + QList blocked_mods; auto anyBlocked = false; for (const auto& result : results.files.values()) { if (!result.resolved || result.url.isEmpty()) { - text += QString("%1: %2
").arg(result.fileName, result.websiteUrl); - urls.append(QUrl(result.websiteUrl)); + + BlockedMod blocked_mod; + blocked_mod.name = result.fileName; + blocked_mod.websiteUrl = result.websiteUrl; + blocked_mod.hash = result.hash; + blocked_mod.matched = false; + blocked_mod.localPath = ""; + + blocked_mods.append(blocked_mod); + anyBlocked = true; } } @@ -388,8 +395,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) auto message_dialog = new BlockedModsDialog(m_parent, tr("Blocked mods found"), tr("The following mods were blocked on third party launchers.
" "You will need to manually download them and add them to the modpack"), - text, - urls); + blocked_mods); message_dialog->setModal(true); if (message_dialog->exec()) { diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 7b112d8f..75fda208 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -176,8 +176,7 @@ void PackInstallTask::resolveMods() void PackInstallTask::onResolveModsSucceeded() { - QString text; - QList urls; + QList blocked_mods; auto anyBlocked = false; Flame::Manifest results = m_mod_id_resolver_task->getResults(); @@ -191,11 +190,19 @@ void PackInstallTask::onResolveModsSucceeded() // First check for blocked mods if (!results_file.resolved || results_file.url.isEmpty()) { - QString type(local_file.type); + // QString type(local_file.type); + + // type[0] = type[0].toUpper(); + + BlockedMod blocked_mod; + blocked_mod.name = local_file.name; + blocked_mod.websiteUrl = results_file.websiteUrl; + blocked_mod.hash = results_file.hash; + blocked_mod.matched = false; + blocked_mod.localPath = ""; + + blocked_mods.append(blocked_mod); - type[0] = type[0].toUpper(); - text += QString("%1: %2 - %3
").arg(type, local_file.name, results_file.websiteUrl); - urls.append(QUrl(results_file.websiteUrl)); anyBlocked = true; } else { local_file.url = results_file.url.toString(); @@ -210,8 +217,7 @@ void PackInstallTask::onResolveModsSucceeded() auto message_dialog = new BlockedModsDialog(m_parent, tr("Blocked files found"), tr("The following files are not available for download in third party launchers.
" "You will need to manually download them and add them to the instance."), - text, - urls); + blocked_mods); if (message_dialog->exec() == QDialog::Accepted) createInstance(); diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index fe87b517..e29f8eb3 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -4,17 +4,22 @@ #include #include +#include -BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, const QString &body, const QList &urls) : - QDialog(parent), ui(new Ui::BlockedModsDialog), urls(urls) { + +BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, const QList &mods) : + QDialog(parent), ui(new Ui::BlockedModsDialog), mods(mods) { ui->setupUi(this); auto openAllButton = ui->buttonBox->addButton(tr("Open All"), QDialogButtonBox::ActionRole); connect(openAllButton, &QPushButton::clicked, this, &BlockedModsDialog::openAll); + qDebug() << "Mods List: " << mods; + this->setWindowTitle(title); ui->label->setText(text); ui->textBrowser->setText(body); + update(); } BlockedModsDialog::~BlockedModsDialog() { @@ -22,7 +27,36 @@ BlockedModsDialog::~BlockedModsDialog() { } void BlockedModsDialog::openAll() { - for(auto &url : urls) { - QDesktopServices::openUrl(url); + for(auto &mod : mods) { + QDesktopServices::openUrl(mod.websiteUrl); } } + +void BlockedModsDialog::update() { + QString text; + QString span; + + for (auto &mod : mods) { + if (mod.matched) { + // ✔ -> html for HEAVY CHECK MARK : ✔ + span = QString(" ✔ Found at %1 ").arg(mod.localPath); + } else { + // ✘ -> html for HEAVY BALLOT X : ✘ + span = QString(" ✘ Not Found "); + } + text += QString("%1: %2

Hash: %3 %4


").arg(mod.name, mod.websiteUrl, mod.hash, span); + } + + ui->textBrowser->setText(text); +} + + +QDebug operator<<(QDebug debug, const BlockedMod &m) { + QDebugStateSaver saver(debug); + + debug.nospace() << "{ name: " << m.name << ", websiteUrl: " << m.websiteUrl + << ", hash: " << m.hash << ", matched: " << m.matched + << ", localPath: " << m.localPath <<"}"; + + return debug; +} \ No newline at end of file diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index 5f5bd61b..4be020ec 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -3,6 +3,15 @@ #include +struct BlockedMod { + QString name; + QString websiteUrl; + QString hash; + bool matched; + QString localPath; + +}; + QT_BEGIN_NAMESPACE namespace Ui { class BlockedModsDialog; } QT_END_NAMESPACE @@ -11,12 +20,15 @@ class BlockedModsDialog : public QDialog { Q_OBJECT public: - BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, const QString &body, const QList &urls); + BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, const QList &mods); ~BlockedModsDialog() override; + private: Ui::BlockedModsDialog *ui; - const QList &urls; + const QList &mods; void openAll(); + void update(); }; + From 1598d6582473f1bb6aa02fd9b4dabc8210771e56 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Tue, 25 Oct 2022 01:19:19 -0700 Subject: [PATCH 02/10] watch filesystem, compute and match hashes Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/modplatform/helpers/HashUtils.cpp | 58 ++++++++++ launcher/modplatform/helpers/HashUtils.h | 15 +++ launcher/ui/dialogs/BlockedModsDialog.cpp | 120 ++++++++++++++++++++- launcher/ui/dialogs/BlockedModsDialog.h | 23 +++- 4 files changed, 212 insertions(+), 4 deletions(-) diff --git a/launcher/modplatform/helpers/HashUtils.cpp b/launcher/modplatform/helpers/HashUtils.cpp index a7bbaba5..bf53aa0e 100644 --- a/launcher/modplatform/helpers/HashUtils.cpp +++ b/launcher/modplatform/helpers/HashUtils.cpp @@ -35,6 +35,18 @@ Hasher::Ptr createFlameHasher(QString file_path) return new FlameHasher(file_path); } +Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider) +{ + return new BlockedModHasher(file_path, provider); +} + +Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider, QString type) +{ + auto hasher = new BlockedModHasher(file_path, provider); + hasher->useHashType(type); + return hasher; +} + void ModrinthHasher::executeTask() { QFile file(m_path); @@ -78,4 +90,50 @@ void FlameHasher::executeTask() } } + +BlockedModHasher::BlockedModHasher(QString file_path, ModPlatform::Provider provider) + : Hasher(file_path), provider(provider) { + setObjectName(QString("BlockedModHasher: %1").arg(file_path)); + hash_type = ProviderCaps.hashType(provider).first(); +} + +void BlockedModHasher::executeTask() +{ + QFile file(m_path); + + try { + file.open(QFile::ReadOnly); + } catch (FS::FileSystemException& e) { + qCritical() << QString("Failed to open JAR file in %1").arg(m_path); + qCritical() << QString("Reason: ") << e.cause(); + + emitFailed("Failed to open file for hashing."); + return; + } + + m_hash = ProviderCaps.hash(provider, &file, hash_type); + + file.close(); + + if (m_hash.isEmpty()) { + emitFailed("Empty hash!"); + } else { + emitSucceeded(); + } +} + +QStringList BlockedModHasher::getHashTypes() { + return ProviderCaps.hashType(provider); +} + +bool BlockedModHasher::useHashType(QString type) { + auto types = ProviderCaps.hashType(provider); + if (types.contains(type)) { + hash_type = type; + return true; + } + qDebug() << "Bad hash type " << type << " for provider"; + return false; +} + } // namespace Hashing diff --git a/launcher/modplatform/helpers/HashUtils.h b/launcher/modplatform/helpers/HashUtils.h index 38fddf03..fa3244f6 100644 --- a/launcher/modplatform/helpers/HashUtils.h +++ b/launcher/modplatform/helpers/HashUtils.h @@ -40,8 +40,23 @@ class ModrinthHasher : public Hasher { void executeTask() override; }; +class BlockedModHasher : public Hasher { + public: + BlockedModHasher(QString file_path, ModPlatform::Provider provider); + + void executeTask() override; + + QStringList getHashTypes(); + bool useHashType(QString type); + private: + ModPlatform::Provider provider; + QString hash_type; +}; + Hasher::Ptr createHasher(QString file_path, ModPlatform::Provider provider); Hasher::Ptr createFlameHasher(QString file_path); Hasher::Ptr createModrinthHasher(QString file_path); +Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider); +Hasher::Ptr createBlockedModHasher(QString file_path, ModPlatform::Provider provider, QString type); } // namespace Hashing diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index e29f8eb3..9ba033d7 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -1,3 +1,6 @@ +#include +#include +#include "Application.h" #include "BlockedModsDialog.h" #include "ui_BlockedModsDialog.h" #include @@ -5,20 +8,29 @@ #include #include +#include -BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, const QList &mods) : + + +BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, QList &mods) : QDialog(parent), ui(new Ui::BlockedModsDialog), mods(mods) { ui->setupUi(this); auto openAllButton = ui->buttonBox->addButton(tr("Open All"), QDialogButtonBox::ActionRole); connect(openAllButton, &QPushButton::clicked, this, &BlockedModsDialog::openAll); + connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged); + + hashing_task = shared_qobject_ptr(new ConcurrentTask(this, "MakeHashesTask", 10)); + qDebug() << "Mods List: " << mods; + setupWatch(); + scanPaths(true); + this->setWindowTitle(title); ui->label->setText(text); - ui->textBrowser->setText(body); update(); } @@ -50,6 +62,110 @@ void BlockedModsDialog::update() { ui->textBrowser->setText(text); } +void BlockedModsDialog::directoryChanged(QString path) { + qDebug() << "Directory changed: " << path; + scanPath(path, false); +} + + +void BlockedModsDialog::setupWatch() { + const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); + const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString(); + watcher.addPath(downloadsFolder); + watcher.addPath(modsFolder); +} + +void BlockedModsDialog::scanPaths(bool init) { + for (auto &dir : watcher.directories()) { + scanPath(dir, init); + } +} + +void BlockedModsDialog::scanPath(QString path, bool init) { + + 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 (checked_paths.contains(file)){ + continue; + } + + if (!checkValidPath(file)) { + continue; + } + + auto hash_task = Hashing::createBlockedModHasher(file, ModPlatform::Provider::FLAME, "sha1"); + + qDebug() << "Creating Hash task for path: " << file; + + connect(hash_task.get(), &Task::succeeded, [this, hash_task, file] { + checkMatchHash(hash_task->getResult(), file); + }); + connect(hash_task.get(), &Task::failed, [this, hash_task, file] { + qDebug() << "Failed to hash path: " << file; + }); + + if (init) { + checked_paths.insert(file); + } + + hashing_task->addTask(hash_task); + } + + hashing_task->start(); + +} + +void BlockedModsDialog::checkMatchHash(QString hash, QString path) { + bool match = false; + + qDebug() << "Checking for match on hash: " << hash << " | From path:" << path; + + for (auto &mod : mods) { + if (mod.matched) { + continue; + } + if (mod.hash.compare(hash, Qt::CaseInsensitive) == 0) { + mod.matched = true; + mod.localPath = path; + match = true; + + qDebug() << "Hash match found: " << mod.name << " " << hash << " | From path:" << path; + + break; + } + } + + if (match) { + update(); + } +} + +bool BlockedModsDialog::checkValidPath(QString path) { + + QFileInfo file = QFileInfo(path); + QString filename = file.fileName(); + + for (auto &mod : mods) { + if (mod.name.compare(filename, Qt::CaseInsensitive) == 0) { + qDebug() << "Name match found: " << mod.name << " | From path:" << path; + return true; + } + } + + return false; +} + +bool BlockedModsDialog::allModsMatched() { + for (auto &mod : mods) { + if (!mod.matched) + return false; + } + return true; +} + QDebug operator<<(QDebug debug, const BlockedMod &m) { QDebugStateSaver saver(debug); diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index 4be020ec..f1ea99ca 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -1,7 +1,14 @@ #pragma once #include +#include +#include +#include + +#include "modplatform/helpers/HashUtils.h" + +#include "tasks/ConcurrentTask.h" struct BlockedMod { QString name; @@ -20,15 +27,27 @@ class BlockedModsDialog : public QDialog { Q_OBJECT public: - BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, const QList &mods); + BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, QList &mods); ~BlockedModsDialog() override; private: Ui::BlockedModsDialog *ui; - const QList &mods; + QList &mods; + QFileSystemWatcher watcher; + shared_qobject_ptr hashing_task; + QSet checked_paths; + void openAll(); void update(); + void directoryChanged(QString path); + void setupWatch(); + void scanPaths(bool init); + void scanPath(QString path, bool init); + void checkMatchHash(QString hash, QString path); + + bool checkValidPath(QString path); + bool allModsMatched(); }; From 13c7efa0584caf34950a6e6efa4b8e3bee16d764 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Tue, 25 Oct 2022 10:59:37 -0700 Subject: [PATCH 03/10] copy found mods to instance (FTB and Flame) Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/FileSystem.cpp | 22 +++++++++ launcher/FileSystem.h | 2 + .../flame/FlameInstanceCreationTask.cpp | 35 +++++++++++++- .../flame/FlameInstanceCreationTask.h | 3 ++ .../modpacksch/FTBPackInstallTask.cpp | 46 +++++++++++++++++-- .../modpacksch/FTBPackInstallTask.h | 3 ++ launcher/ui/dialogs/BlockedModsDialog.cpp | 7 +++ launcher/ui/dialogs/BlockedModsDialog.h | 1 + launcher/ui/dialogs/BlockedModsDialog.ui | 37 +++++++++------ 9 files changed, 137 insertions(+), 19 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 4026d6c1..4285fa87 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -163,6 +163,28 @@ bool ensureFolderPathExists(QString foldernamepath) return success; } +bool copyFile(QString &src, QString &dst) { + using copy_opts = fs::copy_options; + + std::error_code err; + + fs::copy_options opt = copy_opts::none; + // The default behavior is to follow symlinks + opt |= copy_opts::copy_symlinks; + + ensureFilePathExists(dst); + + fs::copy(toStdString(src), toStdString(dst), opt, err); + if (err) { + qWarning() << "Failed to copy files:" << QString::fromStdString(err.message()); + qDebug() << "Source file:" << src; + qDebug() << "Destination file:" << dst; + } + + return err.value() == 0; + +} + bool copy::operator()(const QString& offset) { using copy_opts = fs::copy_options; diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index b46f3281..68f6bc4c 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -75,6 +75,8 @@ bool ensureFilePathExists(QString filenamepath); */ bool ensureFolderPathExists(QString filenamepath); +bool copyFile(QString &src, QString &dst); + class copy { public: copy(const QString& src, const QString& dst) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 15e660a9..fbc4ecf3 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -399,6 +399,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) message_dialog->setModal(true); if (message_dialog->exec()) { + copyBlockedMods(blocked_mods); setupDownloadJob(loop); } else { m_mod_id_resolver.reset(); @@ -410,6 +411,36 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) } } +void FlameCreationTask::copyBlockedMods(QList blocked_mods) { + + setStatus(tr("Copying Blocked Mods...")); + setAbortable(false); + int i = 0; + int total = blocked_mods.length(); + setProgress(i, total); + for (auto mod = blocked_mods.begin(); mod != blocked_mods.end(); mod++, i++) { + + if (!mod->matched) { + qDebug() << mod->name << "was not matched to a local file, skipping copy"; + continue; + } + + auto dest_path = FS::PathCombine(m_stagingPath, "minecraft", "mods", mod->name); + + setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total))); + + qDebug() << "Will try to copy" << mod->localPath << "to" << dest_path; + + if (!FS::copyFile(mod->localPath, dest_path)) { + qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed"; + } + + setProgress(i+1, total); + } + + setAbortable(true); +} + void FlameCreationTask::setupDownloadJob(QEventLoop& loop) { m_files_job = new NetJob(tr("Mod download"), APPLICATION->network()); @@ -455,7 +486,9 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop) m_files_job.reset(); setError(reason); }); - connect(m_files_job.get(), &NetJob::progress, [&](qint64 current, qint64 total) { setProgress(current, total); }); + connect(m_files_job.get(), &NetJob::progress, [&](qint64 current, qint64 total) { + setProgress(current, total); + }); connect(m_files_job.get(), &NetJob::finished, &loop, &QEventLoop::quit); setStatus(tr("Downloading mods...")); diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.h b/launcher/modplatform/flame/FlameInstanceCreationTask.h index ded0e2ce..69a8f1ab 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.h +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.h @@ -10,6 +10,8 @@ #include "net/NetJob.h" +#include "ui/dialogs/BlockedModsDialog.h" + class FlameCreationTask final : public InstanceCreationTask { Q_OBJECT @@ -29,6 +31,7 @@ class FlameCreationTask final : public InstanceCreationTask { private slots: void idResolverSucceeded(QEventLoop&); void setupDownloadJob(QEventLoop&); + void copyBlockedMods(QList blocked_mods); private: QWidget* m_parent = nullptr; diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 75fda208..f6bf2488 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -176,7 +176,6 @@ void PackInstallTask::resolveMods() void PackInstallTask::onResolveModsSucceeded() { - QList blocked_mods; auto anyBlocked = false; Flame::Manifest results = m_mod_id_resolver_task->getResults(); @@ -201,7 +200,7 @@ void PackInstallTask::onResolveModsSucceeded() blocked_mod.matched = false; blocked_mod.localPath = ""; - blocked_mods.append(blocked_mod); + m_blocked_mods.append(blocked_mod); anyBlocked = true; } else { @@ -217,12 +216,16 @@ void PackInstallTask::onResolveModsSucceeded() auto message_dialog = new BlockedModsDialog(m_parent, tr("Blocked files found"), tr("The following files are not available for download in third party launchers.
" "You will need to manually download them and add them to the instance."), - blocked_mods); + m_blocked_mods); - if (message_dialog->exec() == QDialog::Accepted) + if (message_dialog->exec() == QDialog::Accepted) { + qDebug() << "Post dialog mods list: " << m_blocked_mods; createInstance(); - else + } + else { abort(); + } + } else { createInstance(); } @@ -326,6 +329,9 @@ void PackInstallTask::downloadPack() void PackInstallTask::onModDownloadSucceeded() { m_net_job.reset(); + if (m_blocked_mods.length() > 0) { + copyBlockedMods(); + } emitSucceeded(); } @@ -349,4 +355,34 @@ void PackInstallTask::onModDownloadFailed(QString reason) emitFailed(reason); } +void PackInstallTask::copyBlockedMods() { + + setStatus(tr("Copying Blocked Mods...")); + setAbortable(false); + int i = 0; + int total = m_blocked_mods.length(); + setProgress(i, total); + for (auto mod = m_blocked_mods.begin(); mod != m_blocked_mods.end(); mod++, i++) { + + if (!mod->matched) { + qDebug() << mod->name << "was not matched to a local file, skipping copy"; + continue; + } + + auto dest_path = FS::PathCombine(m_stagingPath, ".minecraft", "mods", mod->name); + + setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total))); + + qDebug() << "Will try to copy" << mod->localPath << "to" << dest_path; + + if (!FS::copyFile(mod->localPath, dest_path)) { + qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed"; + } + + setProgress(i+1, total); + } + + setAbortable(true); +} + } // namespace ModpacksCH diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index 7c6fbeb9..2cd4d729 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -43,6 +43,7 @@ #include "QObjectPtr.h" #include "modplatform/flame/FileResolvingTask.h" #include "net/NetJob.h" +#include "ui/dialogs/BlockedModsDialog.h" #include @@ -76,6 +77,7 @@ private: void resolveMods(); void createInstance(); void downloadPack(); + void copyBlockedMods(); private: NetJob::Ptr m_net_job = nullptr; @@ -90,6 +92,7 @@ private: Version m_version; QMap m_files_to_copy; + QList m_blocked_mods; //FIXME: nuke QWidget* m_parent; diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index 9ba033d7..542d0681 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -31,6 +31,7 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons this->setWindowTitle(title); ui->label->setText(text); + ui->labelModsFound->setText("Please download the missing mods."); update(); } @@ -60,6 +61,12 @@ void BlockedModsDialog::update() { } ui->textBrowser->setText(text); + + if (allModsMatched()) { + ui->labelModsFound->setText("All mods found ✔"); + } else { + ui->labelModsFound->setText("Please download the missing mods."); + } } void BlockedModsDialog::directoryChanged(QString path) { diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index f1ea99ca..93b9f46a 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -51,3 +51,4 @@ private: bool allModsMatched(); }; +QDebug operator<<(QDebug debug, const BlockedMod &m); \ No newline at end of file diff --git a/launcher/ui/dialogs/BlockedModsDialog.ui b/launcher/ui/dialogs/BlockedModsDialog.ui index f4ae95b6..371549cf 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.ui +++ b/launcher/ui/dialogs/BlockedModsDialog.ui @@ -13,8 +13,8 @@ BlockedModsDialog - - + + @@ -24,17 +24,7 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - + true @@ -44,6 +34,27 @@ + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + From e9d4793b1e98944dad910b3952c117bb2d3369de Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Tue, 25 Oct 2022 20:18:14 -0700 Subject: [PATCH 04/10] minor clean up and add some docs Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/FileSystem.cpp | 7 ++++ launcher/FileSystem.h | 1 + .../flame/FlameInstanceCreationTask.cpp | 2 + .../modpacksch/FTBPackInstallTask.cpp | 4 +- launcher/ui/dialogs/BlockedModsDialog.cpp | 42 +++++++++++-------- launcher/ui/dialogs/BlockedModsDialog.h | 5 +-- 6 files changed, 38 insertions(+), 23 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 4285fa87..8fe441b3 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -163,6 +163,10 @@ bool ensureFolderPathExists(QString foldernamepath) return success; } +/// @brief Copy file at src to dest, ensures the full filepath exsists +/// @param src srouce file path +/// @param dst destination file path +/// @return boolean: was there an error during the filecopy? bool copyFile(QString &src, QString &dst) { using copy_opts = fs::copy_options; @@ -185,6 +189,9 @@ bool copyFile(QString &src, QString &dst) { } +/// @brief Copies a directory and it's contents from src to dest +/// @param offset subdirectory form src to copy to dest +/// @return if there was an error during the filecopy bool copy::operator()(const QString& offset) { using copy_opts = fs::copy_options; diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index 68f6bc4c..ab006d48 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -77,6 +77,7 @@ bool ensureFolderPathExists(QString filenamepath); bool copyFile(QString &src, QString &dst); +/// @brief Copies a directory and it's contents from src to dest class copy { public: copy(const QString& src, const QString& dst) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index fbc4ecf3..edacb819 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -411,6 +411,8 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) } } +/// @brief copy the matched blocked mods to the instance staging area +/// @param blocked_mods list of the blocked mods and their matched paths void FlameCreationTask::copyBlockedMods(QList blocked_mods) { setStatus(tr("Copying Blocked Mods...")); diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index f6bf2488..49fbafd6 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -189,9 +189,6 @@ void PackInstallTask::onResolveModsSucceeded() // First check for blocked mods if (!results_file.resolved || results_file.url.isEmpty()) { - // QString type(local_file.type); - - // type[0] = type[0].toUpper(); BlockedMod blocked_mod; blocked_mod.name = local_file.name; @@ -355,6 +352,7 @@ void PackInstallTask::onModDownloadFailed(QString reason) emitFailed(reason); } +/// @brief copy the matched blocked mods to the instance staging area void PackInstallTask::copyBlockedMods() { setStatus(tr("Copying Blocked Mods...")); diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index 542d0681..f5bc7f73 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -1,5 +1,3 @@ -#include -#include #include "Application.h" #include "BlockedModsDialog.h" #include "ui_BlockedModsDialog.h" @@ -27,7 +25,7 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons qDebug() << "Mods List: " << mods; setupWatch(); - scanPaths(true); + scanPaths(); this->setWindowTitle(title); ui->label->setText(text); @@ -45,6 +43,7 @@ void BlockedModsDialog::openAll() { } } +/// @brief update UI with current status of the blocked mod detection void BlockedModsDialog::update() { QString text; QString span; @@ -69,12 +68,15 @@ void BlockedModsDialog::update() { } } +/// @brief Signal fired when a watched direcotry has changed +/// @param path the path to the changed directory void BlockedModsDialog::directoryChanged(QString path) { qDebug() << "Directory changed: " << path; - scanPath(path, false); + scanPath(path); } +/// @brief add the user downloads folder and the global mods folder to the filesystem watcher void BlockedModsDialog::setupWatch() { const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString(); @@ -82,23 +84,24 @@ void BlockedModsDialog::setupWatch() { watcher.addPath(modsFolder); } -void BlockedModsDialog::scanPaths(bool init) { + +/// @brief scan all watched folder +void BlockedModsDialog::scanPaths() { for (auto &dir : watcher.directories()) { - scanPath(dir, init); + scanPath(dir); } } -void BlockedModsDialog::scanPath(QString path, bool init) { +/// @brief Scan the directory at path, skip paths that do not contain a file name +/// of a blocked mod we are looking for +/// @param path the directory to scan +void BlockedModsDialog::scanPath(QString path) { 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 (checked_paths.contains(file)){ - continue; - } - if (!checkValidPath(file)) { continue; } @@ -113,10 +116,6 @@ void BlockedModsDialog::scanPath(QString path, bool init) { connect(hash_task.get(), &Task::failed, [this, hash_task, file] { qDebug() << "Failed to hash path: " << file; }); - - if (init) { - checked_paths.insert(file); - } hashing_task->addTask(hash_task); } @@ -125,6 +124,10 @@ void BlockedModsDialog::scanPath(QString path, bool init) { } +/// @brief check if the conputed hash for the provided path matches a blocked +/// mod we are looking for +/// @param hash the computed hash for the provided path +/// @param path the path to the local file being compared void BlockedModsDialog::checkMatchHash(QString hash, QString path) { bool match = false; @@ -150,6 +153,9 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path) { } } +/// @brief Check if the name of the file at path matches the naem of a blocked mod we are searching for +/// @param path the path to check +/// @return boolean: did the path match the name of a blocked mod? bool BlockedModsDialog::checkValidPath(QString path) { QFileInfo file = QFileInfo(path); @@ -165,6 +171,8 @@ bool BlockedModsDialog::checkValidPath(QString path) { return false; } +/// @brief have we found all the mods we're lookign for? +/// @return boolean bool BlockedModsDialog::allModsMatched() { for (auto &mod : mods) { if (!mod.matched) @@ -173,7 +181,7 @@ bool BlockedModsDialog::allModsMatched() { return true; } - +/// qDebug print support for the BlockedMod struct QDebug operator<<(QDebug debug, const BlockedMod &m) { QDebugStateSaver saver(debug); @@ -182,4 +190,4 @@ QDebug operator<<(QDebug debug, const BlockedMod &m) { << ", localPath: " << m.localPath <<"}"; return debug; -} \ No newline at end of file +} diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index 93b9f46a..cf1d3b3d 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -37,14 +37,13 @@ private: QList &mods; QFileSystemWatcher watcher; shared_qobject_ptr hashing_task; - QSet checked_paths; void openAll(); void update(); void directoryChanged(QString path); void setupWatch(); - void scanPaths(bool init); - void scanPath(QString path, bool init); + void scanPaths(); + void scanPath(QString path); void checkMatchHash(QString hash, QString path); bool checkValidPath(QString path); From d2f3dbaa2984b70a71e5fb1b246a31987a6fdf10 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:39:12 -0700 Subject: [PATCH 05/10] fix mispellings and wrap strings for translation Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/ui/dialogs/BlockedModsDialog.cpp | 18 ++++++++---------- launcher/ui/dialogs/BlockedModsDialog.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index f5bc7f73..136a7371 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -29,7 +29,7 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons this->setWindowTitle(title); ui->label->setText(text); - ui->labelModsFound->setText("Please download the missing mods."); + ui->labelModsFound->setText(tr("Please download the missing mods.")); update(); } @@ -51,20 +51,20 @@ void BlockedModsDialog::update() { for (auto &mod : mods) { if (mod.matched) { // ✔ -> html for HEAVY CHECK MARK : ✔ - span = QString(" ✔ Found at %1 ").arg(mod.localPath); + span = QString(tr(" ✔ Found at %1 ")).arg(mod.localPath); } else { // ✘ -> html for HEAVY BALLOT X : ✘ - span = QString(" ✘ Not Found "); + span = QString(tr(" ✘ Not Found ")); } - text += QString("%1: %2

Hash: %3 %4


").arg(mod.name, mod.websiteUrl, mod.hash, span); + text += QString(tr("%1: %2

Hash: %3 %4


")).arg(mod.name, mod.websiteUrl, mod.hash, span); } ui->textBrowser->setText(text); if (allModsMatched()) { - ui->labelModsFound->setText("All mods found ✔"); + ui->labelModsFound->setText(tr("All mods found ✔")); } else { - ui->labelModsFound->setText("Please download the missing mods."); + ui->labelModsFound->setText(tr("Please download the missing mods.")); } } @@ -124,7 +124,7 @@ void BlockedModsDialog::scanPath(QString path) { } -/// @brief check if the conputed hash for the provided path matches a blocked +/// @brief check if the computed hash for the provided path matches a blocked /// mod we are looking for /// @param hash the computed hash for the provided path /// @param path the path to the local file being compared @@ -153,7 +153,7 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path) { } } -/// @brief Check if the name of the file at path matches the naem of a blocked mod we are searching for +/// @brief Check if the name of the file at path matches the name of a blocked mod we are searching for /// @param path the path to check /// @return boolean: did the path match the name of a blocked mod? bool BlockedModsDialog::checkValidPath(QString path) { @@ -171,8 +171,6 @@ bool BlockedModsDialog::checkValidPath(QString path) { return false; } -/// @brief have we found all the mods we're lookign for? -/// @return boolean bool BlockedModsDialog::allModsMatched() { for (auto &mod : mods) { if (!mod.matched) diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index cf1d3b3d..0a5c90db 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -50,4 +50,4 @@ private: bool allModsMatched(); }; -QDebug operator<<(QDebug debug, const BlockedMod &m); \ No newline at end of file +QDebug operator<<(QDebug debug, const BlockedMod &m); From fda2c116bef33df2ca49d77ff4b016e724f47549 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:42:35 -0700 Subject: [PATCH 06/10] code quality cleanup Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/FileSystem.cpp | 2 +- launcher/FileSystem.h | 2 +- .../flame/FlameInstanceCreationTask.cpp | 23 +++++++++---------- .../flame/FlameInstanceCreationTask.h | 2 +- .../modpacksch/FTBPackInstallTask.cpp | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 8fe441b3..508da08d 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -167,7 +167,7 @@ bool ensureFolderPathExists(QString foldernamepath) /// @param src srouce file path /// @param dst destination file path /// @return boolean: was there an error during the filecopy? -bool copyFile(QString &src, QString &dst) { +bool copyFile(QString const& src, QString const& dst) { using copy_opts = fs::copy_options; std::error_code err; diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index ab006d48..771bda60 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -75,7 +75,7 @@ bool ensureFilePathExists(QString filenamepath); */ bool ensureFolderPathExists(QString filenamepath); -bool copyFile(QString &src, QString &dst); +bool copyFile(QString const& src, QString const& dst); /// @brief Copies a directory and it's contents from src to dest class copy { diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index edacb819..30438a1a 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -413,31 +413,32 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) /// @brief copy the matched blocked mods to the instance staging area /// @param blocked_mods list of the blocked mods and their matched paths -void FlameCreationTask::copyBlockedMods(QList blocked_mods) { +void FlameCreationTask::copyBlockedMods(QList const& blocked_mods) { setStatus(tr("Copying Blocked Mods...")); setAbortable(false); int i = 0; int total = blocked_mods.length(); setProgress(i, total); - for (auto mod = blocked_mods.begin(); mod != blocked_mods.end(); mod++, i++) { + for (auto &mod : blocked_mods) { - if (!mod->matched) { - qDebug() << mod->name << "was not matched to a local file, skipping copy"; + if (!mod.matched) { + qDebug() << mod.name << "was not matched to a local file, skipping copy"; continue; } - auto dest_path = FS::PathCombine(m_stagingPath, "minecraft", "mods", mod->name); + auto dest_path = FS::PathCombine(m_stagingPath, "minecraft", "mods", mod.name); setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total))); - qDebug() << "Will try to copy" << mod->localPath << "to" << dest_path; + qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path; - if (!FS::copyFile(mod->localPath, dest_path)) { - qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed"; + if (!FS::copyFile(mod.localPath, dest_path)) { // FIXME: use FS::copy once #333 is merged + qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed"; } - setProgress(i+1, total); + i++; + setProgress(i, total); } setAbortable(true); @@ -488,9 +489,7 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop) m_files_job.reset(); setError(reason); }); - connect(m_files_job.get(), &NetJob::progress, [&](qint64 current, qint64 total) { - setProgress(current, total); - }); + connect(m_files_job.get(), &NetJob::progress, this, &FlameCreationTask::setProgress); connect(m_files_job.get(), &NetJob::finished, &loop, &QEventLoop::quit); setStatus(tr("Downloading mods...")); diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.h b/launcher/modplatform/flame/FlameInstanceCreationTask.h index 69a8f1ab..fbc7d5bf 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.h +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.h @@ -31,7 +31,7 @@ class FlameCreationTask final : public InstanceCreationTask { private slots: void idResolverSucceeded(QEventLoop&); void setupDownloadJob(QEventLoop&); - void copyBlockedMods(QList blocked_mods); + void copyBlockedMods(QList const& blocked_mods); private: QWidget* m_parent = nullptr; diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 49fbafd6..5091db0c 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -326,7 +326,7 @@ void PackInstallTask::downloadPack() void PackInstallTask::onModDownloadSucceeded() { m_net_job.reset(); - if (m_blocked_mods.length() > 0) { + if (!m_blocked_mods.isEmpty()) { copyBlockedMods(); } emitSucceeded(); From a7a331a26e43df3dbafdbb29a59d38ba807ffa7d Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Sun, 30 Oct 2022 22:49:54 -0700 Subject: [PATCH 07/10] ensure FS::copyFile is marked for removal Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/FileSystem.h | 1 + launcher/modplatform/modpacksch/FTBPackInstallTask.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index 771bda60..11981f68 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -75,6 +75,7 @@ bool ensureFilePathExists(QString filenamepath); */ bool ensureFolderPathExists(QString filenamepath); +// TODO: remove in favor of FS::copy once #333 is merged bool copyFile(QString const& src, QString const& dst); /// @brief Copies a directory and it's contents from src to dest diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 5091db0c..06ef1deb 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -373,7 +373,7 @@ void PackInstallTask::copyBlockedMods() { qDebug() << "Will try to copy" << mod->localPath << "to" << dest_path; - if (!FS::copyFile(mod->localPath, dest_path)) { + if (!FS::copyFile(mod->localPath, dest_path)) { // FIXME: use FS::copy once #333 is merged qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed"; } From 6010ce0dc587527caa05bdc9b4cecdb9bd811375 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Tue, 1 Nov 2022 04:28:57 -0700 Subject: [PATCH 08/10] chore(remove FS::copyFile): Now that #333 is merged and FS::copy works on non directory copyFile can be removed. Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/FileSystem.cpp | 26 ------------------- launcher/FileSystem.h | 3 --- .../flame/FlameInstanceCreationTask.cpp | 2 +- .../modpacksch/FTBPackInstallTask.cpp | 2 +- 4 files changed, 2 insertions(+), 31 deletions(-) diff --git a/launcher/FileSystem.cpp b/launcher/FileSystem.cpp index 508da08d..bf0849ec 100644 --- a/launcher/FileSystem.cpp +++ b/launcher/FileSystem.cpp @@ -163,32 +163,6 @@ bool ensureFolderPathExists(QString foldernamepath) return success; } -/// @brief Copy file at src to dest, ensures the full filepath exsists -/// @param src srouce file path -/// @param dst destination file path -/// @return boolean: was there an error during the filecopy? -bool copyFile(QString const& src, QString const& dst) { - using copy_opts = fs::copy_options; - - std::error_code err; - - fs::copy_options opt = copy_opts::none; - // The default behavior is to follow symlinks - opt |= copy_opts::copy_symlinks; - - ensureFilePathExists(dst); - - fs::copy(toStdString(src), toStdString(dst), opt, err); - if (err) { - qWarning() << "Failed to copy files:" << QString::fromStdString(err.message()); - qDebug() << "Source file:" << src; - qDebug() << "Destination file:" << dst; - } - - return err.value() == 0; - -} - /// @brief Copies a directory and it's contents from src to dest /// @param offset subdirectory form src to copy to dest /// @return if there was an error during the filecopy diff --git a/launcher/FileSystem.h b/launcher/FileSystem.h index 11981f68..b7e175fd 100644 --- a/launcher/FileSystem.h +++ b/launcher/FileSystem.h @@ -75,9 +75,6 @@ bool ensureFilePathExists(QString filenamepath); */ bool ensureFolderPathExists(QString filenamepath); -// TODO: remove in favor of FS::copy once #333 is merged -bool copyFile(QString const& src, QString const& dst); - /// @brief Copies a directory and it's contents from src to dest class copy { public: diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 30438a1a..5d4dc689 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -433,7 +433,7 @@ void FlameCreationTask::copyBlockedMods(QList const& blocked_mods) { qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path; - if (!FS::copyFile(mod.localPath, dest_path)) { // FIXME: use FS::copy once #333 is merged + if (!FS::copy(mod.localPath, dest_path)()) { qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed"; } diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 06ef1deb..1e4bbe19 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -373,7 +373,7 @@ void PackInstallTask::copyBlockedMods() { qDebug() << "Will try to copy" << mod->localPath << "to" << dest_path; - if (!FS::copyFile(mod->localPath, dest_path)) { // FIXME: use FS::copy once #333 is merged + if (!FS::copy(mod->localPath, dest_path)()) { qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed"; } From 209a1650e489e21417ce2e1a29862703d51a2cd0 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Tue, 1 Nov 2022 07:06:36 -0700 Subject: [PATCH 09/10] clang_format and code cleanup Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- .../flame/FlameInstanceCreationTask.cpp | 11 +-- .../modpacksch/FTBPackInstallTask.cpp | 24 ++--- launcher/ui/dialogs/BlockedModsDialog.cpp | 95 +++++++++---------- 3 files changed, 62 insertions(+), 68 deletions(-) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 5d4dc689..f86e9335 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -413,15 +413,14 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) /// @brief copy the matched blocked mods to the instance staging area /// @param blocked_mods list of the blocked mods and their matched paths -void FlameCreationTask::copyBlockedMods(QList const& blocked_mods) { - +void FlameCreationTask::copyBlockedMods(QList const& blocked_mods) +{ setStatus(tr("Copying Blocked Mods...")); setAbortable(false); int i = 0; int total = blocked_mods.length(); setProgress(i, total); - for (auto &mod : blocked_mods) { - + for (auto const& mod : blocked_mods) { if (!mod.matched) { qDebug() << mod.name << "was not matched to a local file, skipping copy"; continue; @@ -433,9 +432,9 @@ void FlameCreationTask::copyBlockedMods(QList const& blocked_mods) { qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path; - if (!FS::copy(mod.localPath, dest_path)()) { + if (!FS::copy(mod.localPath, dest_path)()) { qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed"; - } + } i++; setProgress(i, total); diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 1e4bbe19..70ef7571 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -353,31 +353,31 @@ void PackInstallTask::onModDownloadFailed(QString reason) } /// @brief copy the matched blocked mods to the instance staging area -void PackInstallTask::copyBlockedMods() { - +void PackInstallTask::copyBlockedMods() +{ setStatus(tr("Copying Blocked Mods...")); setAbortable(false); int i = 0; int total = m_blocked_mods.length(); setProgress(i, total); - for (auto mod = m_blocked_mods.begin(); mod != m_blocked_mods.end(); mod++, i++) { - - if (!mod->matched) { - qDebug() << mod->name << "was not matched to a local file, skipping copy"; + for (auto const& mod : m_blocked_mods) { + if (!mod.matched) { + qDebug() << mod.name << "was not matched to a local file, skipping copy"; continue; } - auto dest_path = FS::PathCombine(m_stagingPath, ".minecraft", "mods", mod->name); + auto dest_path = FS::PathCombine(m_stagingPath, ".minecraft", "mods", mod.name); setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total))); - qDebug() << "Will try to copy" << mod->localPath << "to" << dest_path; + qDebug() << "Will try to copy" << mod.localPath << "to" << dest_path; - if (!FS::copy(mod->localPath, dest_path)()) { - qDebug() << "Copy of" << mod->localPath << "to" << dest_path << "Failed"; - } + if (!FS::copy(mod.localPath, dest_path)()) { + qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed"; + } - setProgress(i+1, total); + i++; + setProgress(i, total); } setAbortable(true); diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index 136a7371..2cf94250 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -1,18 +1,16 @@ -#include "Application.h" #include "BlockedModsDialog.h" -#include "ui_BlockedModsDialog.h" -#include -#include #include +#include +#include +#include "Application.h" +#include "ui_BlockedModsDialog.h" #include #include - - - -BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, QList &mods) : - QDialog(parent), ui(new Ui::BlockedModsDialog), mods(mods) { +BlockedModsDialog::BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList& mods) + : QDialog(parent), ui(new Ui::BlockedModsDialog), mods(mods) +{ ui->setupUi(this); auto openAllButton = ui->buttonBox->addButton(tr("Open All"), QDialogButtonBox::ActionRole); @@ -21,7 +19,7 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons connect(&watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged); hashing_task = shared_qobject_ptr(new ConcurrentTask(this, "MakeHashesTask", 10)); - + qDebug() << "Mods List: " << mods; setupWatch(); @@ -33,22 +31,25 @@ BlockedModsDialog::BlockedModsDialog(QWidget *parent, const QString &title, cons update(); } -BlockedModsDialog::~BlockedModsDialog() { +BlockedModsDialog::~BlockedModsDialog() +{ delete ui; } -void BlockedModsDialog::openAll() { - for(auto &mod : mods) { +void BlockedModsDialog::openAll() +{ + for (auto& mod : mods) { QDesktopServices::openUrl(mod.websiteUrl); } } /// @brief update UI with current status of the blocked mod detection -void BlockedModsDialog::update() { +void BlockedModsDialog::update() +{ QString text; QString span; - for (auto &mod : mods) { + for (auto& mod : mods) { if (mod.matched) { // ✔ -> html for HEAVY CHECK MARK : ✔ span = QString(tr(" ✔ Found at %1 ")).arg(mod.localPath); @@ -70,33 +71,34 @@ void BlockedModsDialog::update() { /// @brief Signal fired when a watched direcotry has changed /// @param path the path to the changed directory -void BlockedModsDialog::directoryChanged(QString path) { +void BlockedModsDialog::directoryChanged(QString path) +{ qDebug() << "Directory changed: " << path; scanPath(path); } - /// @brief add the user downloads folder and the global mods folder to the filesystem watcher -void BlockedModsDialog::setupWatch() { +void BlockedModsDialog::setupWatch() +{ const QString downloadsFolder = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation); const QString modsFolder = APPLICATION->settings()->get("CentralModsDir").toString(); watcher.addPath(downloadsFolder); watcher.addPath(modsFolder); } - /// @brief scan all watched folder -void BlockedModsDialog::scanPaths() { - for (auto &dir : watcher.directories()) { +void BlockedModsDialog::scanPaths() +{ + for (auto& dir : watcher.directories()) { scanPath(dir); } } -/// @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 /// @param path the directory to scan -void BlockedModsDialog::scanPath(QString path) { - +void BlockedModsDialog::scanPath(QString path) +{ QDir scan_dir(path); QDirIterator scan_it(path, QDir::Filter::Files | QDir::Filter::Hidden, QDirIterator::NoIteratorFlags); while (scan_it.hasNext()) { @@ -110,30 +112,26 @@ void BlockedModsDialog::scanPath(QString path) { qDebug() << "Creating Hash task for path: " << file; - connect(hash_task.get(), &Task::succeeded, [this, hash_task, file] { - checkMatchHash(hash_task->getResult(), file); - }); - connect(hash_task.get(), &Task::failed, [this, hash_task, file] { - qDebug() << "Failed to hash path: " << file; - }); - + connect(hash_task.get(), &Task::succeeded, [this, hash_task, file] { checkMatchHash(hash_task->getResult(), file); }); + connect(hash_task.get(), &Task::failed, [file] { qDebug() << "Failed to hash path: " << file; }); + hashing_task->addTask(hash_task); } hashing_task->start(); - } /// @brief check if the computed hash for the provided path matches a blocked /// mod we are looking for /// @param hash the computed hash for the provided path /// @param path the path to the local file being compared -void BlockedModsDialog::checkMatchHash(QString hash, QString path) { +void BlockedModsDialog::checkMatchHash(QString hash, QString path) +{ bool match = false; - qDebug() << "Checking for match on hash: " << hash << " | From path:" << path; + qDebug() << "Checking for match on hash: " << hash << "| From path:" << path; - for (auto &mod : mods) { + for (auto& mod : mods) { if (mod.matched) { continue; } @@ -142,7 +140,7 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path) { mod.localPath = path; match = true; - qDebug() << "Hash match found: " << mod.name << " " << hash << " | From path:" << path; + qDebug() << "Hash match found:" << mod.name << hash << "| From path:" << path; break; } @@ -156,14 +154,14 @@ void BlockedModsDialog::checkMatchHash(QString hash, QString path) { /// @brief Check if the name of the file at path matches the name of a blocked mod we are searching for /// @param path the path to check /// @return boolean: did the path match the name of a blocked mod? -bool BlockedModsDialog::checkValidPath(QString path) { - +bool BlockedModsDialog::checkValidPath(QString path) +{ QFileInfo file = QFileInfo(path); QString filename = file.fileName(); - for (auto &mod : mods) { + for (auto& mod : mods) { if (mod.name.compare(filename, Qt::CaseInsensitive) == 0) { - qDebug() << "Name match found: " << mod.name << " | From path:" << path; + qDebug() << "Name match found:" << mod.name << "| From path:" << path; return true; } } @@ -171,21 +169,18 @@ bool BlockedModsDialog::checkValidPath(QString path) { return false; } -bool BlockedModsDialog::allModsMatched() { - for (auto &mod : mods) { - if (!mod.matched) - return false; - } - return true; +bool BlockedModsDialog::allModsMatched() +{ + return std::all_of(mods.begin(), mods.end(), [](auto const& mod) { return mod.matched; }); } /// qDebug print support for the BlockedMod struct -QDebug operator<<(QDebug debug, const BlockedMod &m) { +QDebug operator<<(QDebug debug, const BlockedMod& m) +{ QDebugStateSaver saver(debug); - debug.nospace() << "{ name: " << m.name << ", websiteUrl: " << m.websiteUrl - << ", hash: " << m.hash << ", matched: " << m.matched - << ", localPath: " << m.localPath <<"}"; + debug.nospace() << "{ name: " << m.name << ", websiteUrl: " << m.websiteUrl << ", hash: " << m.hash << ", matched: " << m.matched + << ", localPath: " << m.localPath << "}"; return debug; } From 2f10fa8b61dac5af5866e7ad8e72cf702f15a130 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Fri, 11 Nov 2022 05:41:32 -0700 Subject: [PATCH 10/10] add some extra debug logs for CF blocked mods Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/modplatform/flame/FlameInstanceCreationTask.cpp | 1 + launcher/modplatform/modpacksch/FTBPackInstallTask.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index f86e9335..f0fbdc96 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -399,6 +399,7 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) message_dialog->setModal(true); if (message_dialog->exec()) { + qDebug() << "Post dialog blocked mods list: " << blocked_mods; copyBlockedMods(blocked_mods); setupDownloadJob(loop); } else { diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 70ef7571..40aee82b 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -216,7 +216,7 @@ void PackInstallTask::onResolveModsSucceeded() m_blocked_mods); if (message_dialog->exec() == QDialog::Accepted) { - qDebug() << "Post dialog mods list: " << m_blocked_mods; + qDebug() << "Post dialog blocked mods list: " << m_blocked_mods; createInstance(); } else {