aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authortimoreo <contact@timoreo.fr>2022-09-13 12:00:22 +0200
committerRachel Powers <508861+Ryex@users.noreply.github.com>2023-05-05 15:05:17 -0700
commit63c21c53af457673a836915ae7351111c980a4bf (patch)
treefc8364715359aaabbd6c02e195aab2fd157e6724 /launcher
parentd0b6f0124b41f8e279df5b224c975d03b3631b1e (diff)
downloadPrismLauncher-63c21c53af457673a836915ae7351111c980a4bf.tar.gz
PrismLauncher-63c21c53af457673a836915ae7351111c980a4bf.tar.bz2
PrismLauncher-63c21c53af457673a836915ae7351111c980a4bf.zip
Added url handler for curseforge
Signed-off-by: timoreo <contact@timoreo.fr>
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Application.cpp1
-rw-r--r--launcher/InstanceImportTask.cpp69
-rw-r--r--launcher/InstanceImportTask.h1
3 files changed, 54 insertions, 17 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index 28c2a9ce..0b1ab16c 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -240,7 +240,6 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
m_zipsToImport.append(QUrl::fromLocalFile(QFileInfo(zip_path).absoluteFilePath()));
}
-
// error if --launch is missing with --server or --profile
if((!m_serverToJoin.isEmpty() || !m_profileToUse.isEmpty()) && m_instanceIdToLaunch.isEmpty())
{
diff --git a/launcher/InstanceImportTask.cpp b/launcher/InstanceImportTask.cpp
index 8a48873e..ef221bf9 100644
--- a/launcher/InstanceImportTask.cpp
+++ b/launcher/InstanceImportTask.cpp
@@ -47,6 +47,8 @@
#include "modplatform/technic/TechnicPackProcessor.h"
#include "modplatform/modrinth/ModrinthInstanceCreationTask.h"
#include "modplatform/flame/FlameInstanceCreationTask.h"
+// FIXME : move this over to FlameInstanceCreationTask
+#include "Json.h"
#include "settings/INISettingsObject.h"
@@ -87,25 +89,59 @@ void InstanceImportTask::executeTask()
setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
m_downloadRequired = true;
- const QString path(m_sourceUrl.host() + '/' + m_sourceUrl.path());
-
- auto entry = APPLICATION->metacache()->resolveEntry("general", path);
- entry->setStale(true);
- m_archivePath = entry->getFullPath();
-
- m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network()));
- m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
-
- connect(m_filesNetJob.get(), &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded);
- connect(m_filesNetJob.get(), &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
- connect(m_filesNetJob.get(), &NetJob::stepProgress, this, &InstanceImportTask::propogateStepProgress);
- connect(m_filesNetJob.get(), &NetJob::failed, this, &InstanceImportTask::downloadFailed);
- connect(m_filesNetJob.get(), &NetJob::aborted, this, &InstanceImportTask::downloadAborted);
-
- m_filesNetJob->start();
+ if (m_sourceUrl.scheme() == "curseforge") {
+ // need to find the download link for the modpack
+ // format of url curseforge://install?addonId=IDHERE&fileId=IDHERE
+ QUrlQuery query(m_sourceUrl);
+ auto addonId = query.allQueryItemValues("addonId")[0];
+ auto fileId = query.allQueryItemValues("fileId")[0];
+ auto array = new QByteArray();
+ auto req = new NetJob("Curseforge Meta", APPLICATION->network());
+ req->addNetAction(
+ Net::Download::makeByteArray(QUrl(QString("https://api.curseforge.com/v1/mods/%1/files/%2").arg(addonId, fileId)), array));
+ connect(req, &NetJob::finished, [array, req] {
+ req->deleteLater();
+ delete array;
+ });
+ connect(req, &NetJob::failed, this, &InstanceImportTask::downloadFailed);
+ connect(req, &NetJob::succeeded, [array, this] {
+ auto doc = Json::requireDocument(*array);
+ // Have to use ensureString then use QUrl to get proper url encoding
+ m_sourceUrl = QUrl(
+ Json::ensureString(Json::ensureObject(Json::ensureObject(doc.object()), "data"), "downloadUrl", "", "downloadUrl"));
+ if (!m_sourceUrl.isValid()) {
+ emitFailed(tr("The modpack is blocked ! Please download it manually"));
+ return;
+ }
+ downloadFromUrl();
+ });
+ connect(req, &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
+ connect(req, &NetJob::stepProgress, this, &InstanceImportTask::propogateStepProgress);
+ connect(req, &NetJob::aborted, this, &InstanceImportTask::downloadAborted);
+ req->start();
+ } else {
+ downloadFromUrl();
+ }
}
}
+void InstanceImportTask::downloadFromUrl()
+{
+ const QString path = m_sourceUrl.host() + '/' + m_sourceUrl.path();
+ auto entry = APPLICATION->metacache()->resolveEntry("general", path);
+ entry->setStale(true);
+ m_filesNetJob.reset(new NetJob(tr("Modpack download"), APPLICATION->network()));
+ m_filesNetJob->addNetAction(Net::Download::makeCached(m_sourceUrl, entry));
+ m_archivePath = entry->getFullPath();
+
+ connect(m_filesNetJob.get(), &NetJob::succeeded, this, &InstanceImportTask::downloadSucceeded);
+ connect(m_filesNetJob.get(), &NetJob::progress, this, &InstanceImportTask::downloadProgressChanged);
+ connect(m_filesNetJob.get(), &NetJob::stepProgress, this, &InstanceImportTask::propogateStepProgress);
+ connect(m_filesNetJob.get(), &NetJob::failed, this, &InstanceImportTask::downloadFailed);
+ connect(m_filesNetJob.get(), &NetJob::aborted, this, &InstanceImportTask::downloadAborted);
+ m_filesNetJob->start();
+}
+
void InstanceImportTask::downloadSucceeded()
{
processZipPack();
@@ -396,3 +432,4 @@ void InstanceImportTask::processModrinth()
inst_creation_task->start();
}
+
diff --git a/launcher/InstanceImportTask.h b/launcher/InstanceImportTask.h
index 7fda439f..9c1edc6d 100644
--- a/launcher/InstanceImportTask.h
+++ b/launcher/InstanceImportTask.h
@@ -106,4 +106,5 @@ private: /* data */
//FIXME: nuke
QWidget* m_parent;
+ void downloadFromUrl();
};