aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--launcher/CMakeLists.txt25
-rw-r--r--launcher/ModDownloadTask.cpp39
-rw-r--r--launcher/ModDownloadTask.h34
-rw-r--r--launcher/modplatform/flame/FlameModIndex.cpp100
-rw-r--r--launcher/modplatform/flame/FlameModIndex.h50
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackIndex.cpp93
-rw-r--r--launcher/modplatform/modrinth/ModrinthPackIndex.h48
-rw-r--r--launcher/resources/multimc/128x128/instances/modrinth.pngbin0 -> 10575 bytes
-rw-r--r--launcher/resources/multimc/32x32/instances/modrinth.pngbin0 -> 1913 bytes
-rw-r--r--launcher/resources/multimc/multimc.qrc3
-rw-r--r--launcher/ui/dialogs/ModDownloadDialog.cpp98
-rw-r--r--launcher/ui/dialogs/ModDownloadDialog.h54
-rw-r--r--launcher/ui/pages/instance/ModFolderPage.cpp40
-rw-r--r--launcher/ui/pages/instance/ModFolderPage.h1
-rw-r--r--launcher/ui/pages/instance/ModFolderPage.ui9
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModModel.cpp273
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModModel.h79
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModPage.cpp194
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModPage.h67
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModPage.ui90
-rw-r--r--launcher/ui/pages/modplatform/flame/FlameModel.cpp11
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp268
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.h79
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp179
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.h67
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.ui90
26 files changed, 1985 insertions, 6 deletions
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 0ef27f6b..8d8b4d02 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -37,6 +37,10 @@ set(CORE_SOURCES
InstanceImportTask.h
InstanceImportTask.cpp
+ # Mod downloading task
+ ModDownloadTask.h
+ ModDownloadTask.cpp
+
# Use tracking separate from memory management
Usable.h
@@ -497,12 +501,19 @@ set(FLAME_SOURCES
# Flame
modplatform/flame/FlamePackIndex.cpp
modplatform/flame/FlamePackIndex.h
+ modplatform/flame/FlameModIndex.cpp
+ modplatform/flame/FlameModIndex.h
modplatform/flame/PackManifest.h
modplatform/flame/PackManifest.cpp
modplatform/flame/FileResolvingTask.h
modplatform/flame/FileResolvingTask.cpp
)
+set(MODRINTH_SOURCES
+ modplatform/modrinth/ModrinthPackIndex.cpp
+ modplatform/modrinth/ModrinthPackIndex.h
+)
+
set(MODPACKSCH_SOURCES
modplatform/modpacksch/FTBPackInstallTask.h
modplatform/modpacksch/FTBPackInstallTask.cpp
@@ -557,6 +568,7 @@ set(LOGIC_SOURCES
${ICONS_SOURCES}
${FTB_SOURCES}
${FLAME_SOURCES}
+ ${MODRINTH_SOURCES}
${MODPACKSCH_SOURCES}
${TECHNIC_SOURCES}
${ATLAUNCHER_SOURCES}
@@ -730,6 +742,10 @@ SET(LAUNCHER_SOURCES
ui/pages/modplatform/flame/FlameModel.h
ui/pages/modplatform/flame/FlamePage.cpp
ui/pages/modplatform/flame/FlamePage.h
+ ui/pages/modplatform/flame/FlameModModel.cpp
+ ui/pages/modplatform/flame/FlameModModel.h
+ ui/pages/modplatform/flame/FlameModPage.cpp
+ ui/pages/modplatform/flame/FlameModPage.h
ui/pages/modplatform/technic/TechnicModel.cpp
ui/pages/modplatform/technic/TechnicModel.h
@@ -739,6 +755,11 @@ SET(LAUNCHER_SOURCES
ui/pages/modplatform/ImportPage.cpp
ui/pages/modplatform/ImportPage.h
+ ui/pages/modplatform/modrinth/ModrinthModel.cpp
+ ui/pages/modplatform/modrinth/ModrinthModel.h
+ ui/pages/modplatform/modrinth/ModrinthPage.cpp
+ ui/pages/modplatform/modrinth/ModrinthPage.h
+
# GUI - dialogs
ui/dialogs/AboutDialog.cpp
ui/dialogs/AboutDialog.h
@@ -776,6 +797,8 @@ SET(LAUNCHER_SOURCES
ui/dialogs/VersionSelectDialog.h
ui/dialogs/SkinUploadDialog.cpp
ui/dialogs/SkinUploadDialog.h
+ ui/dialogs/ModDownloadDialog.cpp
+ ui/dialogs/ModDownloadDialog.h
# GUI - widgets
@@ -852,10 +875,12 @@ qt5_wrap_ui(LAUNCHER_UI
ui/pages/modplatform/atlauncher/AtlPage.ui
ui/pages/modplatform/VanillaPage.ui
ui/pages/modplatform/flame/FlamePage.ui
+ ui/pages/modplatform/flame/FlameModPage.ui
ui/pages/modplatform/legacy_ftb/Page.ui
ui/pages/modplatform/ImportPage.ui
ui/pages/modplatform/ftb/FtbPage.ui
ui/pages/modplatform/technic/TechnicPage.ui
+ ui/pages/modplatform/modrinth/ModrinthPage.ui
ui/widgets/InstanceCardWidget.ui
ui/widgets/CustomCommands.ui
ui/widgets/MCModInfoFrame.ui
diff --git a/launcher/ModDownloadTask.cpp b/launcher/ModDownloadTask.cpp
new file mode 100644
index 00000000..08a02d29
--- /dev/null
+++ b/launcher/ModDownloadTask.cpp
@@ -0,0 +1,39 @@
+#include "ModDownloadTask.h"
+#include "Application.h"
+
+ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, const std::shared_ptr<ModFolderModel> mods)
+: m_sourceUrl(sourceUrl), mods(mods), filename(filename) {
+}
+
+void ModDownloadTask::executeTask() {
+ setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString()));
+
+ m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
+ m_filesNetJob->addNetAction(Net::Download::makeFile(m_sourceUrl, mods->dir().absoluteFilePath(filename)));
+ connect(m_filesNetJob.get(), &NetJob::succeeded, this, &ModDownloadTask::downloadSucceeded);
+ connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged);
+ connect(m_filesNetJob.get(), &NetJob::failed, this, &ModDownloadTask::downloadFailed);
+ m_filesNetJob->start();
+}
+
+void ModDownloadTask::downloadSucceeded()
+{
+ emitSucceeded();
+ m_filesNetJob.reset();
+}
+
+void ModDownloadTask::downloadFailed(QString reason)
+{
+ emitFailed(reason);
+ m_filesNetJob.reset();
+}
+
+void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total)
+{
+ emit progress(current, total);
+}
+
+bool ModDownloadTask::abort() {
+ return m_filesNetJob->abort();
+}
+
diff --git a/launcher/ModDownloadTask.h b/launcher/ModDownloadTask.h
new file mode 100644
index 00000000..7e4f1b7d
--- /dev/null
+++ b/launcher/ModDownloadTask.h
@@ -0,0 +1,34 @@
+#pragma once
+#include "QObjectPtr.h"
+#include "tasks/Task.h"
+#include "minecraft/mod/ModFolderModel.h"
+#include "net/NetJob.h"
+#include <QUrl>
+
+
+class ModDownloadTask : public Task {
+ Q_OBJECT
+public:
+ explicit ModDownloadTask(const QUrl sourceUrl, const QString filename, const std::shared_ptr<ModFolderModel> mods);
+
+public slots:
+ bool abort() override;
+protected:
+ //! Entry point for tasks.
+ void executeTask() override;
+
+private:
+ QUrl m_sourceUrl;
+ NetJob::Ptr m_filesNetJob;
+ const std::shared_ptr<ModFolderModel> mods;
+ const QString filename;
+
+ void downloadProgressChanged(qint64 current, qint64 total);
+
+ void downloadFailed(QString reason);
+
+ void downloadSucceeded();
+};
+
+
+
diff --git a/launcher/modplatform/flame/FlameModIndex.cpp b/launcher/modplatform/flame/FlameModIndex.cpp
new file mode 100644
index 00000000..ca8f7fd7
--- /dev/null
+++ b/launcher/modplatform/flame/FlameModIndex.cpp
@@ -0,0 +1,100 @@
+#include <QObject>
+#include "FlameModIndex.h"
+#include "Json.h"
+#include "net/NetJob.h"
+#include "BaseInstance.h"
+#include "minecraft/MinecraftInstance.h"
+#include "minecraft/PackProfile.h"
+
+
+void FlameMod::loadIndexedPack(FlameMod::IndexedPack & pack, QJsonObject & obj)
+{
+ pack.addonId = Json::requireInteger(obj, "id");
+ pack.name = Json::requireString(obj, "name");
+ pack.websiteUrl = Json::ensureString(obj, "websiteUrl", "");
+ pack.description = Json::ensureString(obj, "summary", "");
+
+ bool thumbnailFound = false;
+ auto attachments = Json::requireArray(obj, "attachments");
+ for(auto attachmentRaw: attachments) {
+ auto attachmentObj = Json::requireObject(attachmentRaw);
+ bool isDefault = attachmentObj.value("isDefault").toBool(false);
+ if(isDefault) {
+ thumbnailFound = true;
+ pack.logoName = Json::requireString(attachmentObj, "title");
+ pack.logoUrl = Json::requireString(attachmentObj, "thumbnailUrl");
+ break;
+ }
+ }
+
+ if(!thumbnailFound) {
+ throw JSONValidationError(QString("Pack without an icon, skipping: %1").arg(pack.name));
+ }
+
+
+ auto authors = Json::requireArray(obj, "authors");
+ for(auto authorIter: authors) {
+ auto author = Json::requireObject(authorIter);
+ FlameMod::ModpackAuthor packAuthor;
+ packAuthor.name = Json::requireString(author, "name");
+ packAuthor.url = Json::requireString(author, "url");
+ pack.authors.append(packAuthor);
+ }
+}
+
+void FlameMod::loadIndexedPackVersions(FlameMod::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network, BaseInstance * inst)
+{
+ QVector<FlameMod::IndexedVersion> unsortedVersions;
+ bool hasFabric = !((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
+ QString mcVersion = ((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.minecraft");
+
+ for(auto versionIter: arr) {
+ auto obj = versionIter.toObject();
+ FlameMod::IndexedVersion file;
+ file.addonId = pack.addonId;
+ file.fileId = Json::requireInteger(obj, "id");
+ file.date = Json::requireString(obj, "fileDate");
+ auto versionArray = Json::requireArray(obj, "gameVersion");
+ if (versionArray.empty()) {
+ continue;
+ }
+ for(auto mcVer : versionArray){
+ file.mcVersion.append(mcVer.toString());
+ }
+
+ file.version = Json::requireString(obj, "displayName");
+ file.downloadUrl = Json::requireString(obj, "downloadUrl");
+ file.fileName = Json::requireString(obj, "fileName");
+
+ auto modules = Json::requireArray(obj, "modules");
+ bool valid = false;
+ for(auto m : modules){
+ auto fname = Json::requireString(m.toObject(),"foldername");
+ if(hasFabric){
+ if(fname == "fabric.mod.json"){
+ valid = true;
+ break;
+ }
+ }else{
+ //this cannot check for the recent mcmod.toml formats
+ if(fname == "mcmod.info"){
+ valid = true;
+ break;
+ }
+ }
+ }
+ if(!valid || !hasFabric){
+ continue;
+ }
+
+ unsortedVersions.append(file);
+ }
+ auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
+ {
+ //dates are in RFC 3339 format
+ return a.date > b.date;
+ };
+ std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
+ pack.versions = unsortedVersions;
+ pack.versionsLoaded = true;
+} \ No newline at end of file
diff --git a/launcher/modplatform/flame/FlameModIndex.h b/launcher/modplatform/flame/FlameModIndex.h
new file mode 100644
index 00000000..0293bb23
--- /dev/null
+++ b/launcher/modplatform/flame/FlameModIndex.h
@@ -0,0 +1,50 @@
+//
+// Created by timoreo on 16/01/2022.
+//
+
+#pragma once
+#include <QList>
+#include <QMetaType>
+#include <QString>
+#include <QVector>
+#include <QNetworkAccessManager>
+#include <QObjectPtr.h>
+#include "net/NetJob.h"
+#include "BaseInstance.h"
+
+namespace FlameMod {
+ struct ModpackAuthor {
+ QString name;
+ QString url;
+ };
+
+ struct IndexedVersion {
+ int addonId;
+ int fileId;
+ QString version;
+ QVector<QString> mcVersion;
+ QString downloadUrl;
+ QString date;
+ QString fileName;
+ };
+
+ struct IndexedPack
+ {
+ int addonId;
+ QString name;
+ QString description;
+ QList<ModpackAuthor> authors;
+ QString logoName;
+ QString logoUrl;
+ QString websiteUrl;
+
+ bool versionsLoaded = false;
+ QVector<IndexedVersion> versions;
+ };
+
+ void loadIndexedPack(IndexedPack & m, QJsonObject & obj);
+ void loadIndexedPackVersions(IndexedPack &pack, QJsonArray &arr, const shared_qobject_ptr<QNetworkAccessManager> &network, BaseInstance *inst);
+
+}
+
+Q_DECLARE_METATYPE(FlameMod::IndexedPack)
diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.cpp b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
new file mode 100644
index 00000000..a546eb7c
--- /dev/null
+++ b/launcher/modplatform/modrinth/ModrinthPackIndex.cpp
@@ -0,0 +1,93 @@
+#include <QObject>
+#include "ModrinthPackIndex.h"
+
+#include "Json.h"
+#include "net/NetJob.h"
+#include "BaseInstance.h"
+#include "minecraft/MinecraftInstance.h"
+#include "minecraft/PackProfile.h"
+
+
+void Modrinth::loadIndexedPack(Modrinth::IndexedPack & pack, QJsonObject & obj)
+{
+ pack.addonId = Json::requireString(obj, "mod_id");
+ pack.name = Json::requireString(obj, "title");
+ pack.websiteUrl = Json::ensureString(obj, "page_url", "");
+ pack.description = Json::ensureString(obj, "description", "");
+
+ pack.logoUrl = Json::requireString(obj, "icon_url");
+ pack.logoName = pack.addonId;
+
+ Modrinth::ModpackAuthor modAuthor;
+ modAuthor.name = Json::requireString(obj, "author");
+ modAuthor.url = Json::requireString(obj, "author_url");
+ pack.author = modAuthor;
+}
+
+void Modrinth::loadIndexedPackVersions(Modrinth::IndexedPack & pack, QJsonArray & arr, const shared_qobject_ptr<QNetworkAccessManager>& network, BaseInstance * inst)
+{
+ QVector<Modrinth::IndexedVersion> unsortedVersions;
+ bool hasFabric = !((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
+ QString mcVersion = ((MinecraftInstance *)inst)->getPackProfile()->getComponentVersion("net.minecraft");
+
+ for(auto versionIter: arr) {
+ auto obj = versionIter.toObject();
+ Modrinth::IndexedVersion file;
+ file.addonId = Json::requireString(obj,"mod_id") ;
+ file.fileId = Json::requireString(obj, "id");
+ file.date = Json::requireString(obj, "date_published");
+ auto versionArray = Json::requireArray(obj, "game_versions");
+ if (versionArray.empty()) {
+ continue;
+ }
+ for(auto mcVer : versionArray){
+ file.mcVersion.append(mcVer.toString());
+ }
+ auto loaders = Json::requireArray(obj,"loaders");
+ for(auto loader : loaders){
+ file.loaders.append(loader.toString());
+ }
+ file.version = Json::requireString(obj, "name");
+
+ auto files = Json::requireArray(obj, "files");
+ int i = 0;
+ while (files.count() > 1 && i < files.count()){
+ //try to resolve the correct file
+ auto parent = files[i].toObject();
+ auto fileName = Json::requireString(parent, "filename");
+ //avoid grabbing "dev" files
+ if(fileName.contains("javadocs",Qt::CaseInsensitive) || fileName.contains("sources",Qt::CaseInsensitive)){
+ i++;
+ continue;
+ }
+ //grab the correct mod loader
+ if(fileName.contains("forge",Qt::CaseInsensitive) || fileName.contains("fabric",Qt::CaseInsensitive) ){
+ if(hasFabric){
+ if(fileName.contains("forge",Qt::CaseInsensitive)){
+ i++;
+ continue;
+ }
+ }else{
+ if(fileName.contains("fabric",Qt::CaseInsensitive)){
+ i++;
+ continue;
+ }
+ }
+ }
+ break;
+ }
+ auto parent = files[i].toObject();
+ file.downloadUrl = Json::requireString(parent, "url");
+ file.fileName = Json::requireString(parent, "filename");
+
+ unsortedVersions.append(file);
+ }
+ auto orderSortPredicate = [](const IndexedVersion & a, const IndexedVersion & b) -> bool
+ {
+ //dates are in RFC 3339 format
+ return a.date > b.date;
+ };
+ std::sort(unsortedVersions.begin(), unsortedVersions.end(), orderSortPredicate);
+ pack.versions = unsortedVersions;
+ pack.versionsLoaded = true;
+}
diff --git a/launcher/modplatform/modrinth/ModrinthPackIndex.h b/launcher/modplatform/modrinth/ModrinthPackIndex.h
new file mode 100644
index 00000000..3a4cd270
--- /dev/null
+++ b/launcher/modplatform/modrinth/ModrinthPackIndex.h
@@ -0,0 +1,48 @@
+#pragma once
+
+#include <QList>
+#include <QMetaType>
+#include <QString>
+#include <QVector>
+#include <QNetworkAccessManager>
+#include <QObjectPtr.h>
+#include "net/NetJob.h"
+#include "BaseInstance.h"
+
+namespace Modrinth {
+
+struct ModpackAuthor {
+ QString name;
+ QString url;
+};
+
+struct IndexedVersion {
+ QString addonId;
+ QString fileId;
+ QString version;
+ QVector<QString> mcVersion;
+ QString downloadUrl;
+ QString date;
+ QString fileName;
+ QVector<QString> loaders;
+};
+
+struct IndexedPack
+{
+ QString addonId;
+ QString name;
+ QString description;
+ ModpackAuthor author;
+ QString logoName;
+ QString logoUrl;
+ QString websiteUrl;
+
+ bool versionsLoaded = false;
+ QVector<IndexedVersion> versions;
+};
+
+void loadIndexedPack(IndexedPack & m, QJsonObject & obj);
+void loadIndexedPackVersions(IndexedPack &pack, QJsonArray &arr, const shared_qobject_ptr<QNetworkAccessManager> &network, BaseInstance *inst);
+}
+
+Q_DECLARE_METATYPE(Modrinth::IndexedPack)
diff --git a/launcher/resources/multimc/128x128/instances/modrinth.png b/launcher/resources/multimc/128x128/instances/modrinth.png
new file mode 100644
index 00000000..740bc8f0
--- /dev/null
+++ b/launcher/resources/multimc/128x128/instances/modrinth.png
Binary files differ
diff --git a/launcher/resources/multimc/32x32/instances/modrinth.png b/launcher/resources/multimc/32x32/instances/modrinth.png
new file mode 100644
index 00000000..025ed065
--- /dev/null
+++ b/launcher/resources/multimc/32x32/instances/modrinth.png
Binary files differ
diff --git a/launcher/resources/multimc/multimc.qrc b/launcher/resources/multimc/multimc.qrc
index 58b1d763..ef29cf9b 100644
--- a/launcher/resources/multimc/multimc.qrc
+++ b/launcher/resources/multimc/multimc.qrc
@@ -268,6 +268,9 @@
<file>32x32/instances/flame.png</file>
<file>128x128/instances/flame.png</file>
+ <file>32x32/instances/modrinth.png</file>
+ <file>128x128/instances/modrinth.png</file>
+
<file>32x32/instances/gear.png</file>
<file>128x128/instances/gear.png</file>
diff --git a/launcher/ui/dialogs/ModDownloadDialog.cpp b/launcher/ui/dialogs/ModDownloadDialog.cpp
new file mode 100644
index 00000000..6b807b8c
--- /dev/null
+++ b/launcher/ui/dialogs/ModDownloadDialog.cpp
@@ -0,0 +1,98 @@
+#include "ModDownloadDialog.h"
+
+#include <BaseVersion.h>
+#include <icons/IconList.h>
+#include <InstanceList.h>
+
+#include "ProgressDialog.h"
+
+#include <QLayout>
+#include <QPushButton>
+#include <QValidator>
+#include <QDialogButtonBox>
+
+#include "ui/widgets/PageContainer.h"
+#include "ui/pages/modplatform/modrinth/ModrinthPage.h"
+#include "ModDownloadTask.h"
+
+
+ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods, QWidget *parent,
+ BaseInstance *instance)
+ : QDialog(parent), mods(mods), m_instance(instance)
+{
+ setObjectName(QStringLiteral("ModDownloadDialog"));
+ resize(400, 347);
+ m_verticalLayout = new QVBoxLayout(this);
+ m_verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
+
+ setWindowIcon(APPLICATION->getThemedIcon("new"));
+ // NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below.
+ m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+
+ m_container = new PageContainer(this);
+ m_container->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding);
+ m_container->layout()->setContentsMargins(0, 0, 0, 0);
+ m_verticalLayout->addWidget(m_container);
+
+ m_container->addButtons(m_buttons);
+
+ // Bonk Qt over its stupid head and make sure it understands which button is the default one...
+ // See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
+ auto OkButton = m_buttons->button(QDialogButtonBox::Ok);
+ OkButton->setDefault(true);
+ OkButton->setAutoDefault(true);
+ connect(OkButton, &QPushButton::clicked, this, &ModDownloadDialog::accept);
+
+ auto CancelButton = m_buttons->button(QDialogButtonBox::Cancel);
+ CancelButton->setDefault(false);
+ CancelButton->setAutoDefault(false);
+ connect(CancelButton, &QPushButton::clicked, this, &ModDownloadDialog::reject);
+
+ auto HelpButton = m_buttons->button(QDialogButtonBox::Help);
+ HelpButton->setDefault(false);
+ HelpButton->setAutoDefault(false);
+ connect(HelpButton, &QPushButton::clicked, m_container, &PageContainer::help);
+ QMetaObject::connectSlotsByName(this);
+ setWindowModality(Qt::WindowModal);
+ setWindowTitle("Download mods");
+}
+
+QString ModDownloadDialog::dialogTitle()
+{
+ return tr("Download mods");
+}
+
+void ModDownloadDialog::reject()
+{
+ QDialog::reject();
+}
+
+void ModDownloadDialog::accept()
+{
+ QDialog::accept();
+}
+
+QList<BasePage *> ModDownloadDialog::getPages()
+{
+ modrinthPage = new ModrinthPage(this, m_instance);
+ flameModPage = new FlameModPage(this, m_instance);
+ return
+ {
+ modrinthPage,
+ flameModPage
+ };
+}
+
+void ModDownloadDialog::setSuggestedMod(const QString& name, ModDownloadTask* task)
+{
+ modTask.reset(task);
+ m_buttons->button(QDialogButtonBox::Ok)->setEnabled(task);
+}
+
+ModDownloadDialog::~ModDownloadDialog()
+{
+}
+
+ModDownloadTask *ModDownloadDialog::getTask() {
+ return modTask.release();
+}
diff --git a/launcher/ui/dialogs/ModDownloadDialog.h b/launcher/ui/dialogs/ModDownloadDialog.h
new file mode 100644
index 00000000..ece8e328
--- /dev/null
+++ b/launcher/ui/dialogs/ModDownloadDialog.h
@@ -0,0 +1,54 @@
+#pragma once
+
+#include <QDialog>
+#include <QVBoxLayout>
+
+#include "BaseVersion.h"
+#include "ui/pages/BasePageProvider.h"
+#include "minecraft/mod/ModFolderModel.h"
+#include "ModDownloadTask.h"
+#include "ui/pages/modplatform/flame/FlameModPage.h"
+
+namespace Ui
+{
+class ModDownloadDialog;
+}
+
+class PageContainer;
+class QDialogButtonBox;
+class ModrinthPage;
+
+class ModDownloadDialog : public QDialog, public BasePageProvider
+{
+ Q_OBJECT
+
+public:
+ explicit ModDownloadDialog(const std::shared_ptr<ModFolderModel> &mods, QWidget *parent, BaseInstance *instance);
+ ~ModDownloadDialog();
+
+ QString dialogTitle() override;
+ QList<BasePage *> getPages() override;
+
+ void setSuggestedMod(const QString & name = QString(), ModDownloadTask * task = nullptr);
+
+ ModDownloadTask * getTask();
+ const std::shared_ptr<ModFolderModel> &mods;
+
+public slots:
+ void accept() override;
+ void reject() override;
+
+//private slots:
+
+private:
+ Ui::ModDownloadDialog *ui = nullptr;
+ PageContainer * m_container = nullptr;
+ QDialogButtonBox * m_buttons = nullptr;
+ QVBoxLayout *m_verticalLayout = nullptr;
+
+
+ ModrinthPage *modrinthPage = nullptr;
+ FlameModPage *flameModPage = nullptr;
+ std::unique_ptr<ModDownloadTask> modTask;
+ BaseInstance *m_instance;
+};
diff --git a/launcher/ui/pages/instance/ModFolderPage.cpp b/launcher/ui/pages/instance/ModFolderPage.cpp
index e63b1434..09b199fb 100644
--- a/launcher/ui/pages/instance/ModFolderPage.cpp
+++ b/launcher/ui/pages/instance/ModFolderPage.cpp
@@ -26,6 +26,7 @@
#include "Application.h"
#include "ui/dialogs/CustomMessageBox.h"
+#include "ui/dialogs/ModDownloadDialog.h"
#include "ui/GuiUtil.h"
#include "DesktopServices.h"
@@ -36,6 +37,7 @@
#include "minecraft/PackProfile.h"
#include "Version.h"
+#include "ui/dialogs/ProgressDialog.h"
namespace {
// FIXME: wasteful
@@ -342,6 +344,44 @@ void ModFolderPage::on_actionRemove_triggered()
m_mods->deleteMods(selection.indexes());
}
+void ModFolderPage::on_actionInstall_mods_triggered()
+{
+ if(!m_controlsEnabled) {
+ return;
+ }
+ if(m_inst->typeName() != "Minecraft"){
+ return; //this is a null instance or a legacy instance
+ }
+ bool hasFabric = !((MinecraftInstance *)m_inst)->getPackProfile()->getComponentVersion("net.fabricmc.fabric-loader").isEmpty();
+ bool hasForge = !((MinecraftInstance *)m_inst)->getPackProfile()->getComponentVersion("net.minecraftforge").isEmpty();
+ if (!hasFabric && !hasForge) {
+ QMessageBox::critical(this,tr("Error"),tr("Please install a mod loader first!"));
+ return;
+ }
+ ModDownloadDialog mdownload(m_mods, this, m_inst);
+ if(mdownload.exec()) {
+ ModDownloadTask *task = mdownload.getTask();
+ if (task) {
+ connect(task, &Task::failed, [this, task](QString reason) {
+ task->deleteLater();
+ CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
+ });
+ connect(task, &Task::succeeded, [this, task]() {
+ QStringList warnings = task->warnings();
+ if (warnings.count()) {
+ CustomMessageBox::selectable(this, tr("Warnings"), warnings.join('\n'),
+ QMessageBox::Warning)->show();
+ }
+ task->deleteLater();
+ });
+ ProgressDialog loadDialog(this);
+ loadDialog.setSkipButton(true, tr("Abort"));
+ loadDialog.execWithTask(task);
+ m_mods->update();
+ }
+ }
+}
+
void ModFolderPage::on_actionView_configs_triggered()
{
DesktopServices::openDirectory(m_inst->instanceConfigFolder(), true);
diff --git a/launcher/ui/pages/instance/ModFolderPage.h b/launcher/ui/pages/instance/ModFolderPage.h
index 8ef7559b..fbda3cd8 100644
--- a/launcher/ui/pages/instance/ModFolderPage.h
+++ b/launcher/ui/pages/instance/ModFolderPage.h
@@ -102,6 +102,7 @@ slots:
void on_actionRemove_triggered();
void on_actionEnable_triggered();
void on_actionDisable_triggered();
+ void on_actionInstall_mods_triggered();
void on_actionView_Folder_triggered();
void on_actionView_configs_triggered();
void ShowContextMenu(const QPoint &pos);
diff --git a/launcher/ui/pages/instance/ModFolderPage.ui b/launcher/ui/pages/instance/ModFolderPage.ui
index 0fb51e84..b5b4c9b2 100644
--- a/launcher/ui/pages/instance/ModFolderPage.ui
+++ b/launcher/ui/pages/instance/ModFolderPage.ui
@@ -88,6 +88,7 @@
<addaction name="actionRemove"/>
<addaction name="actionEnable"/>
<addaction name="actionDisable"/>
+ <addaction name="actionInstall_mods"/>
<addaction name="actionView_configs"/>
<addaction name="actionView_Folder"/>
</widget>
@@ -136,6 +137,14 @@
<string>View &amp;Folder</string>
</property>
</action>
+ <action name="actionInstall_mods">
+ <property name="text">
+ <string>Install mods</string>
+ </property>
+ <property name="toolTip">
+ <string>Install mods from Modrinth or Curseforge</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/launcher/ui/pages/modplatform/flame/FlameModModel.cpp b/launcher/ui/pages/modplatform/flame/FlameModModel.cpp
new file mode 100644
index 00000000..2cf83261
--- /dev/null
+++ b/launcher/ui/pages/modplatform/flame/FlameModModel.cpp
@@ -0,0 +1,273 @@
+#include "FlameModModel.h"
+#include "Application.h"
+#include "minecraft/MinecraftInstance.h"
+#include "minecraft/PackProfile.h"
+#include "FlameModPage.h"
+#include <Json.h>
+
+#include <MMCStrings.h>
+#include <Version.h>
+
+#include <QtMath>
+
+
+namespace FlameMod {
+
+ListModel::ListModel(FlameModPage *parent) : QAbstractListModel(parent)
+{
+}
+
+ListModel::~ListModel()
+{
+}
+
+int ListModel::rowCount(const QModelIndex &parent) const
+{
+ return modpacks.size();
+}
+
+int ListModel::columnCount(const QModelIndex &parent) const
+{
+ return 1;
+}
+
+QVariant ListModel::data(const QModelIndex &index, int role) const
+{
+ int pos = index.row();
+ if(pos >= modpacks.size() || pos < 0 || !index.isValid())
+