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] 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();