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: copy found mods to instance (FTB and Flame) Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- launcher/FileSystem.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'launcher/FileSystem.cpp') 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; -- cgit 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: 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 ++ .../modplatform/modpacksch/FTBPackInstallTask.cpp | 4 +-- launcher/ui/dialogs/BlockedModsDialog.cpp | 42 +++++++++++++--------- launcher/ui/dialogs/BlockedModsDialog.h | 5 ++- 6 files changed, 38 insertions(+), 23 deletions(-) (limited to 'launcher/FileSystem.cpp') 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); -- cgit 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: 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 +++++++++++----------- .../modplatform/flame/FlameInstanceCreationTask.h | 2 +- .../modplatform/modpacksch/FTBPackInstallTask.cpp | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) (limited to 'launcher/FileSystem.cpp') 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(); -- cgit 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: 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 +- .../modplatform/modpacksch/FTBPackInstallTask.cpp | 2 +- 4 files changed, 2 insertions(+), 31 deletions(-) (limited to 'launcher/FileSystem.cpp') 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"; } -- cgit