feat: implement mod resolving for FTB
Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
parent
86573a5ccd
commit
75a7ea55d4
@ -40,25 +40,32 @@
|
||||
#include "Json.h"
|
||||
#include "minecraft/MinecraftInstance.h"
|
||||
#include "minecraft/PackProfile.h"
|
||||
#include "modplatform/flame/PackManifest.h"
|
||||
#include "net/ChecksumValidator.h"
|
||||
#include "net/Upload.h"
|
||||
#include "settings/INISettingsObject.h"
|
||||
|
||||
#include "BuildConfig.h"
|
||||
#include "Application.h"
|
||||
#include "ui/dialogs/ScrollMessageBox.h"
|
||||
|
||||
namespace ModpacksCH {
|
||||
|
||||
PackInstallTask::PackInstallTask(Modpack pack, QString version)
|
||||
PackInstallTask::PackInstallTask(Modpack pack, QString version, QWidget* parent)
|
||||
{
|
||||
m_pack = pack;
|
||||
m_version_name = version;
|
||||
m_parent = parent;
|
||||
}
|
||||
|
||||
bool PackInstallTask::abort()
|
||||
{
|
||||
if(abortable)
|
||||
{
|
||||
return jobPtr->abort();
|
||||
if (modIdResolver)
|
||||
return modIdResolver->abort();
|
||||
else if (jobPtr)
|
||||
return jobPtr->abort();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -118,7 +125,7 @@ void PackInstallTask::onDownloadSucceeded()
|
||||
}
|
||||
m_version = version;
|
||||
|
||||
downloadPack();
|
||||
resolveMods();
|
||||
}
|
||||
|
||||
void PackInstallTask::onDownloadFailed(QString reason)
|
||||
@ -127,13 +134,92 @@ void PackInstallTask::onDownloadFailed(QString 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()
|
||||
{
|
||||
setStatus(tr("Downloading mods..."));
|
||||
|
||||
jobPtr = new NetJob(tr("Mod download"), APPLICATION->network());
|
||||
for(auto file : m_version.files) {
|
||||
if(file.serverOnly) continue;
|
||||
if(file.serverOnly || file.url.isEmpty()) continue;
|
||||
|
||||
QFileInfo fileName(file.name);
|
||||
auto cacheName = fileName.completeBaseName() + "-" + file.sha1 + "." + fileName.suffix();
|
||||
|
@ -19,9 +19,13 @@
|
||||
|
||||
#include "FTBPackManifest.h"
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
#include "modplatform/flame/FileResolvingTask.h"
|
||||
#include "InstanceTask.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace ModpacksCH {
|
||||
|
||||
class PackInstallTask : public InstanceTask
|
||||
@ -29,7 +33,7 @@ class PackInstallTask : public InstanceTask
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PackInstallTask(Modpack pack, QString version);
|
||||
explicit PackInstallTask(Modpack pack, QString version, QWidget* parent = nullptr);
|
||||
virtual ~PackInstallTask(){}
|
||||
|
||||
bool canAbort() const override { return true; }
|
||||
@ -43,6 +47,7 @@ private slots:
|
||||
void onDownloadFailed(QString reason);
|
||||
|
||||
private:
|
||||
void resolveMods();
|
||||
void downloadPack();
|
||||
void install();
|
||||
|
||||
@ -50,6 +55,9 @@ private:
|
||||
bool abortable = false;
|
||||
|
||||
NetJob::Ptr jobPtr;
|
||||
shared_qobject_ptr<Flame::FileResolvingTask> modIdResolver;
|
||||
QMap<int, int> indexFileIdMap;
|
||||
|
||||
QByteArray response;
|
||||
|
||||
Modpack m_pack;
|
||||
@ -58,6 +66,8 @@ private:
|
||||
|
||||
QMap<QString, QString> filesToCopy;
|
||||
|
||||
//FIXME: nuke
|
||||
QWidget* m_parent;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -127,13 +127,16 @@ static void loadVersionFile(ModpacksCH::VersionFile & a, QJsonObject & obj)
|
||||
a.path = Json::requireString(obj, "path");
|
||||
a.name = Json::requireString(obj, "name");
|
||||
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.size = Json::requireInteger(obj, "size");
|
||||
a.clientOnly = Json::requireBoolean(obj, "clientonly");
|
||||
a.serverOnly = Json::requireBoolean(obj, "serveronly");
|
||||
a.optional = Json::requireBoolean(obj, "optional");
|
||||
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)
|
||||
|
@ -97,6 +97,12 @@ struct VersionTarget
|
||||
int64_t updated;
|
||||
};
|
||||
|
||||
struct VersionFileCurseForge
|
||||
{
|
||||
int project;
|
||||
int file;
|
||||
};
|
||||
|
||||
struct VersionFile
|
||||
{
|
||||
int id;
|
||||
@ -111,6 +117,7 @@ struct VersionFile
|
||||
bool serverOnly;
|
||||
bool optional;
|
||||
int64_t updated;
|
||||
VersionFileCurseForge curseforge;
|
||||
};
|
||||
|
||||
struct Version
|
||||
|
@ -126,7 +126,7 @@ void FtbPage::suggestCurrent()
|
||||
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) {
|
||||
if(art.type == "square") {
|
||||
QString editedLogoName;
|
||||
|
Loading…
Reference in New Issue
Block a user