From f7acde438983a6ff61909b4a33433f2a6c154b02 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Mon, 2 May 2022 15:24:44 +0100 Subject: [PATCH] NOISSUE Support installing CurseForge packs on modpacks.ch There should be all the needed changes to install CurseForge modpacks through modpacks.ch in place now. Now the effort will need to move towards getting the GUI aspects to play nice. --- launcher/CMakeLists.txt | 2 ++ .../modpacksch/FTBPackInstallTask.cpp | 11 ++++--- .../modpacksch/FTBPackInstallTask.h | 5 ++- .../modplatform/modpacksch/MCHPackType.cpp | 33 +++++++++++++++++++ launcher/modplatform/modpacksch/MCHPackType.h | 30 +++++++++++++++++ 5 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 launcher/modplatform/modpacksch/MCHPackType.cpp create mode 100644 launcher/modplatform/modpacksch/MCHPackType.h diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index bd1521d6..fa8234ff 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -519,6 +519,8 @@ set(MODPACKSCH_SOURCES modplatform/modpacksch/FTBPackInstallTask.cpp modplatform/modpacksch/FTBPackManifest.h modplatform/modpacksch/FTBPackManifest.cpp + modplatform/modpacksch/MCHPackType.h + modplatform/modpacksch/MCHPackType.cpp ) set(TECHNIC_SOURCES diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp index 3c9c8d58..750634c5 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp @@ -30,10 +30,11 @@ namespace ModpacksCH { -PackInstallTask::PackInstallTask(Modpack pack, QString version) +PackInstallTask::PackInstallTask(Modpack pack, QString version, PackType type) { m_pack = pack; m_version_name = version; + m_pack_type = type; } bool PackInstallTask::abort() @@ -65,7 +66,10 @@ void PackInstallTask::executeTask() } auto *netJob = new NetJob("ModpacksCH::VersionFetch", APPLICATION->network()); - auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/modpack/%1/%2").arg(m_pack.id).arg(version.id); + auto searchUrl = QString(BuildConfig.MODPACKSCH_API_BASE_URL + "public/%1/%2/%3") + .arg(getRealmForPackType(m_pack_type)) + .arg(m_pack.id) + .arg(version.id); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchUrl), &response)); jobPtr = netJob; jobPtr->start(); @@ -78,14 +82,13 @@ void PackInstallTask::onDownloadSucceeded() { jobPtr.reset(); - QJsonParseError parse_error; + QJsonParseError parse_error {}; QJsonDocument doc = QJsonDocument::fromJson(response, &parse_error); if(parse_error.error != QJsonParseError::NoError) { qWarning() << "Error while parsing JSON response from FTB at " << parse_error.offset << " reason: " << parse_error.errorString(); qWarning() << response; return; } - auto obj = doc.object(); ModpacksCH::Version version; diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h index d85e7091..5bce16fb 100644 --- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h +++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h @@ -18,6 +18,7 @@ #pragma once #include "FTBPackManifest.h" +#include "MCHPackType.h" #include "InstanceTask.h" #include "net/NetJob.h" @@ -29,7 +30,7 @@ class PackInstallTask : public InstanceTask Q_OBJECT public: - explicit PackInstallTask(Modpack pack, QString version); + explicit PackInstallTask(Modpack pack, QString version, PackType type = PackType::ModpacksCH); virtual ~PackInstallTask(){} bool canAbort() const override { return true; } @@ -56,6 +57,8 @@ private: QString m_version_name; Version m_version; + PackType m_pack_type; + QMap filesToExtract; QMap filesToCopy; diff --git a/launcher/modplatform/modpacksch/MCHPackType.cpp b/launcher/modplatform/modpacksch/MCHPackType.cpp new file mode 100644 index 00000000..a03f4bf3 --- /dev/null +++ b/launcher/modplatform/modpacksch/MCHPackType.cpp @@ -0,0 +1,33 @@ +/* + * Copyright 2022 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 "MCHPackType.h" + +#include + +namespace ModpacksCH { + +QString getRealmForPackType(PackType type) +{ + switch (type) { + case PackType::ModpacksCH: + return "modpack"; + case PackType::CurseForge: + return "curseforge"; + } +} + +} diff --git a/launcher/modplatform/modpacksch/MCHPackType.h b/launcher/modplatform/modpacksch/MCHPackType.h new file mode 100644 index 00000000..cb7b2554 --- /dev/null +++ b/launcher/modplatform/modpacksch/MCHPackType.h @@ -0,0 +1,30 @@ +/* + * Copyright 2022 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 ModpacksCH { + +enum class PackType { + ModpacksCH, + CurseForge, +}; + +QString getRealmForPackType(PackType type); + +}