Revert "chore: remove FTB modpack support"

This reverts commit ff07714e8c955003bb3deec84ec6cce6fc3ef5e6.

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2025-01-31 15:09:25 +02:00
parent 078de50951
commit 22dfeec865
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
14 changed files with 1685 additions and 0 deletions

View File

@ -999,6 +999,7 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv)
m_metacache->addBase("FTBPacks", QDir("cache/FTBPacks").absolutePath());
m_metacache->addBase("TechnicPacks", QDir("cache/TechnicPacks").absolutePath());
m_metacache->addBase("FlamePacks", QDir("cache/FlamePacks").absolutePath());
m_metacache->addBase("ModpacksCHPacks", QDir("cache/ModpacksCHPacks").absolutePath());
m_metacache->addBase("FlameMods", QDir("cache/FlameMods").absolutePath());
m_metacache->addBase("ModrinthPacks", QDir("cache/ModrinthPacks").absolutePath());
m_metacache->addBase("ModrinthModpacks", QDir("cache/ModrinthModpacks").absolutePath());

View File

@ -566,6 +566,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
@ -778,6 +785,7 @@ set(LOGIC_SOURCES
${FTB_SOURCES}
${FLAME_SOURCES}
${MODRINTH_SOURCES}
${MODPACKSCH_SOURCES}
${PACKWIZ_SOURCES}
${TECHNIC_SOURCES}
${ATLAUNCHER_SOURCES}
@ -1011,6 +1019,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
@ -1234,6 +1249,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

View File

@ -0,0 +1,388 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 flowln <flowlnlnln@gmail.com>
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright 2020-2021 Petr Mrazek <peterix@gmail.com>
*
* 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_versionName(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_modIdResolverTask)
aborted &= m_modIdResolverTask->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_versionName; });
if (version_it == m_pack.versions.constEnd()) {
emitFailed(tr("Failed to find pack version %1").arg(m_versionName));
return;
}
auto version = *version_it;
auto netJob = makeShared<NetJob>("ModpacksCH::VersionFetch", APPLICATION->network());
auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1/%2").arg(m_pack.id).arg(version.id);
m_response.reset(new QByteArray());
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_fileIds.clear();
Flame::Manifest manifest;
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 flameFile;
flameFile.projectId = file.curseforge.project_id;
flameFile.fileId = file.curseforge.file_id;
// flame_file.hash = file.sha1;
manifest.files.insert(flameFile.fileId, flameFile);
m_fileIds.append(flameFile.fileId);
} else {
m_fileIds.append(-1);
}
}
m_modIdResolverTask.reset(new Flame::FileResolvingTask(APPLICATION->network(), manifest));
connect(m_modIdResolverTask.get(), &Flame::FileResolvingTask::succeeded, this, &PackInstallTask::onResolveModsSucceeded);
connect(m_modIdResolverTask.get(), &Flame::FileResolvingTask::failed, this, &PackInstallTask::onResolveModsFailed);
connect(m_modIdResolverTask.get(), &Flame::FileResolvingTask::aborted, this, &PackInstallTask::abort);
connect(m_modIdResolverTask.get(), &Flame::FileResolvingTask::progress, this, &PackInstallTask::setProgress);
setAbortable(true);
m_modIdResolverTask->start();
}
void PackInstallTask::onResolveModsSucceeded()
{
auto anyBlocked = false;
Flame::Manifest results = m_modIdResolverTask->getResults();
for (int index = 0; index < m_fileIds.size(); index++) {
auto const file_id = m_fileIds.at(index);
if (file_id < 0)
continue;
Flame::File resultsFile = results.files[file_id];
VersionFile& localFile = m_version.files[index];
// First check for blocked mods
if (resultsFile.version.downloadUrl.isEmpty()) {
BlockedMod blocked_mod;
blocked_mod.name = resultsFile.version.fileName;
blocked_mod.websiteUrl = QString("%1/download/%2").arg(resultsFile.pack.websiteUrl, QString::number(resultsFile.fileId));
blocked_mod.hash = resultsFile.version.hash;
blocked_mod.matched = false;
blocked_mod.localPath = "";
blocked_mod.targetFolder = resultsFile.targetFolder;
m_blockedMods.append(blocked_mod);
anyBlocked = true;
} else {
localFile.url = resultsFile.version.downloadUrl;
}
}
m_modIdResolverTask.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.<br/>"
"You will need to manually download them and add them to the instance."),
m_blockedMods);
message_dialog.setModal(true);
if (message_dialog.exec() == QDialog::Accepted) {
qDebug() << "Post dialog blocked mods list: " << m_blockedMods;
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<INISettingsObject>(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);
} else if (target.name == "neoforge") {
components->setComponentVersion("net.neoforged", target.version);
} else if (target.name == "quilt") {
components->setComponentVersion("org.quiltmc.quilt-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<NetJob>(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()) {
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, file.sha1));
}
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_blockedMods.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_blockedMods.length();
setProgress(i, total);
for (auto const& mod : m_blockedMods) {
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

View File

@ -0,0 +1,100 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2022 flowln <flowlnlnln@gmail.com>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright 2020-2021 Petr Mrazek <peterix@gmail.com>
*
* 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 <QWidget>
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<Flame::FileResolvingTask> m_modIdResolverTask = nullptr;
QList<int> m_fileIds;
std::shared_ptr<QByteArray> m_response;
Modpack m_pack;
QString m_versionName;
Version m_version;
QMap<QString, QString> m_filesToCopy;
QList<BlockedMod> m_blockedMods;
// FIXME: nuke
QWidget* m_parent;
};
} // namespace ModpacksCH

View File

@ -0,0 +1,184 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2020 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright 2020-2021 Petr Mrazek <peterix@gmail.com>
*
* 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.safeName = Json::requireString(obj, "name").replace(QRegularExpression("[^A-Za-z0-9]"), "").toLower() + ".png";
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);
}
}

View File

@ -0,0 +1,157 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright 2020 Petr Mrazek <peterix@gmail.com>
*
* 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 <QJsonObject>
#include <QMetaType>
#include <QString>
#include <QUrl>
#include <QVector>
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> art;
QVector<Author> authors;
QVector<VersionInfo> versions;
QVector<Tag> tags;
QString safeName;
};
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<VersionTarget> targets;
QVector<VersionFile> files;
};
struct VersionChangelog {
QString content;
int64_t updated;
};
void loadModpack(Modpack& m, QJsonObject& obj);
void loadVersion(Version& m, QJsonObject& obj);
} // namespace ModpacksCH
Q_DECLARE_METATYPE(ModpacksCH::Modpack)

View File

@ -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"
@ -176,6 +177,7 @@ QList<BasePage*> 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));

View File

@ -0,0 +1,91 @@
/*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
*
* 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 <QDebug>
#include "modplatform/modpacksch/FTBPackManifest.h"
#include "StringUtils.h"
namespace Ftb {
FilterModel::FilterModel(QObject* parent) : QSortFilterProxyModel(parent)
{
m_currentSorting = Sorting::ByPlays;
m_sortings.insert(tr("Sort by Plays"), Sorting::ByPlays);
m_sortings.insert(tr("Sort by Installs"), Sorting::ByInstalls);
m_sortings.insert(tr("Sort by Name"), Sorting::ByName);
}
const QMap<QString, FilterModel::Sorting> FilterModel::getAvailableSortings()
{
return m_sortings;
}
QString FilterModel::translateCurrentSorting()
{
return m_sortings.key(m_currentSorting);
}
void FilterModel::setSorting(Sorting sorting)
{
m_currentSorting = sorting;
invalidate();
}
FilterModel::Sorting FilterModel::getCurrentSorting()
{
return m_currentSorting;
}
void FilterModel::setSearchTerm(const QString& term)
{
m_searchTerm = term.trimmed();
invalidate();
}
bool FilterModel::filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const
{
if (m_searchTerm.isEmpty()) {
return true;
}
auto index = sourceModel()->index(sourceRow, 0, sourceParent);
auto pack = sourceModel()->data(index, Qt::UserRole).value<ModpacksCH::Modpack>();
return pack.name.contains(m_searchTerm, Qt::CaseInsensitive);
}
bool FilterModel::lessThan(const QModelIndex& left, const QModelIndex& right) const
{
ModpacksCH::Modpack leftPack = sourceModel()->data(left, Qt::UserRole).value<ModpacksCH::Modpack>();
ModpacksCH::Modpack rightPack = sourceModel()->data(right, Qt::UserRole).value<ModpacksCH::Modpack>();
if (m_currentSorting == ByPlays) {
return leftPack.plays < rightPack.plays;
} else if (m_currentSorting == ByInstalls) {
return leftPack.installs < rightPack.installs;
} else if (m_currentSorting == ByName) {
return StringUtils::naturalCompare(leftPack.name, rightPack.name, Qt::CaseSensitive) >= 0;
}
// Invalid sorting set, somehow...
qWarning() << "Invalid sorting set!";
return true;
}
} // namespace Ftb

View File

@ -0,0 +1,49 @@
/*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
*
* 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 <QtCore/QSortFilterProxyModel>
namespace Ftb {
class FilterModel : public QSortFilterProxyModel {
Q_OBJECT
public:
FilterModel(QObject* parent = Q_NULLPTR);
enum Sorting {
ByPlays,
ByInstalls,
ByName,
};
const QMap<QString, Sorting> 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<QString, Sorting> m_sortings;
Sorting m_currentSorting;
QString m_searchTerm{ "" };
};
} // namespace Ftb

View File

@ -0,0 +1,251 @@
/*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
*
* 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 "Application.h"
#include "BuildConfig.h"
#include "Json.h"
#include <QPainter>
namespace Ftb {
ListModel::ListModel(QObject* parent) : QAbstractListModel(parent) {}
ListModel::~ListModel() {}
int ListModel::rowCount(const QModelIndex& parent) const
{
return parent.isValid() ? 0 : m_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 >= m_modpacks.size() || pos < 0 || !index.isValid()) {
return QString("INVALID INDEX %1").arg(pos);
}
ModpacksCH::Modpack pack = m_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.safeName);
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.safeName, 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))->getFullPath());
} else {
requestLogo(logo, logoUrl);
}
}
void ListModel::request()
{
m_aborted = false;
beginResetModel();
m_modpacks.clear();
endResetModel();
auto netJob = makeShared<NetJob>("Ftb::Request", APPLICATION->network());
auto url = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/all");
m_response.reset(new QByteArray());
netJob->addNetAction(Net::Download::makeByteArray(QUrl(url), m_response));
m_jobPtr = netJob;
m_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 = m_jobPtr->abort();
m_jobPtr.reset();
}
void ListModel::requestFinished()
{
m_jobPtr.reset();
m_remainingPacks.clear();
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;
}
auto packs = doc.object().value("packs").toArray();
for (auto pack : packs) {
auto packId = pack.toInt();
m_remainingPacks.append(packId);
}
if (!m_remainingPacks.isEmpty()) {
m_currentPack = m_remainingPacks.at(0);
requestPack();
}
}
void ListModel::requestFailed(QString)
{
m_jobPtr.reset();
m_remainingPacks.clear();
}
void ListModel::requestPack()
{
auto netJob = makeShared<NetJob>("Ftb::Search", APPLICATION->network());
auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1").arg(m_currentPack);
m_response.reset(new QByteArray());
netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), m_response));
m_jobPtr = netJob;
m_jobPtr->start();
QObject::connect(netJob.get(), &NetJob::succeeded, this, &ListModel::packRequestFinished);
QObject::connect(netJob.get(), &NetJob::failed, this, &ListModel::packRequestFailed);
}
void ListModel::packRequestFinished()
{
if (!m_jobPtr || m_aborted)
return;
m_jobPtr.reset();
m_remainingPacks.removeOne(m_currentPack);
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;
}
auto obj = doc.object();
ModpacksCH::Modpack pack;
try {
ModpacksCH::loadModpack(pack, obj);
} catch (const JSONValidationError& e) {
qDebug() << QString::fromUtf8(*m_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(), m_modpacks.size(), m_modpacks.size());
m_modpacks.append(pack);
endInsertRows();
}
if (!m_remainingPacks.isEmpty()) {
m_currentPack = m_remainingPacks.at(0);
requestPack();
}
}
void ListModel::packRequestFailed(QString)
{
m_jobPtr.reset();
m_remainingPacks.removeOne(m_currentPack);
}
void ListModel::logoLoaded(QString logo)
{
auto& logoObj = m_logoMap[logo];
logoObj.downloadJob.reset();
logoObj.result = QIcon(logoObj.fullpath);
for (int i = 0; i < m_modpacks.size(); i++) {
if (m_modpacks[i].safeName == 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));
auto job = makeShared<NetJob>(QString("ModpacksCH Icon Download %1").arg(logo), APPLICATION->network());
job->setAskRetry(false);
job->addNetAction(Net::Download::makeCached(QUrl(url), entry));
auto fullPath = entry->getFullPath();
QObject::connect(job.get(), &NetJob::finished, this, [this, logo, fullPath] { logoLoaded(logo); });
QObject::connect(job.get(), &NetJob::failed, this, [this, logo] { logoFailed(logo); });
auto& newLogoEntry = m_logoMap[logo];
newLogoEntry.downloadJob = job;
newLogoEntry.fullpath = fullPath;
job->start();
}
} // namespace Ftb

View File

@ -0,0 +1,82 @@
/*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
*
* 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 <QAbstractListModel>
#include <QIcon>
#include "modplatform/modpacksch/FTBPackManifest.h"
#include "net/NetJob.h"
namespace Ftb {
struct Logo {
QString fullpath;
NetJob::Ptr downloadJob;
QIcon result;
bool failed = false;
};
typedef QMap<QString, Logo> LogoMap;
typedef std::function<void(QString)> 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 m_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);
private:
void requestLogo(QString file, QString url);
private:
bool m_aborted = false;
QList<ModpacksCH::Modpack> m_modpacks;
LogoMap m_logoMap;
NetJob::Ptr m_jobPtr;
int m_currentPack;
QList<int> m_remainingPacks;
std::shared_ptr<QByteArray> m_response;
};
} // namespace Ftb

View File

@ -0,0 +1,187 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2020-2021 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright 2021 Philip T <me@phit.link>
*
* 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 <QKeyEvent>
#include "modplatform/modpacksch/FTBPackInstallTask.h"
#include "ui/dialogs/NewInstanceDialog.h"
#include "Markdown.h"
FtbPage::FtbPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget(parent), m_ui(new Ui::FtbPage), m_dialog(dialog)
{
m_ui->setupUi(this);
m_filterModel = new Ftb::FilterModel(this);
m_listModel = new Ftb::ListModel(this);
m_filterModel->setSourceModel(m_listModel);
m_ui->packView->setModel(m_filterModel);
m_ui->packView->setSortingEnabled(true);
m_ui->packView->header()->hide();
m_ui->packView->setIndentation(0);
m_ui->searchEdit->installEventFilter(this);
m_ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
for (int i = 0; i < m_filterModel->getAvailableSortings().size(); i++) {
m_ui->sortByBox->addItem(m_filterModel->getAvailableSortings().keys().at(i));
}
m_ui->sortByBox->setCurrentText(m_filterModel->translateCurrentSorting());
connect(m_ui->searchEdit, &QLineEdit::textChanged, this, &FtbPage::triggerSearch);
connect(m_ui->sortByBox, &QComboBox::currentTextChanged, this, &FtbPage::onSortingSelectionChanged);
connect(m_ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &FtbPage::onSelectionChanged);
connect(m_ui->versionSelectionBox, &QComboBox::currentTextChanged, this, &FtbPage::onVersionSelectionChanged);
m_ui->packDescription->setMetaEntry("FTBPacks");
}
FtbPage::~FtbPage()
{
delete m_ui;
}
bool FtbPage::eventFilter(QObject* watched, QEvent* event)
{
if (watched == m_ui->searchEdit && event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(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()
{
m_ui->retranslateUi(this);
}
void FtbPage::openedImpl()
{
if (!m_initialised || m_listModel->wasAborted()) {
m_listModel->request();
m_initialised = true;
}
suggestCurrent();
}
void FtbPage::closedImpl()
{
if (m_listModel->isMakingRequest())
m_listModel->abortRequest();
}
void FtbPage::suggestCurrent()
{
if (!isOpened) {
return;
}
if (m_selectedVersion.isEmpty()) {
m_dialog->setSuggestedPack();
return;
}
m_dialog->setSuggestedPack(m_selected.name, m_selectedVersion, new ModpacksCH::PackInstallTask(m_selected, m_selectedVersion, this));
for (auto art : m_selected.art) {
if (art.type == "square") {
auto editedLogoName = "ftb_" + m_selected.safeName;
m_listModel->getLogo(m_selected.safeName, art.url,
[this, editedLogoName](QString logo) { m_dialog->setSuggestedIconFromFile(logo, editedLogoName); });
}
}
}
void FtbPage::triggerSearch()
{
m_filterModel->setSearchTerm(m_ui->searchEdit->text());
}
void FtbPage::onSortingSelectionChanged(QString data)
{
auto toSet = m_filterModel->getAvailableSortings().value(data);
m_filterModel->setSorting(toSet);
}
void FtbPage::onSelectionChanged(QModelIndex first, QModelIndex second)
{
m_ui->versionSelectionBox->clear();
if (!first.isValid()) {
if (isOpened) {
m_dialog->setSuggestedPack();
}
return;
}
m_selected = m_filterModel->data(first, Qt::UserRole).value<ModpacksCH::Modpack>();
QString output = markdownToHTML(m_selected.description.toUtf8());
m_ui->packDescription->setHtml(output);
// reverse foreach, so that the newest versions are first
for (auto i = m_selected.versions.size(); i--;) {
m_ui->versionSelectionBox->addItem(m_selected.versions.at(i).name);
}
suggestCurrent();
}
void FtbPage::onVersionSelectionChanged(QString data)
{
if (data.isNull() || data.isEmpty()) {
m_selectedVersion = "";
return;
}
m_selectedVersion = data;
suggestCurrent();
}

View File

@ -0,0 +1,91 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* PolyMC - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2013-2021 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "FtbFilterModel.h"
#include "FtbListModel.h"
#include <QWidget>
#include "Application.h"
#include "tasks/Task.h"
#include "ui/pages/BasePage.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* m_ui = nullptr;
NewInstanceDialog* m_dialog = nullptr;
Ftb::ListModel* m_listModel = nullptr;
Ftb::FilterModel* m_filterModel = nullptr;
ModpacksCH::Modpack m_selected;
QString m_selectedVersion;
bool m_initialised{ false };
};

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FtbPage</class>
<widget class="QWidget" name="FtbPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>875</width>
<height>745</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_4" columnstretch="0,0,0" rowminimumheight="0" columnminimumwidth="0,0,0">
<item row="0" column="2">
<widget class="QComboBox" name="versionSelectionBox"/>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Version selected:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QComboBox" name="sortByBox"/>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="searchEdit">
<property name="placeholderText">
<string>Search and filter...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QTreeView" name="packView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="iconSize">
<size>
<width>48</width>
<height>48</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="ProjectDescriptionPage" name="packDescription">
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="openLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ProjectDescriptionPage</class>
<extends>QTextBrowser</extends>
<header>ui/widgets/ProjectDescriptionPage.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>searchEdit</tabstop>
<tabstop>versionSelectionBox</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>