From 4f29667e755a52b1f6837e44a62b5dfd544c9583 Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:55:55 -0600 Subject: [PATCH 01/16] feat(ftb): restore ftb pack support --- launcher/CMakeLists.txt | 16 + .../modpacksch/FTBPackInstallTask.cpp | 387 ++++++++++++++++++ .../modpacksch/FTBPackInstallTask.h | 101 +++++ .../modpacksch/FTBPackManifest.cpp | 195 +++++++++ .../modplatform/modpacksch/FTBPackManifest.h | 168 ++++++++ launcher/ui/dialogs/NewInstanceDialog.cpp | 2 + .../pages/modplatform/ftb/FtbFilterModel.cpp | 93 +++++ .../ui/pages/modplatform/ftb/FtbFilterModel.h | 51 +++ .../ui/pages/modplatform/ftb/FtbListModel.cpp | 304 ++++++++++++++ .../ui/pages/modplatform/ftb/FtbListModel.h | 83 ++++ launcher/ui/pages/modplatform/ftb/FtbPage.cpp | 199 +++++++++ launcher/ui/pages/modplatform/ftb/FtbPage.h | 105 +++++ launcher/ui/pages/modplatform/ftb/FtbPage.ui | 86 ++++ 13 files changed, 1790 insertions(+) create mode 100644 launcher/modplatform/modpacksch/FTBPackInstallTask.cpp create mode 100644 launcher/modplatform/modpacksch/FTBPackInstallTask.h create mode 100644 launcher/modplatform/modpacksch/FTBPackManifest.cpp create mode 100644 launcher/modplatform/modpacksch/FTBPackManifest.h create mode 100644 launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp create mode 100644 launcher/ui/pages/modplatform/ftb/FtbFilterModel.h create mode 100644 launcher/ui/pages/modplatform/ftb/FtbListModel.cpp create mode 100644 launcher/ui/pages/modplatform/ftb/FtbListModel.h create mode 100644 launcher/ui/pages/modplatform/ftb/FtbPage.cpp create mode 100644 launcher/ui/pages/modplatform/ftb/FtbPage.h create mode 100644 launcher/ui/pages/modplatform/ftb/FtbPage.ui diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index e5358c8ad..3cd46aa59 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -587,6 +587,13 @@ set(MODRINTH_SOURCES modplatform/modrinth/ModrinthPackExportTask.h ) +set(MODPACKSCH_SOURCES + modplatform/modpacksch/FTBPackInstallTask.h + modplatform/modpacksch/FTBPackInstallTask.cpp + modplatform/modpacksch/FTBPackManifest.h + modplatform/modpacksch/FTBPackManifest.cpp +) + set(PACKWIZ_SOURCES modplatform/packwiz/Packwiz.h modplatform/packwiz/Packwiz.cpp @@ -814,6 +821,7 @@ set(LOGIC_SOURCES ${FTB_SOURCES} ${FLAME_SOURCES} ${MODRINTH_SOURCES} + ${MODPACKSCH_SOURCES} ${PACKWIZ_SOURCES} ${TECHNIC_SOURCES} ${ATLAUNCHER_SOURCES} @@ -1056,6 +1064,13 @@ SET(LAUNCHER_SOURCES ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.cpp ui/pages/modplatform/atlauncher/AtlUserInteractionSupportImpl.h + ui/pages/modplatform/ftb/FtbFilterModel.cpp + ui/pages/modplatform/ftb/FtbFilterModel.h + ui/pages/modplatform/ftb/FtbListModel.cpp + ui/pages/modplatform/ftb/FtbListModel.h + ui/pages/modplatform/ftb/FtbPage.cpp + ui/pages/modplatform/ftb/FtbPage.h + ui/pages/modplatform/legacy_ftb/Page.cpp ui/pages/modplatform/legacy_ftb/Page.h ui/pages/modplatform/legacy_ftb/ListModel.h @@ -1291,6 +1306,7 @@ qt_wrap_ui(LAUNCHER_UI ui/pages/modplatform/import_ftb/ImportFTBPage.ui ui/pages/modplatform/ImportPage.ui ui/pages/modplatform/OptionalModDialog.ui + ui/pages/modplatform/ftb/FtbPage.ui ui/pages/modplatform/modrinth/ModrinthPage.ui ui/pages/modplatform/technic/TechnicPage.ui ui/widgets/CustomCommands.ui diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp new file mode 100644 index 000000000..68d4751cd --- /dev/null +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -0,0 +1,387 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 flowln + * Copyright (c) 2022 Jamie Mansfield + * 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 2020-2021 Jamie Mansfield + * Copyright 2020-2021 Petr Mrazek + * + * 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 "FTBPackInstallTask.h" + +#include "FileSystem.h" +#include "Json.h" +#include "minecraft/MinecraftInstance.h" +#include "minecraft/PackProfile.h" +#include "modplatform/flame/PackManifest.h" +#include "net/ChecksumValidator.h" +#include "settings/INISettingsObject.h" + +#include "Application.h" +#include "BuildConfig.h" +#include "ui/dialogs/BlockedModsDialog.h" + +namespace ModpacksCH { + +PackInstallTask::PackInstallTask(Modpack pack, QString version, QWidget* parent) + : m_pack(std::move(pack)), m_version_name(std::move(version)), m_parent(parent) +{} + +bool PackInstallTask::abort() +{ + if (!canAbort()) + return false; + + bool aborted = true; + + if (m_net_job) + aborted &= m_net_job->abort(); + if (m_mod_id_resolver_task) + aborted &= m_mod_id_resolver_task->abort(); + + return aborted ? InstanceTask::abort() : false; +} + +void PackInstallTask::executeTask() +{ + setStatus(tr("Getting the manifest...")); + setAbortable(false); + + // Find pack version + auto version_it = std::find_if(m_pack.versions.constBegin(), m_pack.versions.constEnd(), + [this](ModpacksCH::VersionInfo const& a) { return a.name == m_version_name; }); + + if (version_it == m_pack.versions.constEnd()) { + emitFailed(tr("Failed to find pack version %1").arg(m_version_name)); + return; + } + + auto version = *version_it; + + auto netJob = makeShared("ModpacksCH::VersionFetch", APPLICATION->network()); + + auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1/%2").arg(m_pack.id).arg(version.id); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &m_response)); + + QObject::connect(netJob.get(), &NetJob::succeeded, this, &PackInstallTask::onManifestDownloadSucceeded); + QObject::connect(netJob.get(), &NetJob::failed, this, &PackInstallTask::onManifestDownloadFailed); + QObject::connect(netJob.get(), &NetJob::aborted, this, &PackInstallTask::abort); + QObject::connect(netJob.get(), &NetJob::progress, this, &PackInstallTask::setProgress); + + m_net_job = netJob; + + setAbortable(true); + netJob->start(); +} + +void PackInstallTask::onManifestDownloadSucceeded() +{ + m_net_job.reset(); + + QJsonParseError parse_error{}; + QJsonDocument doc = QJsonDocument::fromJson(m_response, &parse_error); + if (parse_error.error != QJsonParseError::NoError) { + qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset + << " reason: " << parse_error.errorString(); + qWarning() << m_response; + return; + } + + ModpacksCH::Version version; + try { + auto obj = Json::requireObject(doc); + ModpacksCH::loadVersion(version, obj); + } catch (const JSONValidationError& e) { + emitFailed(tr("Could not understand pack manifest:\n") + e.cause()); + return; + } + + m_version = version; + + resolveMods(); +} + +void PackInstallTask::resolveMods() +{ + setStatus(tr("Resolving mods...")); + setAbortable(false); + setProgress(0, 100); + + m_file_id_map.clear(); + + Flame::Manifest manifest; + int index = 0; + + for (auto const& file : m_version.files) { + if (!file.serverOnly && file.url.isEmpty()) { + if (file.curseforge.file_id <= 0) { + emitFailed(tr("Invalid manifest: There's no information available to download the file '%1'!").arg(file.name)); + return; + } + + Flame::File flame_file; + flame_file.projectId = file.curseforge.project_id; + flame_file.fileId = file.curseforge.file_id; + flame_file.hash = file.sha1; + + manifest.files.insert(flame_file.fileId, flame_file); + m_file_id_map.append(flame_file.fileId); + } else { + m_file_id_map.append(-1); + } + + index++; + } + + m_mod_id_resolver_task.reset(new Flame::FileResolvingTask(APPLICATION->network(), manifest)); + + connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::succeeded, this, &PackInstallTask::onResolveModsSucceeded); + connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::failed, this, &PackInstallTask::onResolveModsFailed); + connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::aborted, this, &PackInstallTask::abort); + connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::progress, this, &PackInstallTask::setProgress); + + setAbortable(true); + + m_mod_id_resolver_task->start(); +} + +void PackInstallTask::onResolveModsSucceeded() +{ + auto anyBlocked = false; + + Flame::Manifest results = m_mod_id_resolver_task->getResults(); + for (int index = 0; index < m_file_id_map.size(); index++) { + auto const file_id = m_file_id_map.at(index); + if (file_id < 0) + continue; + + Flame::File results_file = results.files[file_id]; + VersionFile& local_file = m_version.files[index]; + + // 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); + + anyBlocked = true; + } else { + local_file.url = results_file.url.toString(); + } + } + + m_mod_id_resolver_task.reset(); + + if (anyBlocked) { + 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); + + message_dialog.setModal(true); + + if (message_dialog.exec() == QDialog::Accepted) { + qDebug() << "Post dialog blocked mods list: " << m_blocked_mods; + createInstance(); + } else { + abort(); + } + + } else { + createInstance(); + } +} + +void PackInstallTask::createInstance() +{ + setAbortable(false); + + setStatus(tr("Creating the instance...")); + QCoreApplication::processEvents(); + + auto instanceConfigPath = FS::PathCombine(m_stagingPath, "instance.cfg"); + auto instanceSettings = std::make_shared(instanceConfigPath); + + MinecraftInstance instance(m_globalSettings, instanceSettings, m_stagingPath); + auto components = instance.getPackProfile(); + components->buildingFromScratch(); + + for (auto target : m_version.targets) { + if (target.type == "game" && target.name == "minecraft") { + components->setComponentVersion("net.minecraft", target.version, true); + break; + } + } + + for (auto target : m_version.targets) { + if (target.type != "modloader") + continue; + + if (target.name == "forge") { + components->setComponentVersion("net.minecraftforge", target.version); + } else if (target.name == "fabric") { + components->setComponentVersion("net.fabricmc.fabric-loader", target.version); + } + } + + // install any jar mods + QDir jarModsDir(FS::PathCombine(m_stagingPath, "minecraft", "jarmods")); + if (jarModsDir.exists()) { + QStringList jarMods; + + for (const auto& info : jarModsDir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files)) { + jarMods.push_back(info.absoluteFilePath()); + } + + components->installJarMods(jarMods); + } + + components->saveNow(); + + instance.setName(name()); + instance.setIconKey(m_instIcon); + instance.setManagedPack("modpacksch", QString::number(m_pack.id), m_pack.name, QString::number(m_version.id), m_version.name); + + instance.saveNow(); + + onCreateInstanceSucceeded(); +} + +void PackInstallTask::onCreateInstanceSucceeded() +{ + downloadPack(); +} + +void PackInstallTask::downloadPack() +{ + setStatus(tr("Downloading mods...")); + setAbortable(false); + + auto jobPtr = makeShared(tr("Mod download"), APPLICATION->network()); + for (auto const& file : m_version.files) { + if (file.serverOnly || file.url.isEmpty()) + continue; + + auto path = FS::PathCombine(m_stagingPath, ".minecraft", file.path, file.name); + qDebug() << "Will try to download" << file.url << "to" << path; + + QFileInfo file_info(file.name); + + auto dl = Net::Download::makeFile(file.url, path); + if (!file.sha1.isEmpty()) { + auto rawSha1 = QByteArray::fromHex(file.sha1.toLatin1()); + dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, rawSha1)); + } + + jobPtr->addNetAction(dl); + } + + connect(jobPtr.get(), &NetJob::succeeded, this, &PackInstallTask::onModDownloadSucceeded); + connect(jobPtr.get(), &NetJob::failed, this, &PackInstallTask::onModDownloadFailed); + connect(jobPtr.get(), &NetJob::aborted, this, &PackInstallTask::abort); + connect(jobPtr.get(), &NetJob::progress, this, &PackInstallTask::setProgress); + + m_net_job = jobPtr; + + setAbortable(true); + jobPtr->start(); +} + +void PackInstallTask::onModDownloadSucceeded() +{ + m_net_job.reset(); + if (!m_blocked_mods.isEmpty()) { + copyBlockedMods(); + } + emitSucceeded(); +} + +void PackInstallTask::onManifestDownloadFailed(QString reason) +{ + m_net_job.reset(); + emitFailed(reason); +} +void PackInstallTask::onResolveModsFailed(QString reason) +{ + m_net_job.reset(); + emitFailed(reason); +} +void PackInstallTask::onCreateInstanceFailed(QString reason) +{ + emitFailed(reason); +} +void PackInstallTask::onModDownloadFailed(QString reason) +{ + m_net_job.reset(); + emitFailed(reason); +} + +/// @brief copy the matched blocked mods to the instance staging area +void PackInstallTask::copyBlockedMods() +{ + setStatus(tr("Copying Blocked Mods...")); + setAbortable(false); + int i = 0; + int total = m_blocked_mods.length(); + setProgress(i, total); + 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", mod.targetFolder, 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::copy(mod.localPath, dest_path)()) { + qDebug() << "Copy of" << mod.localPath << "to" << dest_path << "Failed"; + } + + i++; + setProgress(i, total); + } + + setAbortable(true); +} + +} // namespace ModpacksCH diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h new file mode 100644 index 000000000..97b1eb0b1 --- /dev/null +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2022 flowln + * 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 2020-2021 Jamie Mansfield + * Copyright 2020-2021 Petr Mrazek + * + * 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 "FTBPackManifest.h" + +#include "InstanceTask.h" +#include "QObjectPtr.h" +#include "modplatform/flame/FileResolvingTask.h" +#include "net/NetJob.h" +#include "ui/dialogs/BlockedModsDialog.h" + +#include + +namespace ModpacksCH { + +class PackInstallTask final : public InstanceTask +{ + Q_OBJECT + +public: + explicit PackInstallTask(Modpack pack, QString version, QWidget* parent = nullptr); + ~PackInstallTask() override = default; + + bool abort() override; + +protected: + void executeTask() override; + +private slots: + void onManifestDownloadSucceeded(); + void onResolveModsSucceeded(); + void onCreateInstanceSucceeded(); + void onModDownloadSucceeded(); + + void onManifestDownloadFailed(QString reason); + void onResolveModsFailed(QString reason); + void onCreateInstanceFailed(QString reason); + void onModDownloadFailed(QString reason); + +private: + void resolveMods(); + void createInstance(); + void downloadPack(); + void copyBlockedMods(); + +private: + NetJob::Ptr m_net_job = nullptr; + shared_qobject_ptr m_mod_id_resolver_task = nullptr; + + QList m_file_id_map; + + QByteArray m_response; + + Modpack m_pack; + QString m_version_name; + Version m_version; + + QMap m_files_to_copy; + QList m_blocked_mods; + + //FIXME: nuke + QWidget* m_parent; +}; + +} diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.cpp b/launcher/modplatform/modpacksch/FTBPackManifest.cpp new file mode 100644 index 000000000..421527aef --- /dev/null +++ b/launcher/modplatform/modpacksch/FTBPackManifest.cpp @@ -0,0 +1,195 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - 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 2020 Jamie Mansfield + * Copyright 2020-2021 Petr Mrazek + * + * 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 "FTBPackManifest.h" + +#include "Json.h" + +static void loadSpecs(ModpacksCH::Specs & s, QJsonObject & obj) +{ + s.id = Json::requireInteger(obj, "id"); + s.minimum = Json::requireInteger(obj, "minimum"); + s.recommended = Json::requireInteger(obj, "recommended"); +} + +static void loadTag(ModpacksCH::Tag & t, QJsonObject & obj) +{ + t.id = Json::requireInteger(obj, "id"); + t.name = Json::requireString(obj, "name"); +} + +static void loadArt(ModpacksCH::Art & a, QJsonObject & obj) +{ + a.id = Json::requireInteger(obj, "id"); + a.url = Json::requireString(obj, "url"); + a.type = Json::requireString(obj, "type"); + a.width = Json::requireInteger(obj, "width"); + a.height = Json::requireInteger(obj, "height"); + a.compressed = Json::requireBoolean(obj, "compressed"); + a.sha1 = Json::requireString(obj, "sha1"); + a.size = Json::requireInteger(obj, "size"); + a.updated = Json::requireInteger(obj, "updated"); +} + +static void loadAuthor(ModpacksCH::Author & a, QJsonObject & obj) +{ + a.id = Json::requireInteger(obj, "id"); + a.name = Json::requireString(obj, "name"); + a.type = Json::requireString(obj, "type"); + a.website = Json::requireString(obj, "website"); + a.updated = Json::requireInteger(obj, "updated"); +} + +static void loadVersionInfo(ModpacksCH::VersionInfo & v, QJsonObject & obj) +{ + v.id = Json::requireInteger(obj, "id"); + v.name = Json::requireString(obj, "name"); + v.type = Json::requireString(obj, "type"); + v.updated = Json::requireInteger(obj, "updated"); + auto specs = Json::requireObject(obj, "specs"); + loadSpecs(v.specs, specs); +} + +void ModpacksCH::loadModpack(ModpacksCH::Modpack & m, QJsonObject & obj) +{ + m.id = Json::requireInteger(obj, "id"); + m.name = Json::requireString(obj, "name"); + m.synopsis = Json::requireString(obj, "synopsis"); + m.description = Json::requireString(obj, "description"); + m.type = Json::requireString(obj, "type"); + m.featured = Json::requireBoolean(obj, "featured"); + m.installs = Json::requireInteger(obj, "installs"); + m.plays = Json::requireInteger(obj, "plays"); + m.updated = Json::requireInteger(obj, "updated"); + m.refreshed = Json::requireInteger(obj, "refreshed"); + auto artArr = Json::requireArray(obj, "art"); + for (QJsonValueRef artRaw : artArr) + { + auto artObj = Json::requireObject(artRaw); + ModpacksCH::Art art; + loadArt(art, artObj); + m.art.append(art); + } + auto authorArr = Json::requireArray(obj, "authors"); + for (QJsonValueRef authorRaw : authorArr) + { + auto authorObj = Json::requireObject(authorRaw); + ModpacksCH::Author author; + loadAuthor(author, authorObj); + m.authors.append(author); + } + auto versionArr = Json::requireArray(obj, "versions"); + for (QJsonValueRef versionRaw : versionArr) + { + auto versionObj = Json::requireObject(versionRaw); + ModpacksCH::VersionInfo version; + loadVersionInfo(version, versionObj); + m.versions.append(version); + } + auto tagArr = Json::requireArray(obj, "tags"); + for (QJsonValueRef tagRaw : tagArr) + { + auto tagObj = Json::requireObject(tagRaw); + ModpacksCH::Tag tag; + loadTag(tag, tagObj); + m.tags.append(tag); + } + m.updated = Json::requireInteger(obj, "updated"); +} + +static void loadVersionTarget(ModpacksCH::VersionTarget & a, QJsonObject & obj) +{ + a.id = Json::requireInteger(obj, "id"); + a.name = Json::requireString(obj, "name"); + a.type = Json::requireString(obj, "type"); + a.version = Json::requireString(obj, "version"); + a.updated = Json::requireInteger(obj, "updated"); +} + +static void loadVersionFile(ModpacksCH::VersionFile & a, QJsonObject & obj) +{ + a.id = Json::requireInteger(obj, "id"); + a.type = Json::requireString(obj, "type"); + a.path = Json::requireString(obj, "path"); + a.name = Json::requireString(obj, "name"); + a.version = Json::requireString(obj, "version"); + a.url = Json::ensureString(obj, "url"); // optional + a.sha1 = Json::requireString(obj, "sha1"); + a.size = Json::requireInteger(obj, "size"); + a.clientOnly = Json::requireBoolean(obj, "clientonly"); + a.serverOnly = Json::requireBoolean(obj, "serveronly"); + a.optional = Json::requireBoolean(obj, "optional"); + a.updated = Json::requireInteger(obj, "updated"); + auto curseforgeObj = Json::ensureObject(obj, "curseforge"); // optional + a.curseforge.project_id = Json::ensureInteger(curseforgeObj, "project"); + a.curseforge.file_id = Json::ensureInteger(curseforgeObj, "file"); +} + +void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj) +{ + m.id = Json::requireInteger(obj, "id"); + m.parent = Json::requireInteger(obj, "parent"); + m.name = Json::requireString(obj, "name"); + m.type = Json::requireString(obj, "type"); + m.installs = Json::requireInteger(obj, "installs"); + m.plays = Json::requireInteger(obj, "plays"); + m.updated = Json::requireInteger(obj, "updated"); + m.refreshed = Json::requireInteger(obj, "refreshed"); + auto specs = Json::requireObject(obj, "specs"); + loadSpecs(m.specs, specs); + auto targetArr = Json::requireArray(obj, "targets"); + for (QJsonValueRef targetRaw : targetArr) + { + auto versionObj = Json::requireObject(targetRaw); + ModpacksCH::VersionTarget target; + loadVersionTarget(target, versionObj); + m.targets.append(target); + } + auto fileArr = Json::requireArray(obj, "files"); + for (QJsonValueRef fileRaw : fileArr) + { + auto fileObj = Json::requireObject(fileRaw); + ModpacksCH::VersionFile file; + loadVersionFile(file, fileObj); + m.files.append(file); + } +} + +//static void loadVersionChangelog(ModpacksCH::VersionChangelog & m, QJsonObject & obj) +//{ +// m.content = Json::requireString(obj, "content"); +// m.updated = Json::requireInteger(obj, "updated"); +//} diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.h b/launcher/modplatform/modpacksch/FTBPackManifest.h new file mode 100644 index 000000000..a8b6f35ec --- /dev/null +++ b/launcher/modplatform/modpacksch/FTBPackManifest.h @@ -0,0 +1,168 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - 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 2020-2021 Jamie Mansfield + * Copyright 2020 Petr Mrazek + * + * 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 +#include +#include +#include +#include + +namespace ModpacksCH +{ + +struct Specs +{ + int id; + int minimum; + int recommended; +}; + +struct Tag +{ + int id; + QString name; +}; + +struct Art +{ + int id; + QString url; + QString type; + int width; + int height; + bool compressed; + QString sha1; + int size; + int64_t updated; +}; + +struct Author +{ + int id; + QString name; + QString type; + QString website; + int64_t updated; +}; + +struct VersionInfo +{ + int id; + QString name; + QString type; + int64_t updated; + Specs specs; +}; + +struct Modpack +{ + int id; + QString name; + QString synopsis; + QString description; + QString type; + bool featured; + int installs; + int plays; + int64_t updated; + int64_t refreshed; + QVector art; + QVector authors; + QVector versions; + QVector tags; +}; + +struct VersionTarget +{ + int id; + QString type; + QString name; + QString version; + int64_t updated; +}; + +struct VersionFileCurseForge +{ + int project_id; + int file_id; +}; + +struct VersionFile +{ + int id; + QString type; + QString path; + QString name; + QString version; + QString url; + QString sha1; + int size; + bool clientOnly; + bool serverOnly; + bool optional; + int64_t updated; + VersionFileCurseForge curseforge; +}; + +struct Version +{ + int id; + int parent; + QString name; + QString type; + int installs; + int plays; + int64_t updated; + int64_t refreshed; + Specs specs; + QVector targets; + QVector files; +}; + +struct VersionChangelog +{ + QString content; + int64_t updated; +}; + +void loadModpack(Modpack & m, QJsonObject & obj); + +void loadVersion(Version & m, QJsonObject & obj); +} + +Q_DECLARE_METATYPE(ModpacksCH::Modpack) diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 8d80966ac..8cf094527 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -61,6 +61,7 @@ #include "ui/pages/modplatform/ImportPage.h" #include "ui/pages/modplatform/atlauncher/AtlPage.h" #include "ui/pages/modplatform/flame/FlamePage.h" +#include "ui/pages/modplatform/ftb/FtbPage.h" #include "ui/pages/modplatform/legacy_ftb/Page.h" #include "ui/pages/modplatform/modrinth/ModrinthPage.h" #include "ui/pages/modplatform/technic/TechnicPage.h" @@ -177,6 +178,7 @@ QList NewInstanceDialog::getPages() pages.append(new AtlPage(this)); if (APPLICATION->capabilities() & Application::SupportsFlame) pages.append(new FlamePage(this)); + pages.append(new FtbPage(this)); pages.append(new LegacyFTB::Page(this)); pages.append(new FTBImportAPP::ImportFTBPage(this)); pages.append(new ModrinthPage(this)); diff --git a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp new file mode 100644 index 000000000..e2b548f2d --- /dev/null +++ b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.cpp @@ -0,0 +1,93 @@ +/* + * Copyright 2020-2021 Jamie Mansfield + * + * 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 "FtbFilterModel.h" + +#include + +#include "modplatform/modpacksch/FTBPackManifest.h" + +#include "StringUtils.h" + +namespace Ftb { + +FilterModel::FilterModel(QObject *parent) : QSortFilterProxyModel(parent) +{ + currentSorting = Sorting::ByPlays; + sortings.insert(tr("Sort by Plays"), Sorting::ByPlays); + sortings.insert(tr("Sort by Installs"), Sorting::ByInstalls); + sortings.insert(tr("Sort by Name"), Sorting::ByName); +} + +const QMap FilterModel::getAvailableSortings() +{ + return sortings; +} + +QString FilterModel::translateCurrentSorting() +{ + return sortings.key(currentSorting); +} + +void FilterModel::setSorting(Sorting sorting) +{ + currentSorting = sorting; + invalidate(); +} + +FilterModel::Sorting FilterModel::getCurrentSorting() +{ + return currentSorting; +} + +void FilterModel::setSearchTerm(const QString& term) +{ + searchTerm = term.trimmed(); + invalidate(); +} + +bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const +{ + if (searchTerm.isEmpty()) { + return true; + } + + auto index = sourceModel()->index(sourceRow, 0, sourceParent); + auto pack = sourceModel()->data(index, Qt::UserRole).value(); + return pack.name.contains(searchTerm, Qt::CaseInsensitive); +} + +bool FilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const +{ + ModpacksCH::Modpack leftPack = sourceModel()->data(left, Qt::UserRole).value(); + ModpacksCH::Modpack rightPack = sourceModel()->data(right, Qt::UserRole).value(); + + if (currentSorting == ByPlays) { + return leftPack.plays < rightPack.plays; + } + else if (currentSorting == ByInstalls) { + return leftPack.installs < rightPack.installs; + } + else if (currentSorting == ByName) { + return StringUtils::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0; + } + + // Invalid sorting set, somehow... + qWarning() << "Invalid sorting set!"; + return true; +} + +} diff --git a/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h new file mode 100644 index 000000000..1be28e995 --- /dev/null +++ b/launcher/ui/pages/modplatform/ftb/FtbFilterModel.h @@ -0,0 +1,51 @@ +/* + * Copyright 2020-2021 Jamie Mansfield + * + * 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 + +namespace Ftb { + +class FilterModel : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + FilterModel(QObject* parent = Q_NULLPTR); + enum Sorting { + ByPlays, + ByInstalls, + ByName, + }; + const QMap getAvailableSortings(); + QString translateCurrentSorting(); + void setSorting(Sorting sorting); + Sorting getCurrentSorting(); + void setSearchTerm(const QString& term); + +protected: + bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; + bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; + +private: + QMap sortings; + Sorting currentSorting; + QString searchTerm { "" }; + +}; + +} diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp new file mode 100644 index 000000000..e80654158 --- /dev/null +++ b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp @@ -0,0 +1,304 @@ +/* + * Copyright 2020-2021 Jamie Mansfield + * + * 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 "FtbListModel.h" + +#include "BuildConfig.h" +#include "Application.h" +#include "Json.h" + +#include + +namespace Ftb { + +ListModel::ListModel(QObject *parent) : QAbstractListModel(parent) +{ +} + +ListModel::~ListModel() +{ +} + +int ListModel::rowCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : modpacks.size(); +} + +int ListModel::columnCount(const QModelIndex &parent) const +{ + return parent.isValid() ? 0 : 1; +} + +QVariant ListModel::data(const QModelIndex &index, int role) const +{ + int pos = index.row(); + if(pos >= modpacks.size() || pos < 0 || !index.isValid()) + { + return QString("INVALID INDEX %1").arg(pos); + } + + ModpacksCH::Modpack pack = modpacks.at(pos); + if(role == Qt::DisplayRole) + { + return pack.name; + } + else if (role == Qt::ToolTipRole) + { + return pack.synopsis; + } + else if(role == Qt::DecorationRole) + { + QIcon placeholder = APPLICATION->getThemedIcon("screenshot-placeholder"); + + auto iter = m_logoMap.find(pack.name); + if (iter != m_logoMap.end()) { + auto & logo = *iter; + if(!logo.result.isNull()) { + return logo.result; + } + return placeholder; + } + + for(auto art : pack.art) { + if(art.type == "square") { + ((ListModel *)this)->requestLogo(pack.name, art.url); + } + } + return placeholder; + } + else if(role == Qt::UserRole) + { + QVariant v; + v.setValue(pack); + return v; + } + + return QVariant(); +} + +void ListModel::getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback) +{ + if(m_logoMap.contains(logo)) + { + callback(APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0)))->getFullPath()); + } + else + { + requestLogo(logo, logoUrl); + } +} + +void ListModel::request() +{ + m_aborted = false; + + beginResetModel(); + modpacks.clear(); + endResetModel(); + + auto netJob = makeShared("Ftb::Request", APPLICATION->network()); + auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all"); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response)); + jobPtr = netJob; + jobPtr->start(); + + QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::requestFinished); + QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::requestFailed); +} + +void ListModel::abortRequest() +{ + m_aborted = jobPtr->abort(); + jobPtr.reset(); +} + +void ListModel::requestFinished() +{ + jobPtr.reset(); + remainingPacks.clear(); + + QJsonParseError parse_error {}; + QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error); + if(parse_error.error != QJsonParseError::NoError) { + qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset << " reason: " << parse_error.errorString(); + qWarning() << response; + return; + } + + auto packs = doc.object().value("packs").toArray(); + for(auto pack : packs) { + auto packId = pack.toInt(); + remainingPacks.append(packId); + } + + if(!remainingPacks.isEmpty()) { + currentPack = remainingPacks.at(0); + requestPack(); + } +} + +void ListModel::requestFailed(QString reason) +{ + jobPtr.reset(); + remainingPacks.clear(); +} + +void ListModel::requestPack() +{ + auto netJob = makeShared("Ftb::Search", APPLICATION->network()); + auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1").arg(currentPack); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); + jobPtr = netJob; + jobPtr->start(); + + QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::packRequestFinished); + QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::packRequestFailed); +} + +void ListModel::packRequestFinished() +{ + if (!jobPtr || m_aborted) + return; + + jobPtr.reset(); + remainingPacks.removeOne(currentPack); + + QJsonParseError parse_error; + QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error); + + if(parse_error.error != QJsonParseError::NoError) { + qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset << " reason: " << parse_error.errorString(); + qWarning() << response; + return; + } + + auto obj = doc.object(); + + ModpacksCH::Modpack pack; + try + { + ModpacksCH::loadModpack(pack, obj); + } + catch (const JSONValidationError &e) + { + qDebug() << QString::fromUtf8(response); + qWarning() << "Error while reading pack manifest from ModpacksCH: " << e.cause(); + return; + } + + // Since there is no guarantee that packs have a version, this will just + // ignore those "dud" packs. + if (pack.versions.empty()) + { + qWarning() << "ModpacksCH Pack " << pack.id << " ignored. reason: lacking any versions"; + } + else + { + beginInsertRows(QModelIndex(), modpacks.size(), modpacks.size()); + modpacks.append(pack); + endInsertRows(); + } + + if(!remainingPacks.isEmpty()) { + currentPack = remainingPacks.at(0); + requestPack(); + } +} + +void ListModel::packRequestFailed(QString reason) +{ + jobPtr.reset(); + remainingPacks.removeOne(currentPack); +} + +void ListModel::logoLoaded(QString logo, bool stale) +{ + auto & logoObj = m_logoMap[logo]; + logoObj.downloadJob.reset(); + QString smallPath = logoObj.fullpath + ".small"; + + QFileInfo smallInfo(smallPath); + + if(stale || !smallInfo.exists()) { + QImage image(logoObj.fullpath); + if (image.isNull()) + { + logoObj.failed = true; + return; + } + QImage small; + if (image.width() > image.height()) { + small = image.scaledToWidth(512).scaledToWidth(256, Qt::SmoothTransformation); + } + else { + small = image.scaledToHeight(512).scaledToHeight(256, Qt::SmoothTransformation); + } + QPoint offset((256 - small.width()) / 2, (256 - small.height()) / 2); + QImage square(QSize(256, 256), QImage::Format_ARGB32); + square.fill(Qt::transparent); + + QPainter painter(&square); + painter.drawImage(offset, small); + painter.end(); + + square.save(logoObj.fullpath + ".small", "PNG"); + } + + logoObj.result = QIcon(logoObj.fullpath + ".small"); + for(int i = 0; i < modpacks.size(); i++) { + if(modpacks[i].name == logo) { + emit dataChanged(createIndex(i, 0), createIndex(i, 0), {Qt::DecorationRole}); + } + } +} + +void ListModel::logoFailed(QString logo) +{ + m_logoMap[logo].failed = true; + m_logoMap[logo].downloadJob.reset(); +} + +void ListModel::requestLogo(QString logo, QString url) +{ + if(m_logoMap.contains(logo)) { + return; + } + + MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("ModpacksCHPacks", QString("logos/%1").arg(logo.section(".", 0, 0))); + + bool stale = entry->isStale(); + + auto job = makeShared(QString("ModpacksCH Icon Download %1").arg(logo), APPLICATION->network()); + job->addNetAction(Net::Download::makeCached(QUrl(url), entry)); + + auto fullPath = entry->getFullPath(); + QObject::connect(job.get(), &NetJob::finished, this, [this, logo, fullPath, stale] + { + logoLoaded(logo, stale); + }); + + QObject::connect(job.get(), &NetJob::failed, this, [this, logo] + { + logoFailed(logo); + }); + + auto &newLogoEntry = m_logoMap[logo]; + newLogoEntry.downloadJob = job; + newLogoEntry.fullpath = fullPath; + job->start(); +} + +} diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.h b/launcher/ui/pages/modplatform/ftb/FtbListModel.h new file mode 100644 index 000000000..d7a120f06 --- /dev/null +++ b/launcher/ui/pages/modplatform/ftb/FtbListModel.h @@ -0,0 +1,83 @@ +/* + * Copyright 2020-2021 Jamie Mansfield + * + * 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 + +#include "modplatform/modpacksch/FTBPackManifest.h" +#include "net/NetJob.h" +#include + +namespace Ftb { + +struct Logo { + QString fullpath; + NetJob::Ptr downloadJob; + QIcon result; + bool failed = false; +}; + +typedef QMap LogoMap; +typedef std::function LogoCallback; + +class ListModel : public QAbstractListModel +{ + Q_OBJECT + +public: + ListModel(QObject *parent); + virtual ~ListModel(); + + int rowCount(const QModelIndex &parent) const override; + int columnCount(const QModelIndex &parent) const override; + QVariant data(const QModelIndex &index, int role) const override; + + void request(); + void abortRequest(); + + void getLogo(const QString &logo, const QString &logoUrl, LogoCallback callback); + + [[nodiscard]] bool isMakingRequest() const { return jobPtr.get(); } + [[nodiscard]] bool wasAborted() const { return m_aborted; } + +private slots: + void requestFinished(); + void requestFailed(QString reason); + + void requestPack(); + void packRequestFinished(); + void packRequestFailed(QString reason); + + void logoFailed(QString logo); + void logoLoaded(QString logo, bool stale); + +private: + void requestLogo(QString file, QString url); + +private: + bool m_aborted = false; + + QList modpacks; + LogoMap m_logoMap; + + NetJob::Ptr jobPtr; + int currentPack; + QList remainingPacks; + QByteArray response; +}; + +} diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp new file mode 100644 index 000000000..7d59a6ae7 --- /dev/null +++ b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (c) 2022 Jamie Mansfield + * 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 2020-2021 Jamie Mansfield + * Copyright 2021 Philip T + * + * 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 "FtbPage.h" +#include "ui_FtbPage.h" + +#include + +#include "ui/dialogs/NewInstanceDialog.h" +#include "modplatform/modpacksch/FTBPackInstallTask.h" + +#include "Markdown.h" + +FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget *parent) + : QWidget(parent), ui(new Ui::FtbPage), dialog(dialog) +{ + ui->setupUi(this); + + filterModel = new Ftb::FilterModel(this); + listModel = new Ftb::ListModel(this); + filterModel->setSourceModel(listModel); + ui->packView->setModel(filterModel); + ui->packView->setSortingEnabled(true); + ui->packView->header()->hide(); + ui->packView->setIndentation(0); + + ui->searchEdit->installEventFilter(this); + + ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300); + + for(int i = 0; i < filterModel->getAvailableSortings().size(); i++) + { + ui->sortByBox->addItem(filterModel->getAvailableSortings().keys().at(i)); + } + ui->sortByBox->setCurrentText(filterModel->translateCurrentSorting()); + + connect(ui->searchEdit, &QLineEdit::textChanged, this, &FtbPage::triggerSearch); + connect(ui->sortByBox, &QComboBox::currentTextChanged, this, &FtbPage::onSortingSelectionChanged); + connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FtbPage::onSelectionChanged); + connect(ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FtbPage::onVersionSelectionChanged); + + ui->packDescription->setMetaEntry("FTBPacks"); +} + +FtbPage::~FtbPage() +{ + delete ui; +} + +bool FtbPage::eventFilter(QObject* watched, QEvent* event) +{ + if (watched == ui->searchEdit && event->type() == QEvent::KeyPress) { + QKeyEvent* keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Return) { + triggerSearch(); + keyEvent->accept(); + return true; + } + } + return QWidget::eventFilter(watched, event); +} + +bool FtbPage::shouldDisplay() const +{ + return true; +} + +void FtbPage::retranslate() +{ + ui->retranslateUi(this); +} + +void FtbPage::openedImpl() +{ + if(!initialised || listModel->wasAborted()) + { + listModel->request(); + initialised = true; + } + + suggestCurrent(); +} + +void FtbPage::closedImpl() +{ + if (listModel->isMakingRequest()) + listModel->abortRequest(); +} + +void FtbPage::suggestCurrent() +{ + if(!isOpened) + { + return; + } + + if (selectedVersion.isEmpty()) + { + dialog->setSuggestedPack(); + return; + } + + dialog->setSuggestedPack(selected.name, selectedVersion, new ModpacksCH::PackInstallTask(selected, selectedVersion, this)); + for(auto art : selected.art) { + if(art.type == "square") { + QString editedLogoName; + editedLogoName = selected.name; + + listModel->getLogo(selected.name, art.url, [this, editedLogoName](QString logo) + { + dialog->setSuggestedIconFromFile(logo + ".small", editedLogoName); + }); + } + } +} + +void FtbPage::triggerSearch() +{ + filterModel->setSearchTerm(ui->searchEdit->text()); +} + +void FtbPage::onSortingSelectionChanged(QString data) +{ + auto toSet = filterModel->getAvailableSortings().value(data); + filterModel->setSorting(toSet); +} + +void FtbPage::onSelectionChanged(QModelIndex first, QModelIndex second) +{ + ui->versionSelectionBox->clear(); + + if(!first.isValid()) + { + if(isOpened) + { + dialog->setSuggestedPack(); + } + return; + } + + selected = filterModel->data(first, Qt::UserRole).value(); + + QString output = markdownToHTML(selected.description.toUtf8()); + ui->packDescription->setHtml(output); + + // reverse foreach, so that the newest versions are first + for (auto i = selected.versions.size(); i--;) { + ui->versionSelectionBox->addItem(selected.versions.at(i).name); + } + + suggestCurrent(); +} + +void FtbPage::onVersionSelectionChanged(QString data) +{ + if(data.isNull() || data.isEmpty()) + { + selectedVersion = ""; + return; + } + + selectedVersion = data; + suggestCurrent(); +} diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.h b/launcher/ui/pages/modplatform/ftb/FtbPage.h new file mode 100644 index 000000000..631ae7f56 --- /dev/null +++ b/launcher/ui/pages/modplatform/ftb/FtbPage.h @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (c) 2022 Jamie Mansfield + * + * 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 "FtbFilterModel.h" +#include "FtbListModel.h" + +#include + +#include "Application.h" +#include "ui/pages/BasePage.h" +#include "tasks/Task.h" + +namespace Ui +{ + class FtbPage; +} + +class NewInstanceDialog; + +class FtbPage : public QWidget, public BasePage +{ +Q_OBJECT + +public: + explicit FtbPage(NewInstanceDialog* dialog, QWidget *parent = 0); + virtual ~FtbPage(); + virtual QString displayName() const override + { + return "FTB"; + } + virtual QIcon icon() const override + { + return APPLICATION->getThemedIcon("ftb_logo"); + } + virtual QString id() const override + { + return "ftb"; + } + virtual QString helpPage() const override + { + return "FTB-platform"; + } + virtual bool shouldDisplay() const override; + void retranslate() override; + + void openedImpl() override; + void closedImpl() override; + + bool eventFilter(QObject * watched, QEvent * event) override; + +private: + void suggestCurrent(); + +private slots: + void triggerSearch(); + + void onSortingSelectionChanged(QString data); + void onSelectionChanged(QModelIndex first, QModelIndex second); + void onVersionSelectionChanged(QString data); + +private: + Ui::FtbPage *ui = nullptr; + NewInstanceDialog* dialog = nullptr; + Ftb::ListModel* listModel = nullptr; + Ftb::FilterModel* filterModel = nullptr; + + ModpacksCH::Modpack selected; + QString selectedVersion; + + bool initialised { false }; +}; diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.ui b/launcher/ui/pages/modplatform/ftb/FtbPage.ui new file mode 100644 index 000000000..8de0f4e65 --- /dev/null +++ b/launcher/ui/pages/modplatform/ftb/FtbPage.ui @@ -0,0 +1,86 @@ + + + FtbPage + + + + 0 + 0 + 875 + 745 + + + + + + + + + + + + Version selected: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + + Search and filter... + + + true + + + + + + + + + true + + + + 48 + 48 + + + + + + + + true + + + true + + + + + + + + + + ProjectDescriptionPage + QTextBrowser +
ui/widgets/ProjectDescriptionPage.h
+
+
+ + searchEdit + versionSelectionBox + + + +
From 6b6ee82e6c376f3278f92f79ac032589dad1e248 Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:56:54 -0600 Subject: [PATCH 02/16] feat(ftb): add neoforge support to ftb --- launcher/modplatform/modpacksch/FTBPackInstallTask.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 68d4751cd..80a49bb2c 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -258,6 +258,8 @@ void PackInstallTask::createInstance() components->setComponentVersion("net.minecraftforge", target.version); } else if (target.name == "fabric") { components->setComponentVersion("net.fabricmc.fabric-loader", target.version); + } else if (target.name == "neoforge") { + components->setComponentVersion("net.neoforged", target.version); } } From 52eda4199251f2ac828de1915b86a0404693b17d Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sun, 8 Feb 2026 16:57:37 -0600 Subject: [PATCH 03/16] feat(ftb): add metacache directory for ftb packs --- launcher/Application.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index e6ae0132b..de397a94c 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1046,6 +1046,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_metacache->addBase("FlameMods", QDir("cache/FlameMods").absolutePath()); m_metacache->addBase("ModrinthPacks", QDir("cache/ModrinthPacks").absolutePath()); m_metacache->addBase("ModrinthModpacks", QDir("cache/ModrinthModpacks").absolutePath()); + m_metacache->addBase("ModpacksCHPacks", QDir("cache/ModpacksCHPacks").absolutePath()); m_metacache->addBase("translations", QDir("translations").absolutePath()); m_metacache->addBase("meta", QDir("meta").absolutePath()); m_metacache->addBase("java", QDir("cache/java").absolutePath()); From 25df6db67cfce89e896a10a8ecc07b635e6ca36e Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sun, 8 Feb 2026 17:01:02 -0600 Subject: [PATCH 04/16] feat(curseforge): allow fetching official api key Based upon the implementation by @evan-goode in FJord, without the popup on first launch. --- launcher/Application.cpp | 14 ++++ launcher/CMakeLists.txt | 2 + launcher/net/FetchFlameAPIKey.cpp | 106 +++++++++++++++++++++++++++ launcher/net/FetchFlameAPIKey.h | 42 +++++++++++ launcher/ui/GuiUtil.cpp | 22 ++++++ launcher/ui/GuiUtil.h | 1 + launcher/ui/pages/global/APIPage.cpp | 11 +++ launcher/ui/pages/global/APIPage.h | 1 + launcher/ui/pages/global/APIPage.ui | 13 +++- 9 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 launcher/net/FetchFlameAPIKey.cpp create mode 100644 launcher/net/FetchFlameAPIKey.h diff --git a/launcher/Application.cpp b/launcher/Application.cpp index de397a94c..6362ea6a9 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -50,6 +50,7 @@ #include "net/PasteUpload.h" #include "tasks/Task.h" #include "tools/GenericProfiler.h" +#include "ui/GuiUtil.h" #include "ui/InstanceWindow.h" #include "ui/MainWindow.h" #include "ui/ToolTipFilter.h" @@ -923,6 +924,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_settings->set("FlameKeyOverride", flameKey); m_settings->reset("CFKeyOverride"); } + m_settings->registerSetting("FlameKeyShouldBeFetchedOnStartup", true); m_settings->registerSetting("ModrinthToken", ""); m_settings->registerSetting("UserAgentOverride", ""); @@ -1400,6 +1402,18 @@ void Application::performMainStartupAction() return; } } + { + bool shouldFetch = m_settings->get("FlameKeyShouldBeFetchedOnStartup").toBool(); + if (shouldFetch && !(capabilities() & Capability::SupportsFlame)) { + const auto& apiKey = GuiUtil::fetchFlameKey(); + if (!apiKey.isEmpty()) { + m_settings->set("FlameKeyOverride", apiKey); + updateCapabilities(); + } + } + m_settings->set("FlameKeyShouldBeFetchedOnStartup", false); + } + } if (!m_mainWindow) { // normal main window showMainWindow(false); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 3cd46aa59..1181fc423 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -119,6 +119,8 @@ set(NET_SOURCES net/ChecksumValidator.h net/Download.cpp net/Download.h + net/FetchFlameAPIKey.cpp + net/FetchFlameAPIKey.h net/FileSink.cpp net/FileSink.h net/Head.cpp diff --git a/launcher/net/FetchFlameAPIKey.cpp b/launcher/net/FetchFlameAPIKey.cpp new file mode 100644 index 000000000..2aa03ab37 --- /dev/null +++ b/launcher/net/FetchFlameAPIKey.cpp @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 Lenny McLennington + * + * 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 . + */ + +#include "FetchFlameAPIKey.h" +#include +#include +#include "Application.h" + +#include +#include + +FetchFlameAPIKey::FetchFlameAPIKey() : Task{} {} + +// Here, we fetch the official CurseForge API key from the files of the +// CurseForge app. We range-request the specific ~84KiB zlib block inside the +// AppImage's SquashFS that contains the API key and extract only that. + +// Note: We need a direct link to the AppImage for this to work. The download +// link for the Linux app on CurseForge's website is to a zipped AppImage, +// which will not work here since (I think?) ZIP files typically have one +// non-chunked DEFLATE stream for each file, and there's no way to fetch a +// single, independent chunk to extract. + +// See also https://git.sakamoto.pl/domi/curseme/src/commit/388ac991eb57dedd5d1aca45f418deb221d757d1/getToken.sh + +const QUrl CURSEFORGE_APP_URL{ "https://curseforge.overwolf.com/electron/linux/CurseForge-0.198.1-21.AppImage" }; + +// Use https://github.com/unmojang/appimage-token-finder to find these offsets +const uint32_t IN_ADDR{ 82926761 }; +const uint32_t IN_SIZE{ 84196 }; +const uint32_t OUT_SIZE{ 131072 }; + +void FetchFlameAPIKey::executeTask() +{ + QNetworkRequest req{ CURSEFORGE_APP_URL }; + // Request only a single zlib block from inside the AppImage file + const auto& rangeHeader = QString("bytes=%1-%2").arg(IN_ADDR).arg(IN_ADDR + IN_SIZE); + req.setRawHeader("Range", rangeHeader.toUtf8()); + + m_reply.reset(APPLICATION->network()->get(req)); + connect(m_reply.get(), &QNetworkReply::downloadProgress, this, &Task::setProgress); + connect(m_reply.get(), &QNetworkReply::finished, this, &FetchFlameAPIKey::downloadFinished); + connect(m_reply.get(), +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + &QNetworkReply::errorOccurred, +#else + qOverload(&QNetworkReply::error), +#endif + this, [this](QNetworkReply::NetworkError error) { + qCritical() << "Network error: " << error; + emitFailed(m_reply->errorString()); + }); + + setStatus(tr("Fetching Curseforge core API key (may take a few seconds)...")); +} + +void FetchFlameAPIKey::downloadFinished() +{ + auto res = m_reply->readAll(); + + // Prepend expected size header. See https://doc.qt.io/qt-6/qbytearray.html#qUncompress-1 + QByteArray expectedSizeHeader; + QDataStream expectedSizeHeaderStream{ &expectedSizeHeader, QIODevice::WriteOnly }; + expectedSizeHeaderStream.setByteOrder(QDataStream::BigEndian); + expectedSizeHeaderStream << OUT_SIZE; + + res.prepend(expectedSizeHeader); + + const auto& block = qUncompress(res); + if (block.isEmpty()) { + emitFailed("Couldn't decompress Curseforge app data."); + } + + const char* precedingString = "\"cfCoreApiKey\":\""; + const QByteArray preceding{ precedingString }; + const auto& precedingIndex = block.indexOf(preceding); + if (precedingIndex == -1) { + emitFailed(QString("Couldn't find string '%1'.").arg(precedingString)); + } + + const auto& startIndex = precedingIndex + preceding.size(); + const auto& finalIndex = block.indexOf(QByteArray{ "\"" }, startIndex); + if (finalIndex == -1) { + emitFailed("Couldn't find closing \" for cfCoreApiKey value."); + } + + const auto& keyByteArray = block.mid(startIndex, finalIndex - startIndex); + m_result = QString{ keyByteArray }; + qDebug() << "Fetched Flame API key: " << m_result; + emitSucceeded(); +} diff --git a/launcher/net/FetchFlameAPIKey.h b/launcher/net/FetchFlameAPIKey.h new file mode 100644 index 000000000..e8f974cc7 --- /dev/null +++ b/launcher/net/FetchFlameAPIKey.h @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * PolyMC - Minecraft Launcher + * Copyright (C) 2022 Lenny McLennington + * + * 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 . + */ + +#ifndef FETCHFLAMEAPIKEY_H +#define FETCHFLAMEAPIKEY_H + +#include +#include +#include + +class FetchFlameAPIKey : public Task { + Q_OBJECT + public: + explicit FetchFlameAPIKey(); + + QString m_result; + + public slots: + void downloadFinished(); + + protected: + virtual void executeTask(); + + std::shared_ptr m_reply; +}; + +#endif // FETCHFLAMEAPIKEY_H diff --git a/launcher/ui/GuiUtil.cpp b/launcher/ui/GuiUtil.cpp index 141153b92..bee0bf6ea 100644 --- a/launcher/ui/GuiUtil.cpp +++ b/launcher/ui/GuiUtil.cpp @@ -45,6 +45,7 @@ #include "FileSystem.h" #include "logs/AnonymizeLog.h" +#include "net/FetchFlameAPIKey.h" #include "net/NetJob.h" #include "net/NetRequest.h" #include "net/PasteUpload.h" @@ -79,6 +80,27 @@ QString truncateLogForMclogs(const QString& logContent) return logContent; } +QString GuiUtil::fetchFlameKey(QWidget* parentWidget) +{ + ProgressDialog prog(parentWidget); + auto flameKeyTask = std::make_unique(); + prog.execWithTask(flameKeyTask.get()); + + if (!flameKeyTask->wasSuccessful()) { + auto message = QObject::tr("Fetching the Curseforge API key failed. Reason: %1").arg(flameKeyTask->failReason()); + if (!(APPLICATION->capabilities() & Application::SupportsFlame)) { + message += "\n\n" + QObject::tr( + "Downloading Curseforge modpacks will not work unless you manually set a valid Curseforge API key " + "in the settings."); + } + + CustomMessageBox::selectable(parentWidget, QObject::tr("Failed to fetch Curseforge API key."), message, QMessageBox::Critical) + ->exec(); + } + + return flameKeyTask->m_result; +} + std::optional GuiUtil::uploadPaste(const QString& name, const QFileInfo& filePath, QWidget* parentWidget) { return uploadPaste(name, FS::read(filePath.absoluteFilePath()), parentWidget); diff --git a/launcher/ui/GuiUtil.h b/launcher/ui/GuiUtil.h index c3ba01f5b..c9a8a7792 100644 --- a/launcher/ui/GuiUtil.h +++ b/launcher/ui/GuiUtil.h @@ -5,6 +5,7 @@ #include namespace GuiUtil { +QString fetchFlameKey(QWidget* parentWidget = nullptr); std::optional uploadPaste(const QString& name, const QFileInfo& filePath, QWidget* parentWidget); std::optional uploadPaste(const QString& name, const QString& data, QWidget* parentWidget); void setClipboardText(QString text); diff --git a/launcher/ui/pages/global/APIPage.cpp b/launcher/ui/pages/global/APIPage.cpp index ebe93e5b4..0b0d9f3fb 100644 --- a/launcher/ui/pages/global/APIPage.cpp +++ b/launcher/ui/pages/global/APIPage.cpp @@ -52,6 +52,7 @@ #include "net/PasteUpload.h" #include "settings/SettingsObject.h" #include "tools/BaseProfiler.h" +#include "ui/GuiUtil.h" APIPage::APIPage(QWidget* parent) : QWidget(parent), ui(new Ui::APIPage) { @@ -87,6 +88,8 @@ APIPage::APIPage(QWidget* parent) : QWidget(parent), ui(new Ui::APIPage) resetBaseURLNote(); connect(ui->pasteTypeComboBox, currentIndexChangedSignal, this, &APIPage::updateBaseURLNote); connect(ui->baseURLEntry, &QLineEdit::textEdited, this, &APIPage::resetBaseURLNote); + + connect(ui->fetchKeyButton, &QPushButton::clicked, this, &APIPage::fetchKeyButtonPressed); } APIPage::~APIPage() @@ -194,6 +197,14 @@ void APIPage::applySettings() s->set("TechnicClientID", ui->technicClientID->text()); } +void APIPage::fetchKeyButtonPressed() +{ + QString apiKey = GuiUtil::fetchFlameKey(parentWidget()); + + if (!apiKey.isEmpty()) + ui->flameKey->setText(apiKey); +} + bool APIPage::apply() { applySettings(); diff --git a/launcher/ui/pages/global/APIPage.h b/launcher/ui/pages/global/APIPage.h index 7a22aa069..04010dcfc 100644 --- a/launcher/ui/pages/global/APIPage.h +++ b/launcher/ui/pages/global/APIPage.h @@ -66,6 +66,7 @@ class APIPage : public QWidget, public BasePage { void updateBaseURLPlaceholder(int index); void loadSettings(); void applySettings(); + void fetchKeyButtonPressed(); private: Ui::APIPage* ui; diff --git a/launcher/ui/pages/global/APIPage.ui b/launcher/ui/pages/global/APIPage.ui index cb0abe557..13648575b 100644 --- a/launcher/ui/pages/global/APIPage.ui +++ b/launcher/ui/pages/global/APIPage.ui @@ -339,6 +339,8 @@ + + true @@ -347,11 +349,20 @@ Use Default + + + + + Fetch Official Launcher's Key + + + + - Note: you probably don't need to set this if CurseForge already works. + <span style="font-weight:700;">Using the official CurseForge app's API key may break CurseForge's terms of service but should allow Freesm Launcher to download all mods in a modpack without you needing to download any of them manually.</span> true From f5d8a62f031f284e52794b289e7baef223429bf6 Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sun, 8 Feb 2026 17:04:02 -0600 Subject: [PATCH 05/16] feat: allow curseforge to appear on new instance page regardless of api key --- launcher/ui/dialogs/NewInstanceDialog.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 8cf094527..4ad4d6127 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -176,8 +176,7 @@ QList NewInstanceDialog::getPages() pages.append(new CustomPage(this)); pages.append(importPage); pages.append(new AtlPage(this)); - if (APPLICATION->capabilities() & Application::SupportsFlame) - pages.append(new FlamePage(this)); + pages.append(new FlamePage(this)); pages.append(new FtbPage(this)); pages.append(new LegacyFTB::Page(this)); pages.append(new FTBImportAPP::ImportFTBPage(this)); From 1f16751412b2830de12678b823601719795dab14 Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sun, 8 Feb 2026 17:05:45 -0600 Subject: [PATCH 06/16] chore: remove prism's api key Remove the Prism Launcher CurseForge key, as we have access to the official one. --- CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a674da86..08101c9cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,11 +267,7 @@ set(Launcher_MSA_CLIENT_ID "c36a9fb6-4f2a-41ff-90bd-ae7cc92031eb" CACHE STRING " set(Launcher_ELYBY_CLIENT_ID "freesm-launcher" CACHE STRING "Client ID you can get from Ely.by Accounts for developers when you register an application") -# By using this key in your builds you accept the terms and conditions laid down in -# https://support.curseforge.com/en/support/solutions/articles/9000207405-curse-forge-3rd-party-api-terms-and-conditions -# NOTE: CurseForge requires you to change this if you make any kind of derivative work. -# This key was issued specifically for Prism Launcher -set(Launcher_CURSEFORGE_API_KEY "$2a$10$wuAJuNZuted3NORVmpgUC.m8sI.pv1tOPKZyBgLFGjxFp/br0lZCC" CACHE STRING "API key for the CurseForge platform") +set(Launcher_CURSEFORGE_API_KEY "" CACHE STRING "API key for the CurseForge platform") set(Launcher_COMPILER_NAME ${CMAKE_CXX_COMPILER_ID}) set(Launcher_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION}) From 90d80ae7aa8ba21733f07fac094f227eac1d9cb4 Mon Sep 17 00:00:00 2001 From: Luna <93695520+LunaisLazier@users.noreply.github.com> Date: Sun, 8 Feb 2026 17:07:42 -0600 Subject: [PATCH 07/16] chore: remove (now) incorrect message Removes the message above CurseForge modpacks as manually downloading mods is not required with the official API. --- .../ui/pages/modplatform/flame/FlamePage.ui | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/launcher/ui/pages/modplatform/flame/FlamePage.ui b/launcher/ui/pages/modplatform/flame/FlamePage.ui index cf882ef1c..56e177882 100644 --- a/launcher/ui/pages/modplatform/flame/FlamePage.ui +++ b/launcher/ui/pages/modplatform/flame/FlamePage.ui @@ -11,24 +11,6 @@ - - - - - true - - - - Note: CurseForge allows creators to block access to third-party tools like Prism Launcher. As such, you may need to manually download some mods to be able to install a modpack. - - - Qt::AlignCenter - - - true - - - From 32bc7affc6e2d3d888c300625e0a68ccdb36324a Mon Sep 17 00:00:00 2001 From: notwindstone Date: Thu, 12 Feb 2026 17:54:04 +0300 Subject: [PATCH 08/16] fix(ftb): use QIcon instead of a non-existent getThemedIcon --- launcher/ui/pages/modplatform/ftb/FtbListModel.cpp | 2 +- launcher/ui/pages/modplatform/ftb/FtbPage.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp index e80654158..f68ce8e8e 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp +++ b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp @@ -61,7 +61,7 @@ QVariant ListModel::data(const QModelIndex &index, int role) const } else if(role == Qt::DecorationRole) { - QIcon placeholder = APPLICATION->getThemedIcon("screenshot-placeholder"); + QIcon placeholder = QIcon::fromTheme("screenshot-placeholder"); auto iter = m_logoMap.find(pack.name); if (iter != m_logoMap.end()) { diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.h b/launcher/ui/pages/modplatform/ftb/FtbPage.h index 631ae7f56..528755a1f 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbPage.h +++ b/launcher/ui/pages/modplatform/ftb/FtbPage.h @@ -40,7 +40,6 @@ #include -#include "Application.h" #include "ui/pages/BasePage.h" #include "tasks/Task.h" @@ -64,7 +63,7 @@ Q_OBJECT } virtual QIcon icon() const override { - return APPLICATION->getThemedIcon("ftb_logo"); + return QIcon::fromTheme("ftb_logo"); } virtual QString id() const override { From 2651a8cb67d7fb3d514bfdc244b90d0fc5fdea1d Mon Sep 17 00:00:00 2001 From: notwindstone Date: Thu, 12 Feb 2026 18:29:47 +0300 Subject: [PATCH 09/16] fix(ftb): replace missing methods with their alternatives --- .../modpacksch/FTBPackInstallTask.cpp | 20 ++++++++----------- .../modpacksch/FTBPackManifest.cpp | 8 ++++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 80a49bb2c..a800c6b4d 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -90,7 +90,7 @@ void PackInstallTask::executeTask() auto netJob = makeShared("ModpacksCH::VersionFetch", APPLICATION->network()); auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1/%2").arg(m_pack.id).arg(version.id); - netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &m_response)); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), m_response)); QObject::connect(netJob.get(), &NetJob::succeeded, this, &PackInstallTask::onManifestDownloadSucceeded); QObject::connect(netJob.get(), &NetJob::failed, this, &PackInstallTask::onManifestDownloadFailed); @@ -108,11 +108,11 @@ void PackInstallTask::onManifestDownloadSucceeded() m_net_job.reset(); QJsonParseError parse_error{}; - QJsonDocument doc = QJsonDocument::fromJson(m_response, &parse_error); + QJsonDocument doc = QJsonDocument::fromJson(*m_response, &parse_error); if (parse_error.error != QJsonParseError::NoError) { qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset << " reason: " << parse_error.errorString(); - qWarning() << m_response; + qWarning() << *m_response; return; } @@ -139,7 +139,6 @@ void PackInstallTask::resolveMods() m_file_id_map.clear(); Flame::Manifest manifest; - int index = 0; for (auto const& file : m_version.files) { if (!file.serverOnly && file.url.isEmpty()) { @@ -151,18 +150,15 @@ void PackInstallTask::resolveMods() Flame::File flame_file; flame_file.projectId = file.curseforge.project_id; flame_file.fileId = file.curseforge.file_id; - flame_file.hash = file.sha1; manifest.files.insert(flame_file.fileId, flame_file); m_file_id_map.append(flame_file.fileId); } else { m_file_id_map.append(-1); } - - index++; } - m_mod_id_resolver_task.reset(new Flame::FileResolvingTask(APPLICATION->network(), manifest)); + m_mod_id_resolver_task.reset(new Flame::FileResolvingTask(manifest)); connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::succeeded, this, &PackInstallTask::onResolveModsSucceeded); connect(m_mod_id_resolver_task.get(), &Flame::FileResolvingTask::failed, this, &PackInstallTask::onResolveModsFailed); @@ -188,11 +184,11 @@ void PackInstallTask::onResolveModsSucceeded() VersionFile& local_file = m_version.files[index]; // First check for blocked mods - if (!results_file.resolved || results_file.url.isEmpty()) { + if (results_file.version.downloadUrl.isEmpty()) { BlockedMod blocked_mod; blocked_mod.name = local_file.name; - blocked_mod.websiteUrl = results_file.websiteUrl; - blocked_mod.hash = results_file.hash; + blocked_mod.websiteUrl = results_file.pack.websiteUrl; + blocked_mod.hash = results_file.version.hash; blocked_mod.matched = false; blocked_mod.localPath = ""; blocked_mod.targetFolder = results_file.targetFolder; @@ -201,7 +197,7 @@ void PackInstallTask::onResolveModsSucceeded() anyBlocked = true; } else { - local_file.url = results_file.url.toString(); + local_file.url = results_file.version.downloadUrl; } } diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.cpp b/launcher/modplatform/modpacksch/FTBPackManifest.cpp index 421527aef..b88507171 100644 --- a/launcher/modplatform/modpacksch/FTBPackManifest.cpp +++ b/launcher/modplatform/modpacksch/FTBPackManifest.cpp @@ -146,16 +146,16 @@ static void loadVersionFile(ModpacksCH::VersionFile & a, QJsonObject & obj) a.path = Json::requireString(obj, "path"); a.name = Json::requireString(obj, "name"); a.version = Json::requireString(obj, "version"); - a.url = Json::ensureString(obj, "url"); // optional + a.url = obj["url"].toString(""); // optional a.sha1 = Json::requireString(obj, "sha1"); a.size = Json::requireInteger(obj, "size"); a.clientOnly = Json::requireBoolean(obj, "clientonly"); a.serverOnly = Json::requireBoolean(obj, "serveronly"); a.optional = Json::requireBoolean(obj, "optional"); a.updated = Json::requireInteger(obj, "updated"); - auto curseforgeObj = Json::ensureObject(obj, "curseforge"); // optional - a.curseforge.project_id = Json::ensureInteger(curseforgeObj, "project"); - a.curseforge.file_id = Json::ensureInteger(curseforgeObj, "file"); + auto curseforgeObj = obj["curseforge"].toObject(); // optional + a.curseforge.project_id = curseforgeObj["project"].toInt(); + a.curseforge.file_id = curseforgeObj["file"].toInt(); } void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj) From 668a805086bf4a79740782007e64f4a61fbd39fb Mon Sep 17 00:00:00 2001 From: notwindstone Date: Thu, 12 Feb 2026 19:00:29 +0300 Subject: [PATCH 10/16] fix: fix closure syntax and change the variable type --- launcher/Application.cpp | 3 +-- launcher/modplatform/modpacksch/FTBPackInstallTask.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 6362ea6a9..91dce8f3e 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -1411,8 +1411,7 @@ void Application::performMainStartupAction() updateCapabilities(); } } - m_settings->set("FlameKeyShouldBeFetchedOnStartup", false); - } + m_settings->set("FlameKeyShouldBeFetchedOnStartup", false); } if (!m_mainWindow) { // normal main window diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index 97b1eb0b1..68acf0463 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -85,7 +85,7 @@ private slots: QList m_file_id_map; - QByteArray m_response; + std::shared_ptr m_response = std::make_shared(); Modpack m_pack; QString m_version_name; From 762610f9005762ed4b1a5c9e1f9627c86f184e5c Mon Sep 17 00:00:00 2001 From: notwindstone Date: Thu, 12 Feb 2026 19:20:05 +0300 Subject: [PATCH 11/16] fix(ftb): change the response variable type --- launcher/ui/pages/modplatform/ftb/FtbListModel.cpp | 14 +++++++------- launcher/ui/pages/modplatform/ftb/FtbListModel.h | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp index f68ce8e8e..f41a863ae 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp +++ b/launcher/ui/pages/modplatform/ftb/FtbListModel.cpp @@ -111,7 +111,7 @@ void ListModel::request() auto netJob = makeShared("Ftb::Request", APPLICATION->network()); auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all"); - netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), &response)); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), response)); jobPtr = netJob; jobPtr->start(); @@ -131,10 +131,10 @@ void ListModel::requestFinished() remainingPacks.clear(); QJsonParseError parse_error {}; - QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error); + QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if(parse_error.error != QJsonParseError::NoError) { qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset << " reason: " << parse_error.errorString(); - qWarning() << response; + qWarning() << *response; return; } @@ -160,7 +160,7 @@ void ListModel::requestPack() { auto netJob = makeShared("Ftb::Search", APPLICATION->network()); auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1").arg(currentPack); - netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); + netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), response)); jobPtr = netJob; jobPtr->start(); @@ -177,11 +177,11 @@ void ListModel::packRequestFinished() remainingPacks.removeOne(currentPack); QJsonParseError parse_error; - QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error); + QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); if(parse_error.error != QJsonParseError::NoError) { qWarning() << "Error while parsing JSON response from ModpacksCH at " << parse_error.offset << " reason: " << parse_error.errorString(); - qWarning() << response; + qWarning() << *response; return; } @@ -194,7 +194,7 @@ void ListModel::packRequestFinished() } catch (const JSONValidationError &e) { - qDebug() << QString::fromUtf8(response); + qDebug() << QString::fromUtf8(*response); qWarning() << "Error while reading pack manifest from ModpacksCH: " << e.cause(); return; } diff --git a/launcher/ui/pages/modplatform/ftb/FtbListModel.h b/launcher/ui/pages/modplatform/ftb/FtbListModel.h index d7a120f06..d640b5c06 100644 --- a/launcher/ui/pages/modplatform/ftb/FtbListModel.h +++ b/launcher/ui/pages/modplatform/ftb/FtbListModel.h @@ -77,7 +77,7 @@ private slots: NetJob::Ptr jobPtr; int currentPack; QList remainingPacks; - QByteArray response; + std::shared_ptr response = std::make_shared(); }; } From 57ef1e1690f6dcc1e68454dd1c1c2e6e562328d6 Mon Sep 17 00:00:00 2001 From: so5iso4ka Date: Sun, 15 Feb 2026 12:23:05 +0300 Subject: [PATCH 12/16] chore(flame): remove unnecessary qt5 compatibility code as it is no longer supported Signed-off-by: so5iso4ka --- launcher/net/FetchFlameAPIKey.cpp | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/launcher/net/FetchFlameAPIKey.cpp b/launcher/net/FetchFlameAPIKey.cpp index 2aa03ab37..c637fdf2b 100644 --- a/launcher/net/FetchFlameAPIKey.cpp +++ b/launcher/net/FetchFlameAPIKey.cpp @@ -55,16 +55,10 @@ void FetchFlameAPIKey::executeTask() m_reply.reset(APPLICATION->network()->get(req)); connect(m_reply.get(), &QNetworkReply::downloadProgress, this, &Task::setProgress); connect(m_reply.get(), &QNetworkReply::finished, this, &FetchFlameAPIKey::downloadFinished); - connect(m_reply.get(), -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) - &QNetworkReply::errorOccurred, -#else - qOverload(&QNetworkReply::error), -#endif - this, [this](QNetworkReply::NetworkError error) { - qCritical() << "Network error: " << error; - emitFailed(m_reply->errorString()); - }); + connect(m_reply.get(), &QNetworkReply::errorOccurred, this, [this](QNetworkReply::NetworkError error) { + qCritical() << "Network error: " << error; + emitFailed(m_reply->errorString()); + }); setStatus(tr("Fetching Curseforge core API key (may take a few seconds)...")); } From 5e93fb1e4225016649b0e99831e466e86c0bb66d Mon Sep 17 00:00:00 2001 From: so5iso4ka Date: Sun, 15 Feb 2026 12:31:35 +0300 Subject: [PATCH 13/16] fix(flame): add missing return statements Signed-off-by: so5iso4ka --- launcher/net/FetchFlameAPIKey.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launcher/net/FetchFlameAPIKey.cpp b/launcher/net/FetchFlameAPIKey.cpp index c637fdf2b..41b4f9374 100644 --- a/launcher/net/FetchFlameAPIKey.cpp +++ b/launcher/net/FetchFlameAPIKey.cpp @@ -78,6 +78,7 @@ void FetchFlameAPIKey::downloadFinished() const auto& block = qUncompress(res); if (block.isEmpty()) { emitFailed("Couldn't decompress Curseforge app data."); + return; } const char* precedingString = "\"cfCoreApiKey\":\""; @@ -85,12 +86,14 @@ void FetchFlameAPIKey::downloadFinished() const auto& precedingIndex = block.indexOf(preceding); if (precedingIndex == -1) { emitFailed(QString("Couldn't find string '%1'.").arg(precedingString)); + return; } const auto& startIndex = precedingIndex + preceding.size(); const auto& finalIndex = block.indexOf(QByteArray{ "\"" }, startIndex); if (finalIndex == -1) { emitFailed("Couldn't find closing \" for cfCoreApiKey value."); + return; } const auto& keyByteArray = block.mid(startIndex, finalIndex - startIndex); From eafda60da67c82046500607e0198fac8f9eb1f3b Mon Sep 17 00:00:00 2001 From: so5iso4ka Date: Sun, 15 Feb 2026 12:32:39 +0300 Subject: [PATCH 14/16] refactor(flame): log API key in auth credentials category Signed-off-by: so5iso4ka --- launcher/net/FetchFlameAPIKey.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/launcher/net/FetchFlameAPIKey.cpp b/launcher/net/FetchFlameAPIKey.cpp index 41b4f9374..c5cfd6783 100644 --- a/launcher/net/FetchFlameAPIKey.cpp +++ b/launcher/net/FetchFlameAPIKey.cpp @@ -19,6 +19,8 @@ #include "FetchFlameAPIKey.h" #include #include +#include + #include "Application.h" #include @@ -98,6 +100,6 @@ void FetchFlameAPIKey::downloadFinished() const auto& keyByteArray = block.mid(startIndex, finalIndex - startIndex); m_result = QString{ keyByteArray }; - qDebug() << "Fetched Flame API key: " << m_result; + qCDebug(authCredentials()) << "Fetched Flame API key: " << m_result; emitSucceeded(); } From 7c3c2dd8eb0ae42f78b3145f916ccdedddbc4840 Mon Sep 17 00:00:00 2001 From: so5iso4ka Date: Sun, 15 Feb 2026 12:35:42 +0300 Subject: [PATCH 15/16] style: replace include guard with pragma once Signed-off-by: so5iso4ka --- launcher/net/FetchFlameAPIKey.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/launcher/net/FetchFlameAPIKey.h b/launcher/net/FetchFlameAPIKey.h index e8f974cc7..31bea4a95 100644 --- a/launcher/net/FetchFlameAPIKey.h +++ b/launcher/net/FetchFlameAPIKey.h @@ -16,8 +16,7 @@ * along with this program. If not, see . */ -#ifndef FETCHFLAMEAPIKEY_H -#define FETCHFLAMEAPIKEY_H +#pragma once #include #include @@ -38,5 +37,3 @@ class FetchFlameAPIKey : public Task { std::shared_ptr m_reply; }; - -#endif // FETCHFLAMEAPIKEY_H From bdbeecad6c54a46ec4cb221f3f588bd768908ff3 Mon Sep 17 00:00:00 2001 From: so5iso4ka Date: Sun, 15 Feb 2026 15:13:58 +0300 Subject: [PATCH 16/16] feat(flame): move API key fetching to setup wizard Signed-off-by: so5iso4ka --- CMakeLists.txt | 6 +- launcher/Application.cpp | 21 +++--- launcher/CMakeLists.txt | 2 + .../ui/setupwizard/FlameApiKeyWizardPage.cpp | 66 +++++++++++++++++++ .../ui/setupwizard/FlameApiKeyWizardPage.h | 39 +++++++++++ 5 files changed, 121 insertions(+), 13 deletions(-) create mode 100644 launcher/ui/setupwizard/FlameApiKeyWizardPage.cpp create mode 100644 launcher/ui/setupwizard/FlameApiKeyWizardPage.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 08101c9cc..1a674da86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -267,7 +267,11 @@ set(Launcher_MSA_CLIENT_ID "c36a9fb6-4f2a-41ff-90bd-ae7cc92031eb" CACHE STRING " set(Launcher_ELYBY_CLIENT_ID "freesm-launcher" CACHE STRING "Client ID you can get from Ely.by Accounts for developers when you register an application") -set(Launcher_CURSEFORGE_API_KEY "" CACHE STRING "API key for the CurseForge platform") +# By using this key in your builds you accept the terms and conditions laid down in +# https://support.curseforge.com/en/support/solutions/articles/9000207405-curse-forge-3rd-party-api-terms-and-conditions +# NOTE: CurseForge requires you to change this if you make any kind of derivative work. +# This key was issued specifically for Prism Launcher +set(Launcher_CURSEFORGE_API_KEY "$2a$10$wuAJuNZuted3NORVmpgUC.m8sI.pv1tOPKZyBgLFGjxFp/br0lZCC" CACHE STRING "API key for the CurseForge platform") set(Launcher_COMPILER_NAME ${CMAKE_CXX_COMPILER_ID}) set(Launcher_COMPILER_VERSION ${CMAKE_CXX_COMPILER_VERSION}) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 91dce8f3e..b22134c80 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -71,6 +71,7 @@ #include "ui/pages/global/ProxyPage.h" #include "ui/setupwizard/AutoJavaWizardPage.h" +#include "ui/setupwizard/FlameApiKeyWizardPage.h" #include "ui/setupwizard/JavaWizardPage.h" #include "ui/setupwizard/LanguageWizardPage.h" #include "ui/setupwizard/LoginWizardPage.h" @@ -1265,8 +1266,10 @@ bool Application::createSetupWizard() bool validWidgets = m_themeManager->isValidApplicationTheme(settings()->get("ApplicationTheme").toString()); bool validIcons = m_themeManager->isValidIconTheme(settings()->get("IconTheme").toString()); bool login = !m_accounts->anyAccountIsValid() && capabilities() & Application::SupportsMSA; + bool fetchFlameAPIKey = settings()->get("FlameKeyShouldBeFetchedOnStartup").toBool(); bool themeInterventionRequired = !validWidgets || !validIcons; - bool wizardRequired = javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired || askjava || login; + bool wizardRequired = + javaRequired || languageRequired || pasteInterventionRequired || themeInterventionRequired || askjava || login || fetchFlameAPIKey; if (wizardRequired) { // set default theme after going into theme wizard if (!validIcons) @@ -1306,6 +1309,11 @@ bool Application::createSetupWizard() if (login) { m_setupWizard->addPage(new LoginWizardPage(m_setupWizard)); } + + if (fetchFlameAPIKey) { + m_setupWizard->addPage(new FlameAPIKeyWizardPage(m_setupWizard)); + } + connect(m_setupWizard, &QDialog::finished, this, &Application::setupWizardFinished); m_setupWizard->show(); } @@ -1402,17 +1410,6 @@ void Application::performMainStartupAction() return; } } - { - bool shouldFetch = m_settings->get("FlameKeyShouldBeFetchedOnStartup").toBool(); - if (shouldFetch && !(capabilities() & Capability::SupportsFlame)) { - const auto& apiKey = GuiUtil::fetchFlameKey(); - if (!apiKey.isEmpty()) { - m_settings->set("FlameKeyOverride", apiKey); - updateCapabilities(); - } - } - m_settings->set("FlameKeyShouldBeFetchedOnStartup", false); - } if (!m_mainWindow) { // normal main window showMainWindow(false); diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 1181fc423..c3c898551 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -913,6 +913,8 @@ SET(LAUNCHER_SOURCES ui/setupwizard/SetupWizard.h ui/setupwizard/SetupWizard.cpp ui/setupwizard/BaseWizardPage.h + ui/setupwizard/FlameApiKeyWizardPage.cpp + ui/setupwizard/FlameApiKeyWizardPage.h ui/setupwizard/JavaWizardPage.cpp ui/setupwizard/JavaWizardPage.h ui/setupwizard/LanguageWizardPage.cpp diff --git a/launcher/ui/setupwizard/FlameApiKeyWizardPage.cpp b/launcher/ui/setupwizard/FlameApiKeyWizardPage.cpp new file mode 100644 index 000000000..32c72fafc --- /dev/null +++ b/launcher/ui/setupwizard/FlameApiKeyWizardPage.cpp @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Freesm Launcher - Minecraft Launcher + * Copyright (C) 2026 so5iso4ka + * + * 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 . + */ + +#include +#include +#include + +#include "Application.h" +#include "ui/GuiUtil.h" + +#include "FlameApiKeyWizardPage.h" + +FlameAPIKeyWizardPage::FlameAPIKeyWizardPage(QWidget* parent) : BaseWizardPage(parent) +{ + auto layout = new QVBoxLayout{ this }; + m_titleLabel = new QLabel{ this }; + m_descriptionLabel = new QLabel{ this }; + m_descriptionLabel->setWordWrap(true); + m_fetchButton = new QPushButton{ this }; + + connect(m_fetchButton, &QPushButton::clicked, this, [this] { + const auto& apiKey = GuiUtil::fetchFlameKey(this); + if (!apiKey.isEmpty()) { + APPLICATION->settings()->set("FlameKeyOverride", apiKey); + APPLICATION->updateCapabilities(); + } + }); + + layout->addWidget(m_titleLabel); + layout->addWidget(m_descriptionLabel); + layout->addWidget(m_fetchButton); + + setLayout(layout); + + FlameAPIKeyWizardPage::retranslate(); +} + +void FlameAPIKeyWizardPage::initializePage() +{ + APPLICATION->settings()->set("FlameKeyShouldBeFetchedOnStartup", false); +} + +void FlameAPIKeyWizardPage::retranslate() +{ + m_titleLabel->setText( + tr(R"(

Fetch CurseForge API key

)")); + m_descriptionLabel->setText( + tr("Using the official CurseForge app's API key may break CurseForge's terms of service but should allow Freesm Launcher to " + "download all mods in a modpack without you needing to download any of them manually. This can be done later in the settings.")); + m_fetchButton->setText(tr("Fetch Official Launcher's Key")); +} diff --git a/launcher/ui/setupwizard/FlameApiKeyWizardPage.h b/launcher/ui/setupwizard/FlameApiKeyWizardPage.h new file mode 100644 index 000000000..1ceed6aa3 --- /dev/null +++ b/launcher/ui/setupwizard/FlameApiKeyWizardPage.h @@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-3.0-only +/* + * Freesm Launcher - Minecraft Launcher + * Copyright (C) 2026 so5iso4ka + * + * 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 . + */ + +#pragma once + +class QLabel; +class QPushButton; + +#include "BaseWizardPage.h" + +class FlameAPIKeyWizardPage : public BaseWizardPage { + Q_OBJECT + public: + explicit FlameAPIKeyWizardPage(QWidget* parent = nullptr); + + void initializePage() override; + + void retranslate() override; + + private: + QLabel* m_titleLabel; + QLabel* m_descriptionLabel; + QPushButton* m_fetchButton; +};