diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2022-12-14 23:22:27 +0100 |
---|---|---|
committer | Sefa Eyeoglu <contact@scrumplex.net> | 2022-12-14 23:22:27 +0100 |
commit | 849b92665e0762a38a7e17403015e2b037318aec (patch) | |
tree | 2fbeac111297727aa6613aacc08e80dcec5c3724 /launcher/modplatform | |
parent | fdbd8d9d2b2e04cd68fd800882309b40c05aba2c (diff) | |
parent | d193ed9eebb392b259edb88a227dce4cee773df6 (diff) | |
download | PrismLauncher-849b92665e0762a38a7e17403015e2b037318aec.tar.gz PrismLauncher-849b92665e0762a38a7e17403015e2b037318aec.tar.bz2 PrismLauncher-849b92665e0762a38a7e17403015e2b037318aec.zip |
Merge branch 'develop' into remove-updater
Diffstat (limited to 'launcher/modplatform')
9 files changed, 183 insertions, 104 deletions
diff --git a/launcher/modplatform/flame/FileResolvingTask.cpp b/launcher/modplatform/flame/FileResolvingTask.cpp index 25b56fbd..7f1beb1a 100644 --- a/launcher/modplatform/flame/FileResolvingTask.cpp +++ b/launcher/modplatform/flame/FileResolvingTask.cpp @@ -42,12 +42,25 @@ void Flame::FileResolvingTask::executeTask() void Flame::FileResolvingTask::netJobFinished() { setProgress(1, 3); - int index = 0; // job to check modrinth for blocked projects m_checkJob = new NetJob("Modrinth check", m_network); blockedProjects = QMap<File *,QByteArray *>(); - auto doc = Json::requireDocument(*result); - auto array = Json::requireArray(doc.object()["data"]); + + QJsonDocument doc; + QJsonArray array; + + try { + doc = Json::requireDocument(*result); + array = Json::requireArray(doc.object()["data"]); + } catch (Json::JsonException& e) { + qCritical() << "Non-JSON data returned from the CF API"; + qCritical() << e.cause(); + + emitFailed(tr("Invalid data returned from the API.")); + + return; + } + for (QJsonValueRef file : array) { auto fileid = Json::requireInteger(Json::requireObject(file)["id"]); auto& out = m_toProcess.files[fileid]; @@ -68,7 +81,6 @@ void Flame::FileResolvingTask::netJobFinished() blockedProjects.insert(&out, output); } } - index++; } connect(m_checkJob.get(), &NetJob::finished, this, &Flame::FileResolvingTask::modrinthCheckFinished); diff --git a/launcher/modplatform/flame/FlameInstanceCreationTask.cpp b/launcher/modplatform/flame/FlameInstanceCreationTask.cpp index 91554b58..729268d7 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 <contact@scrumplex.net> + * + * 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 <https://www.gnu.org/licenses/>. + * + * 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" @@ -46,13 +81,19 @@ bool FlameCreationTask::updateInstance() auto instance_list = APPLICATION->instances(); // FIXME: How to handle situations when there's more than one install already for a given modpack? - auto inst = instance_list->getInstanceByManagedName(originalName()); + InstancePtr inst; + if (auto original_id = originalInstanceID(); !original_id.isEmpty()) { + inst = instance_list->getInstanceById(original_id); + Q_ASSERT(inst); + } else { + inst = instance_list->getInstanceByManagedName(originalName()); - if (!inst) { - inst = instance_list->getInstanceById(originalName()); + if (!inst) { + inst = instance_list->getInstanceById(originalName()); - if (!inst) - return false; + if (!inst) + return false; + } } QString index_path(FS::PathCombine(m_stagingPath, "manifest.json")); @@ -67,24 +108,14 @@ bool FlameCreationTask::updateInstance() auto version_id = inst->getManagedPackVersionName(); auto version_str = !version_id.isEmpty() ? tr(" (version %1)").arg(version_id) : ""; - auto info = CustomMessageBox::selectable( - m_parent, tr("Similar modpack was found!"), - 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); - info->setButtonText(QMessageBox::Ok, tr("Update existing instance")); - info->setButtonText(QMessageBox::Abort, tr("Create new instance")); - info->setButtonText(QMessageBox::Reset, tr("Cancel")); - - info->exec(); - - if (info->clickedButton() == info->button(QMessageBox::Abort)) - return false; - - if (info->clickedButton() == info->button(QMessageBox::Reset)) { - m_abort = true; - return false; + if (shouldConfirmUpdate()) { + auto should_update = askIfShouldUpdate(m_parent, version_str); + if (should_update == ShouldUpdate::SkipUpdating) + return false; + if (should_update == ShouldUpdate::Cancel) { + m_abort = true; + return false; + } } QDir old_inst_dir(inst->instanceRoot()); @@ -197,10 +228,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; @@ -208,7 +239,7 @@ bool FlameCreationTask::updateInstance() } } - setOverride(true); + setOverride(true, inst->id()); qDebug() << "Will override instance!"; m_instance = inst; @@ -330,7 +361,7 @@ bool FlameCreationTask::createInstance() FS::deletePath(jarmodsPath); } - instance.setManagedPack("flame", {}, m_pack.name, {}, m_pack.version); + instance.setManagedPack("flame", m_managed_id, m_pack.name, m_managed_version_id, m_pack.version); instance.setName(name()); m_mod_id_resolver = new Flame::FileResolvingTask(APPLICATION->network(), m_pack); @@ -338,6 +369,7 @@ bool FlameCreationTask::createInstance() connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::failed, [&](QString reason) { m_mod_id_resolver.reset(); setError(tr("Unable to resolve mod IDs:\n") + reason); + loop.quit(); }); connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::progress, this, &FlameCreationTask::setProgress); connect(m_mod_id_resolver.get(), &Flame::FileResolvingTask::status, this, &FlameCreationTask::setStatus); @@ -353,14 +385,6 @@ bool FlameCreationTask::createInstance() setAbortable(false); auto inst = m_instance.value(); - // Only change the name if it didn't use a custom name, so that the previous custom name - // is preserved, but if we're using the original one, we update the version string. - // NOTE: This needs to come before the copyManagedPack call! - if (inst->name().contains(inst->getManagedPackVersionName())) { - if (askForChangingInstanceName(m_parent, inst->name(), instance.name()) == InstanceNameChange::ShouldChange) - inst->setName(instance.name()); - } - inst->copyManagedPack(instance); } @@ -376,13 +400,13 @@ 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; blocked_mod.hash = result.hash; blocked_mod.matched = false; blocked_mod.localPath = ""; + blocked_mod.targetFolder = result.targetFolder; blocked_mods.append(blocked_mod); @@ -392,14 +416,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"), - tr("The following files are not available for download in third party launchers.<br/>" - "You will need to manually download them and add them to the instance."), - blocked_mods); + BlockedModsDialog message_dialog(m_parent, tr("Blocked mods found"), + tr("The following files are not available for download in third party launchers.<br/>" + "You will need to manually download them and add them to the instance."), + 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); @@ -428,7 +452,7 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods) continue; } - auto dest_path = FS::PathCombine(m_stagingPath, "minecraft", "mods", mod.name); + auto dest_path = FS::PathCombine(m_stagingPath, "minecraft", mod.targetFolder, mod.name); setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total))); @@ -483,9 +507,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/flame/FlameInstanceCreationTask.h b/launcher/modplatform/flame/FlameInstanceCreationTask.h index fbc7d5bf..3a1c729f 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 <contact@scrumplex.net> + * + * 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 <https://www.gnu.org/licenses/>. + * + * 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" @@ -16,11 +51,21 @@ class FlameCreationTask final : public InstanceCreationTask { Q_OBJECT public: - FlameCreationTask(const QString& staging_path, SettingsObjectPtr global_settings, QWidget* parent) - : InstanceCreationTask(), m_parent(parent) + FlameCreationTask(const QString& staging_path, + SettingsObjectPtr global_settings, + QWidget* parent, + QString id, + QString version_id, + QString original_instance_id = {}) + : InstanceCreationTask() + , m_parent(parent) + , m_managed_id(std::move(id)) + , m_managed_version_id(std::move(version_id)) { setStagingPath(staging_path); setParentSettings(global_settings); + + m_original_instance_id = std::move(original_instance_id); } bool abort() override; @@ -43,5 +88,7 @@ class FlameCreationTask final : public InstanceCreationTask { NetJob* m_process_update_file_info_job = nullptr; NetJob::Ptr m_files_job = nullptr; + QString m_managed_id, m_managed_version_id; + std::optional<InstancePtr> m_instance; }; diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 4c7b7a4f..2979663d 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 <flowlnlnln@gmail.com> * Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> @@ -189,13 +189,13 @@ 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; blocked_mod.hash = results_file.hash; blocked_mod.matched = false; blocked_mod.localPath = ""; + blocked_mod.targetFolder = results_file.targetFolder; m_blocked_mods.append(blocked_mod); @@ -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"), - tr("The following files are not available for download in third party launchers.<br/>" - "You will need to manually download them and add them to the instance."), - m_blocked_mods); + BlockedModsDialog message_dialog(m_parent, tr("Blocked files found"), + tr("The following files are not available for download in third party launchers.<br/>" + "You will need to manually download them and add them to the instance."), + m_blocked_mods); + + message_dialog.setModal(true); - if (message_dialog->exec() == QDialog::Accepted) { + if (message_dialog.exec() == QDialog::Accepted) { qDebug() << "Post dialog blocked mods list: " << m_blocked_mods; createInstance(); } else { @@ -365,7 +367,7 @@ void PackInstallTask::copyBlockedMods() continue; } - auto dest_path = FS::PathCombine(m_stagingPath, ".minecraft", "mods", mod.name); + auto dest_path = FS::PathCombine(m_stagingPath, ".minecraft", mod.targetFolder, mod.name); setStatus(tr("Copying Blocked Mods (%1 out of %2 are done)").arg(QString::number(i), QString::number(total))); diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index 2cd4d729..97b1eb0b 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 <flowlnlnln@gmail.com> * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net> * diff --git a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp index ddeea224..1c0e8979 100644 --- a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp +++ b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.cpp @@ -33,13 +33,19 @@ bool ModrinthCreationTask::updateInstance() auto instance_list = APPLICATION->instances(); // FIXME: How to handle situations when there's more than one install already for a given modpack? - auto inst = instance_list->getInstanceByManagedName(originalName()); + InstancePtr inst; + if (auto original_id = originalInstanceID(); !original_id.isEmpty()) { + inst = instance_list->getInstanceById(original_id); + Q_ASSERT(inst); + } else { + inst = instance_list->getInstanceByManagedName(originalName()); - if (!inst) { - inst = instance_list->getInstanceById(originalName()); + if (!inst) { + inst = instance_list->getInstanceById(originalName()); - if (!inst) - return false; + if (!inst) + return false; + } } QString index_path = FS::PathCombine(m_stagingPath, "modrinth.index.json"); @@ -49,25 +55,14 @@ bool ModrinthCreationTask::updateInstance() auto version_name = inst->getManagedPackVersionName(); auto version_str = !version_name.isEmpty() ? tr(" (version %1)").arg(version_name) : ""; - auto info = CustomMessageBox::selectable( - m_parent, tr("Similar modpack was found!"), - 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); - info->setButtonText(QMessageBox::Ok, tr("Create new instance")); - info->setButtonText(QMessageBox::Abort, tr("Update existing instance")); - info->setButtonText(QMessageBox::Reset, tr("Cancel")); - - info->exec(); - - if (info->clickedButton() == info->button(QMessageBox::Ok)) - return false; - - if (info->clickedButton() == info->button(QMessageBox::Reset)) { - m_abort = true; - return false; + if (shouldConfirmUpdate()) { + auto should_update = askIfShouldUpdate(m_parent, version_str); + if (should_update == ShouldUpdate::SkipUpdating) + return false; + if (should_update == ShouldUpdate::Cancel) { + m_abort = true; + return false; + } } // Remove repeated files, we don't need to download them! @@ -149,7 +144,7 @@ bool ModrinthCreationTask::updateInstance() } - setOverride(true); + setOverride(true, inst->id()); qDebug() << "Will override instance!"; m_instance = inst; @@ -222,7 +217,7 @@ bool ModrinthCreationTask::createInstance() instance.setIconKey("modrinth"); } - instance.setManagedPack("modrinth", getManagedPackID(), m_managed_name, m_managed_version_id, version()); + instance.setManagedPack("modrinth", m_managed_id, m_managed_name, m_managed_version_id, version()); instance.setName(name()); instance.saveNow(); @@ -295,7 +290,8 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path, std::vector< } if (set_managed_info) { - m_managed_version_id = Json::ensureString(obj, "versionId", {}, "Managed ID"); + if (m_managed_version_id.isEmpty()) + m_managed_version_id = Json::ensureString(obj, "versionId", {}, "Managed ID"); m_managed_name = Json::ensureString(obj, "name", {}, "Managed Name"); } @@ -395,13 +391,3 @@ bool ModrinthCreationTask::parseManifest(const QString& index_path, std::vector< return true; } - -QString ModrinthCreationTask::getManagedPackID() const -{ - if (!m_source_url.isEmpty()) { - QRegularExpression regex(R"(data\/(.*)\/versions)"); - return regex.match(m_source_url).captured(1); - } - - return {}; -} diff --git a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.h b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.h index e459aadf..122fc5ce 100644 --- a/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.h +++ b/launcher/modplatform/modrinth/ModrinthInstanceCreationTask.h @@ -14,11 +14,21 @@ class ModrinthCreationTask final : public InstanceCreationTask { Q_OBJECT public: - ModrinthCreationTask(QString staging_path, SettingsObjectPtr global_settings, QWidget* parent, QString source_url = {}) - : InstanceCreationTask(), m_parent(parent), m_source_url(std::move(source_url)) + ModrinthCreationTask(QString staging_path, + SettingsObjectPtr global_settings, + QWidget* parent, + QString id, + QString version_id = {}, + QString original_instance_id = {}) + : InstanceCreationTask() + , m_parent(parent) + , m_managed_id(std::move(id)) + , m_managed_version_id(std::move(version_id)) { setStagingPath(staging_path); setParentSettings(global_settings); + + m_original_instance_id = std::move(original_instance_id); } bool abort() override; @@ -28,14 +38,12 @@ class ModrinthCreationTask final : public InstanceCreationTask { private: bool parseManifest(const QString&, std::vector<Modrinth::File>&, bool set_managed_info = true, bool show_optional_dialog = true); - QString getManagedPackID() const; private: QWidget* m_parent = nullptr; QString minecraftVersion, fabricVersion, quiltVersion, forgeVersion; QString m_managed_id, m_managed_version_id, m_managed_name; - QString m_source_url; std::vector<Modrinth::File> m_files; NetJob::Ptr m_files_job; diff --git a/launcher/modplatform/modrinth/ModrinthPackManifest.cpp b/launcher/modplatform/modrinth/ModrinthPackManifest.cpp index 96f54067..4dca786f 100644 --- a/launcher/modplatform/modrinth/ModrinthPackManifest.cpp +++ b/launcher/modplatform/modrinth/ModrinthPackManifest.cpp @@ -128,6 +128,7 @@ auto loadIndexedVersion(QJsonObject &obj) -> ModpackVersion file.name = Json::requireString(obj, "name"); file.version = Json::requireString(obj, "version_number"); + file.changelog = Json::ensureString(obj, "changelog"); file.id = Json::requireString(obj, "id"); file.project_id = Json::requireString(obj, "project_id"); diff --git a/launcher/modplatform/modrinth/ModrinthPackManifest.h b/launcher/modplatform/modrinth/ModrinthPackManifest.h index 035dc62e..2973dfba 100644 --- a/launcher/modplatform/modrinth/ModrinthPackManifest.h +++ b/launcher/modplatform/modrinth/ModrinthPackManifest.h @@ -80,6 +80,7 @@ struct ModpackExtra { struct ModpackVersion { QString name; QString version; + QString changelog; QString id; QString project_id; |