From 2fd7338cd300de7ef86ccccb6fca89da7ec28e31 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 5 Dec 2022 21:27:23 +0100 Subject: [PATCH 1/4] dix: disable FS watcher after closing BlockedModsDialog Signed-off-by: Sefa Eyeoglu --- launcher/ui/dialogs/BlockedModsDialog.cpp | 6 ++++++ launcher/ui/dialogs/BlockedModsDialog.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/launcher/ui/dialogs/BlockedModsDialog.cpp b/launcher/ui/dialogs/BlockedModsDialog.cpp index edb4ff7d4..214eeeaa3 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.cpp +++ b/launcher/ui/dialogs/BlockedModsDialog.cpp @@ -79,6 +79,12 @@ void BlockedModsDialog::dropEvent(QDropEvent* e) update(); } +void BlockedModsDialog::done(int r) +{ + QDialog::done(r); + disconnect(&m_watcher, &QFileSystemWatcher::directoryChanged, this, &BlockedModsDialog::directoryChanged); +} + void BlockedModsDialog::openAll() { for (auto& mod : m_mods) { diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index dac43cbad..ebe700dad 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -35,6 +35,10 @@ protected: void dragEnterEvent(QDragEnterEvent *event) override; void dropEvent(QDropEvent *event) override; +protected +slots: + void done(int r) override; + private: Ui::BlockedModsDialog *ui; QList &m_mods; From 07359865c6aeeb70bcebcfb77e5f12430013de3c Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Mon, 5 Dec 2022 21:33:42 +0100 Subject: [PATCH 2/4] fix: don't allocate BlockedsModsDialog Fixes temporary memory leak! Signed-off-by: Sefa Eyeoglu --- launcher/modplatform/flame/FlameInstanceCreationTask.cpp | 6 +++--- launcher/modplatform/modpacksch/FTBPackInstallTask.cpp | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index a00c948a8..56d2273c8 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -393,14 +393,14 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) if (anyBlocked) { qWarning() << "Blocked mods found, displaying mod list"; - auto message_dialog = new BlockedModsDialog(m_parent, tr("Blocked mods found"), + BlockedModsDialog message_dialog(m_parent, tr("Blocked mods 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); - message_dialog->setModal(true); + message_dialog.setModal(true); - if (message_dialog->exec()) { + if (message_dialog.exec()) { qDebug() << "Post dialog blocked mods list: " << blocked_mods; copyBlockedMods(blocked_mods); setupDownloadJob(loop); diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 4c7b7a4fe..7a6067f88 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -210,12 +210,14 @@ void PackInstallTask::onResolveModsSucceeded() if (anyBlocked) { qDebug() << "Blocked files found, displaying file list"; - auto message_dialog = new BlockedModsDialog(m_parent, tr("Blocked files found"), + BlockedModsDialog message_dialog(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."), m_blocked_mods); - if (message_dialog->exec() == QDialog::Accepted) { + message_dialog.setModal(true); + + if (message_dialog.exec() == QDialog::Accepted) { qDebug() << "Post dialog blocked mods list: " << m_blocked_mods; createInstance(); } else { From 85bddbed86a6e56aa96c0b024c4bafa79d86eaad Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Tue, 6 Dec 2022 13:16:27 +0100 Subject: [PATCH 3/4] chore: reformat code Signed-off-by: Sefa Eyeoglu --- .../flame/FlameInstanceCreationTask.cpp | 22 +++++++------- .../modpacksch/FTBPackInstallTask.cpp | 7 ++--- launcher/ui/dialogs/BlockedModsDialog.h | 30 +++++++++---------- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 56d2273c8..77cb947f0 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -72,7 +72,8 @@ bool FlameCreationTask::updateInstance() tr("One or more of your instances are from this same modpack%1. Do you want to create a " "separate instance, or update the existing one?\n\nNOTE: Make sure you made a backup of your important instance data before " "updating, as worlds can be corrupted and some configuration may be lost (due to pack overrides).") - .arg(version_str), QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort); + .arg(version_str), + QMessageBox::Information, QMessageBox::Ok | QMessageBox::Reset | QMessageBox::Abort); info->setButtonText(QMessageBox::Ok, tr("Update existing instance")); info->setButtonText(QMessageBox::Abort, tr("Create new instance")); info->setButtonText(QMessageBox::Reset, tr("Cancel")); @@ -197,10 +198,10 @@ bool FlameCreationTask::updateInstance() m_process_update_file_info_job = nullptr; } else { // We don't have an old index file, so we may duplicate stuff! - auto dialog = CustomMessageBox::selectable(m_parent, - tr("No index file."), - tr("We couldn't find a suitable index file for the older version. This may cause some of the files to be duplicated. Do you want to continue?"), - QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Cancel); + auto dialog = CustomMessageBox::selectable(m_parent, tr("No index file."), + tr("We couldn't find a suitable index file for the older version. This may cause some " + "of the files to be duplicated. Do you want to continue?"), + QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Cancel); if (dialog->exec() == QDialog::DialogCode::Rejected) { m_abort = true; @@ -377,7 +378,6 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) auto anyBlocked = false; for (const auto& result : results.files.values()) { if (!result.resolved || result.url.isEmpty()) { - BlockedMod blocked_mod; blocked_mod.name = result.fileName; blocked_mod.websiteUrl = result.websiteUrl; @@ -394,9 +394,9 @@ void FlameCreationTask::idResolverSucceeded(QEventLoop& loop) qWarning() << "Blocked mods found, displaying mod list"; BlockedModsDialog message_dialog(m_parent, tr("Blocked mods 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); + 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); message_dialog.setModal(true); @@ -484,9 +484,7 @@ void FlameCreationTask::setupDownloadJob(QEventLoop& loop) } m_mod_id_resolver.reset(); - connect(m_files_job.get(), &NetJob::succeeded, this, [&]() { - m_files_job.reset(); - }); + connect(m_files_job.get(), &NetJob::succeeded, this, [&]() { m_files_job.reset(); }); connect(m_files_job.get(), &NetJob::failed, [&](QString reason) { m_files_job.reset(); setError(reason); diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 7a6067f88..cd8e1914a 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -189,7 +189,6 @@ void PackInstallTask::onResolveModsSucceeded() // First check for blocked mods if (!results_file.resolved || results_file.url.isEmpty()) { - BlockedMod blocked_mod; blocked_mod.name = local_file.name; blocked_mod.websiteUrl = results_file.websiteUrl; @@ -211,9 +210,9 @@ void PackInstallTask::onResolveModsSucceeded() qDebug() << "Blocked files found, displaying file list"; BlockedModsDialog message_dialog(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."), - m_blocked_mods); + 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."), + m_blocked_mods); message_dialog.setModal(true); diff --git a/launcher/ui/dialogs/BlockedModsDialog.h b/launcher/ui/dialogs/BlockedModsDialog.h index ebe700dad..f5aef8bfd 100644 --- a/launcher/ui/dialogs/BlockedModsDialog.h +++ b/launcher/ui/dialogs/BlockedModsDialog.h @@ -1,8 +1,8 @@ #pragma once #include -#include #include +#include #include @@ -16,32 +16,32 @@ struct BlockedMod { QString hash; bool matched; QString localPath; - }; QT_BEGIN_NAMESPACE -namespace Ui { class BlockedModsDialog; } +namespace Ui { +class BlockedModsDialog; +} QT_END_NAMESPACE class BlockedModsDialog : public QDialog { -Q_OBJECT + Q_OBJECT -public: - BlockedModsDialog(QWidget *parent, const QString &title, const QString &text, QList &mods); + public: + BlockedModsDialog(QWidget* parent, const QString& title, const QString& text, QList& mods); ~BlockedModsDialog() override; -protected: - void dragEnterEvent(QDragEnterEvent *event) override; - void dropEvent(QDropEvent *event) override; + protected: + void dragEnterEvent(QDragEnterEvent* event) override; + void dropEvent(QDropEvent* event) override; -protected -slots: + protected slots: void done(int r) override; -private: - Ui::BlockedModsDialog *ui; - QList &m_mods; + private: + Ui::BlockedModsDialog* ui; + QList& m_mods; QFileSystemWatcher m_watcher; shared_qobject_ptr m_hashing_task; QSet m_pending_hash_paths; @@ -65,4 +65,4 @@ private: bool allModsMatched(); }; -QDebug operator<<(QDebug debug, const BlockedMod &m); +QDebug operator<<(QDebug debug, const BlockedMod& m); From c8c3fe1023439a020d094ab72f19d9ab91118e83 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Tue, 6 Dec 2022 13:18:50 +0100 Subject: [PATCH 4/4] chore: add license headers Signed-off-by: Sefa Eyeoglu --- .../flame/FlameInstanceCreationTask.cpp | 35 +++++++++++++++++++ .../flame/FlameInstanceCreationTask.h | 35 +++++++++++++++++++ .../modpacksch/FTBPackInstallTask.cpp | 2 +- .../modpacksch/FTBPackInstallTask.h | 2 +- 4 files changed, 72 insertions(+), 2 deletions(-) diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 77cb947f0..f9258f243 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp @@ -1,3 +1,38 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 Sefa Eyeoglu + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "FlameInstanceCreationTask.h" #include "modplatform/flame/FlameAPI.h" diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.h b/launcher/modplatform/flame/FlameInstanceCreationTask.h index fbc7d5bf7..5d227ee50 100644 --- a/launcher/modplatform/flame/FlameInstanceCreationTask.h +++ b/launcher/modplatform/flame/FlameInstanceCreationTask.h @@ -1,3 +1,38 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 Sefa Eyeoglu + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #pragma once #include "InstanceCreationTask.h" diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index cd8e1914a..48caa938f 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 flowln * Copyright (c) 2022 Jamie Mansfield * Copyright (C) 2022 Sefa Eyeoglu diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index 2cd4d7296..97b1eb0b1 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 flowln * Copyright (C) 2022 Sefa Eyeoglu *