diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
index cac432cdd..c888ef227 100644
--- a/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
+++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.cpp
@@ -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 - %3
").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.
"
+ "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();
diff --git a/launcher/modplatform/modpacksch/FTBPackInstallTask.h b/launcher/modplatform/modpacksch/FTBPackInstallTask.h
index ff59b695c..a85f360a9 100644
--- a/launcher/modplatform/modpacksch/FTBPackInstallTask.h
+++ b/launcher/modplatform/modpacksch/FTBPackInstallTask.h
@@ -19,9 +19,13 @@
#include "FTBPackManifest.h"
+#include "QObjectPtr.h"
+#include "modplatform/flame/FileResolvingTask.h"
#include "InstanceTask.h"
#include "net/NetJob.h"
+#include
+
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 modIdResolver;
+ QMap indexFileIdMap;
+
QByteArray response;
Modpack m_pack;
@@ -58,6 +66,8 @@ private:
QMap filesToCopy;
+ //FIXME: nuke
+ QWidget* m_parent;
};
}
diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.cpp b/launcher/modplatform/modpacksch/FTBPackManifest.cpp
index e2d47a5bb..a8c0f6b80 100644
--- a/launcher/modplatform/modpacksch/FTBPackManifest.cpp
+++ b/launcher/modplatform/modpacksch/FTBPackManifest.cpp
@@ -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)
diff --git a/launcher/modplatform/modpacksch/FTBPackManifest.h b/launcher/modplatform/modpacksch/FTBPackManifest.h
index da45d8ac9..0451127a6 100644
--- a/launcher/modplatform/modpacksch/FTBPackManifest.h
+++ b/launcher/modplatform/modpacksch/FTBPackManifest.h
@@ -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
diff --git a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp
index 8a93bc2e3..693ee8840 100644
--- a/launcher/ui/pages/modplatform/ftb/FtbPage.cpp
+++ b/launcher/ui/pages/modplatform/ftb/FtbPage.cpp
@@ -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;