feat: implement mod resolving for FTB

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-06-02 21:23:20 +02:00
parent 86573a5ccd
commit 75a7ea55d4
No known key found for this signature in database
GPG Key ID: C10411294912A422
5 changed files with 113 additions and 7 deletions

View File

@ -40,24 +40,31 @@
#include "Json.h" #include "Json.h"
#include "minecraft/MinecraftInstance.h" #include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h" #include "minecraft/PackProfile.h"
#include "modplatform/flame/PackManifest.h"
#include "net/ChecksumValidator.h" #include "net/ChecksumValidator.h"
#include "net/Upload.h"
#include "settings/INISettingsObject.h" #include "settings/INISettingsObject.h"
#include "BuildConfig.h" #include "BuildConfig.h"
#include "Application.h" #include "Application.h"
#include "ui/dialogs/ScrollMessageBox.h"
namespace ModpacksCH { namespace ModpacksCH {
PackInstallTask::PackInstallTask(Modpack pack, QString version) PackInstallTask::PackInstallTask(Modpack pack, QString version, QWidget* parent)
{ {
m_pack = pack; m_pack = pack;
m_version_name = version; m_version_name = version;
m_parent = parent;
} }
bool PackInstallTask::abort() bool PackInstallTask::abort()
{ {
if(abortable) if(abortable)
{ {
if (modIdResolver)
return modIdResolver->abort();
else if (jobPtr)
return jobPtr->abort(); return jobPtr->abort();
} }
return false; return false;
@ -118,7 +125,7 @@ void PackInstallTask::onDownloadSucceeded()
} }
m_version = version; m_version = version;
downloadPack(); resolveMods();
} }
void PackInstallTask::onDownloadFailed(QString reason) void PackInstallTask::onDownloadFailed(QString reason)
@ -127,13 +134,92 @@ void PackInstallTask::onDownloadFailed(QString reason)
emitFailed(reason); emitFailed(reason);
} }
void PackInstallTask::resolveMods()
{
setStatus(tr("Resolving mods..."));
Flame::Manifest manifest;
indexFileIdMap.clear();
int index = 0;
for(auto file : m_version.files) {
if(!file.serverOnly && file.url.isEmpty()) {
if(file.curseforge.file <= 0)
emitFailed("Invalid manifest"); // TODO better error
Flame::File f;
f.projectId = file.curseforge.project;
f.fileId = file.curseforge.file;
f.hash = file.sha1;
manifest.files.insert(f.fileId, f);
indexFileIdMap.insert(index, f.fileId);
}
index++;
}
modIdResolver = new Flame::FileResolvingTask(APPLICATION->network(), manifest);
connect(modIdResolver.get(), &Flame::FileResolvingTask::succeeded, this, [&]()
{
abortable = false;
//first check for blocked mods
QString text;
auto anyBlocked = false;
Flame::Manifest results = modIdResolver->getResults();
for(int index : indexFileIdMap.keys())
{
int fileId = indexFileIdMap[index];
Flame::File foo = results.files[fileId];
VersionFile &bar = m_version.files[index];
if (!foo.resolved || foo.url.isEmpty())
{
QString type = bar.type;
type[0] = type[0].toUpper();
text += QString("%1: %2 - <a href='%3'>%3</a><br/>").arg(type, bar.name, foo.websiteUrl);
anyBlocked = true;
} else {
bar.url = foo.url.toString();
}
}
if(anyBlocked) {
qWarning() << "Blocked files found, displaying file list";
auto message_dialog = new ScrollMessageBox(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."),
text);
message_dialog->setModal(true);
message_dialog->show();
connect(message_dialog, &QDialog::rejected, [&]() {
modIdResolver.reset();
emitFailed("Canceled");
});
connect(message_dialog, &QDialog::accepted, [&]() {
modIdResolver.reset();
downloadPack();
});
} else {
modIdResolver.reset();
downloadPack();
}
});
connect(modIdResolver.get(), &Flame::FileResolvingTask::failed, this, &PackInstallTask::onDownloadFailed);
modIdResolver->start();
abortable = true;
}
void PackInstallTask::downloadPack() void PackInstallTask::downloadPack()
{ {
setStatus(tr("Downloading mods...")); setStatus(tr("Downloading mods..."));
jobPtr = new NetJob(tr("Mod download"), APPLICATION->network()); jobPtr = new NetJob(tr("Mod download"), APPLICATION->network());
for(auto file : m_version.files) { for(auto file : m_version.files) {
if(file.serverOnly) continue; if(file.serverOnly || file.url.isEmpty()) continue;
QFileInfo fileName(file.name); QFileInfo fileName(file.name);
auto cacheName = fileName.completeBaseName() + "-" + file.sha1 + "." + fileName.suffix(); auto cacheName = fileName.completeBaseName() + "-" + file.sha1 + "." + fileName.suffix();

View File

@ -19,9 +19,13 @@
#include "FTBPackManifest.h" #include "FTBPackManifest.h"
#include "QObjectPtr.h"
#include "modplatform/flame/FileResolvingTask.h"
#include "InstanceTask.h" #include "InstanceTask.h"
#include "net/NetJob.h" #include "net/NetJob.h"
#include <QWidget>
namespace ModpacksCH { namespace ModpacksCH {
class PackInstallTask : public InstanceTask class PackInstallTask : public InstanceTask
@ -29,7 +33,7 @@ class PackInstallTask : public InstanceTask
Q_OBJECT Q_OBJECT
public: public:
explicit PackInstallTask(Modpack pack, QString version); explicit PackInstallTask(Modpack pack, QString version, QWidget* parent = nullptr);
virtual ~PackInstallTask(){} virtual ~PackInstallTask(){}
bool canAbort() const override { return true; } bool canAbort() const override { return true; }
@ -43,6 +47,7 @@ private slots:
void onDownloadFailed(QString reason); void onDownloadFailed(QString reason);
private: private:
void resolveMods();
void downloadPack(); void downloadPack();
void install(); void install();
@ -50,6 +55,9 @@ private:
bool abortable = false; bool abortable = false;
NetJob::Ptr jobPtr; NetJob::Ptr jobPtr;
shared_qobject_ptr<Flame::FileResolvingTask> modIdResolver;
QMap<int, int> indexFileIdMap;
QByteArray response; QByteArray response;
Modpack m_pack; Modpack m_pack;
@ -58,6 +66,8 @@ private:
QMap<QString, QString> filesToCopy; QMap<QString, QString> filesToCopy;
//FIXME: nuke
QWidget* m_parent;
}; };
} }

View File

@ -127,13 +127,16 @@ static void loadVersionFile(ModpacksCH::VersionFile & a, QJsonObject & obj)
a.path = Json::requireString(obj, "path"); a.path = Json::requireString(obj, "path");
a.name = Json::requireString(obj, "name"); a.name = Json::requireString(obj, "name");
a.version = Json::requireString(obj, "version"); a.version = Json::requireString(obj, "version");
a.url = Json::requireString(obj, "url"); a.url = Json::ensureString(obj, "url"); // optional
a.sha1 = Json::requireString(obj, "sha1"); a.sha1 = Json::requireString(obj, "sha1");
a.size = Json::requireInteger(obj, "size"); a.size = Json::requireInteger(obj, "size");
a.clientOnly = Json::requireBoolean(obj, "clientonly"); a.clientOnly = Json::requireBoolean(obj, "clientonly");
a.serverOnly = Json::requireBoolean(obj, "serveronly"); a.serverOnly = Json::requireBoolean(obj, "serveronly");
a.optional = Json::requireBoolean(obj, "optional"); a.optional = Json::requireBoolean(obj, "optional");
a.updated = Json::requireInteger(obj, "updated"); a.updated = Json::requireInteger(obj, "updated");
auto curseforgeObj = Json::ensureObject(obj, "curseforge"); // optional
a.curseforge.project = Json::ensureInteger(curseforgeObj, "project");
a.curseforge.file = Json::ensureInteger(curseforgeObj, "file");
} }
void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj) void ModpacksCH::loadVersion(ModpacksCH::Version & m, QJsonObject & obj)

View File

@ -97,6 +97,12 @@ struct VersionTarget
int64_t updated; int64_t updated;
}; };
struct VersionFileCurseForge
{
int project;
int file;
};
struct VersionFile struct VersionFile
{ {
int id; int id;
@ -111,6 +117,7 @@ struct VersionFile
bool serverOnly; bool serverOnly;
bool optional; bool optional;
int64_t updated; int64_t updated;
VersionFileCurseForge curseforge;
}; };
struct Version struct Version

View File

@ -126,7 +126,7 @@ void FtbPage::suggestCurrent()
return; return;
} }
dialog->setSuggestedPack(selected.name + " " + selectedVersion, new ModpacksCH::PackInstallTask(selected, selectedVersion)); dialog->setSuggestedPack(selected.name + " " + selectedVersion, new ModpacksCH::PackInstallTask(selected, selectedVersion, this));
for(auto art : selected.art) { for(auto art : selected.art) {
if(art.type == "square") { if(art.type == "square") {
QString editedLogoName; QString editedLogoName;