diff --git a/buildconfig/BuildConfig.h b/buildconfig/BuildConfig.h index 4a3090736..a05d7a9eb 100644 --- a/buildconfig/BuildConfig.h +++ b/buildconfig/BuildConfig.h @@ -161,6 +161,8 @@ class Config { QString MODRINTH_STAGING_URL = "https://staging-api.modrinth.com/v2"; QString MODRINTH_PROD_URL = "https://api.modrinth.com/v2"; + QString FLAME_BASE_URL = "https://api.curseforge.com/v1"; + QString versionString() const; /** * \brief Converts the Version to a string. diff --git a/launcher/ui/pages/instance/ManagedPackPage.cpp b/launcher/ui/pages/instance/ManagedPackPage.cpp index 2f1e4ff05..45be7c715 100644 --- a/launcher/ui/pages/instance/ManagedPackPage.cpp +++ b/launcher/ui/pages/instance/ManagedPackPage.cpp @@ -269,7 +269,65 @@ FlameManagedPackPage::FlameManagedPackPage(BaseInstance* inst, InstanceWindow* i connect(ui->versionsComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(suggestVersion())); } -void FlameManagedPackPage::parseManagedPack() {} +void FlameManagedPackPage::parseManagedPack() { + qDebug() << "Parsing Flame pack"; + + auto netJob = new NetJob(QString("Flame::PackVersions(%1)").arg(m_inst->getManagedPackName()), APPLICATION->network()); + auto response = new QByteArray(); + + QString id = m_inst->getManagedPackID(); + + netJob->addNetAction(Net::Download::makeByteArray(QString("%1/mods/%2/files").arg(BuildConfig.FLAME_BASE_URL, id), response)); + + QObject::connect(netJob, &NetJob::succeeded, this, [this, response, id] { + QJsonParseError parse_error{}; + QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error); + if (parse_error.error != QJsonParseError::NoError) { + qWarning() << "Error while parsing JSON response from Flame at " << parse_error.offset + << " reason: " << parse_error.errorString(); + qWarning() << *response; + + setFailState(); + + return; + } + + try { + auto obj = doc.object(); + auto data = Json::ensureArray(obj, "data"); + Flame::loadIndexedPackVersions(m_pack, data); + } catch (const JSONValidationError& e) { + qDebug() << *response; + qWarning() << "Error while reading modrinth modpack version: " << e.cause(); + + setFailState(); + return; + } + + for (auto version : m_pack.versions) { + QString name; + + name = version.version; + + if (version.fileId == m_inst->getManagedPackVersionID().toInt()) + name.append(tr(" (Current)")); + + ui->versionsComboBox->addItem(name, QVariant(version.fileId)); + } + + suggestVersion(); + + m_loaded = true; + }); + QObject::connect(netJob, &NetJob::failed, this, &FlameManagedPackPage::setFailState); + QObject::connect(netJob, &NetJob::aborted, this, &FlameManagedPackPage::setFailState); + QObject::connect(netJob, &NetJob::finished, this, [response, netJob] { + netJob->deleteLater(); + delete response; + }); + + netJob->start(); +} QString FlameManagedPackPage::url() const { @@ -278,6 +336,12 @@ QString FlameManagedPackPage::url() const void FlameManagedPackPage::suggestVersion() { + auto index = ui->versionsComboBox->currentIndex(); + auto version = m_pack.versions.at(index); + + ui->changelogTextBrowser->setHtml(m_api.getModFileChangelog(m_inst->getManagedPackID().toInt(), version.fileId)); + + ManagedPackPage::suggestVersion(); } #include "ManagedPackPage.moc" diff --git a/launcher/ui/pages/instance/ManagedPackPage.h b/launcher/ui/pages/instance/ManagedPackPage.h index a81d24f02..6d4878204 100644 --- a/launcher/ui/pages/instance/ManagedPackPage.h +++ b/launcher/ui/pages/instance/ManagedPackPage.h @@ -5,6 +5,9 @@ #include "modplatform/modrinth/ModrinthAPI.h" #include "modplatform/modrinth/ModrinthPackManifest.h" +#include "modplatform/flame/FlameAPI.h" +#include "modplatform/flame/FlamePackIndex.h" + #include "ui/pages/BasePage.h" #include @@ -130,4 +133,8 @@ class FlameManagedPackPage final : public ManagedPackPage { public slots: void suggestVersion() override; + + private: + Flame::IndexedPack m_pack; + FlameAPI m_api; };