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.
This commit is contained in:
Jamie Mansfield 2022-05-02 15:24:44 +01:00 committed by Petr Mrázek
parent 8c1d95b484
commit f7acde4389
5 changed files with 76 additions and 5 deletions

View File

@ -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

View File

@ -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;

View File

@ -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<QString, VersionFile> filesToExtract;
QMap<QString, QString> filesToCopy;

View File

@ -0,0 +1,33 @@
/*
* Copyright 2022 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 "MCHPackType.h"
#include <QString>
namespace ModpacksCH {
QString getRealmForPackType(PackType type)
{
switch (type) {
case PackType::ModpacksCH:
return "modpack";
case PackType::CurseForge:
return "curseforge";
}
}
}

View File

@ -0,0 +1,30 @@
/*
* Copyright 2022 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 <QString>
namespace ModpacksCH {
enum class PackType {
ModpacksCH,
CurseForge,
};
QString getRealmForPackType(PackType type);
}