aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--launcher/CMakeLists.txt1
-rw-r--r--launcher/net/ApiDownload.cpp67
-rw-r--r--launcher/net/ApiDownload.h14
-rw-r--r--launcher/net/ApiHeaderProxy.h28
-rw-r--r--launcher/net/Download.cpp5
-rw-r--r--launcher/net/Download.h4
-rw-r--r--launcher/net/HeaderProxy.h3
-rw-r--r--launcher/net/NetAction.h1
-rw-r--r--launcher/net/Upload.h1
-rw-r--r--launcher/screenshots/ImgurAlbumCreation.h2
-rw-r--r--launcher/screenshots/ImgurUpload.h1
11 files changed, 101 insertions, 26 deletions
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 63156471..1e28591e 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -140,6 +140,7 @@ set(NET_SOURCES
net/RawHeaderProxy.h
net/ApiHeaderProxy.h
net/ApiDownload.h
+ net/ApiDownload.cpp
)
# Game launch logic
diff --git a/launcher/net/ApiDownload.cpp b/launcher/net/ApiDownload.cpp
new file mode 100644
index 00000000..69b39c4a
--- /dev/null
+++ b/launcher/net/ApiDownload.cpp
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-3.0-only
+/*
+ * Prism Launcher - Minecraft Launcher
+ * Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "ByteArraySink.h"
+#include "ChecksumValidator.h"
+#include "MetaCacheSink.h"
+#include "net/ApiDownload.h"
+#include "net/NetAction.h"
+
+namespace Net {
+
+auto ApiDownload::makeCached(QUrl url, MetaEntryPtr entry, Options options) -> Download::Ptr
+{
+ auto dl = makeShared<ApiDownload>();
+ dl->m_url = url;
+ dl->setObjectName(QString("CACHE:") + url.toString());
+ dl->m_options = options;
+ auto md5Node = new ChecksumValidator(QCryptographicHash::Md5);
+ auto cachedNode = new MetaCacheSink(entry, md5Node, options.testFlag(Option::MakeEternal));
+ dl->m_sink.reset(cachedNode);
+ return dl;
+}
+
+auto ApiDownload::makeByteArray(QUrl url, QByteArray* output, Options options) -> Download::Ptr
+{
+ auto dl = makeShared<ApiDownload>();
+ dl->m_url = url;
+ dl->setObjectName(QString("BYTES:") + url.toString());
+ dl->m_options = options;
+ dl->m_sink.reset(new ByteArraySink(output));
+ return dl;
+}
+
+auto ApiDownload::makeFile(QUrl url, QString path, Options options) -> Download::Ptr
+{
+ auto dl = makeShared<ApiDownload>();
+ dl->m_url = url;
+ dl->setObjectName(QString("FILE:") + url.toString());
+ dl->m_options = options;
+ dl->m_sink.reset(new FileSink(path));
+ return dl;
+}
+
+
+void ApiDownload::init()
+{
+ qDebug() << "Setting up api download";
+ auto api_headers = new ApiHeaderProxy();
+ addHeaderProxy(api_headers);
+}
+} // namespace Net
diff --git a/launcher/net/ApiDownload.h b/launcher/net/ApiDownload.h
index 3ffda445..7a1f2e92 100644
--- a/launcher/net/ApiDownload.h
+++ b/launcher/net/ApiDownload.h
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
- * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
- * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
@@ -28,12 +26,14 @@ namespace Net {
class ApiDownload : public Download {
public:
- ApiDownload() : Download()
- {
- auto api_headers = new ApiHeaderProxy();
- addHeaderProxy(api_headers);
- }
virtual ~ApiDownload() = default;
+
+ static auto makeCached(QUrl url, MetaEntryPtr entry, Options options = Option::NoOptions) -> Download::Ptr;
+ static auto makeByteArray(QUrl url, QByteArray* output, Options options = Option::NoOptions) -> Download::Ptr;
+ static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr;
+
+ void init() override;
+
};
} // namespace Net
diff --git a/launcher/net/ApiHeaderProxy.h b/launcher/net/ApiHeaderProxy.h
index 0da92a74..5de503a6 100644
--- a/launcher/net/ApiHeaderProxy.h
+++ b/launcher/net/ApiHeaderProxy.h
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
- * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
- * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
@@ -21,9 +19,9 @@
#pragma once
+#include "net/HeaderProxy.h"
#include "Application.h"
#include "BuildConfig.h"
-#include "net/HeaderProxy.h"
namespace Net {
@@ -33,19 +31,19 @@ class ApiHeaderProxy : public HeaderProxy {
virtual ~ApiHeaderProxy() = default;
public:
- virtual QList<HeaderPair> headers(const QNetworkRequest& request) const override
- {
- QList<HeaderPair> hdrs;
- if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
- hdrs.append({ "x-api-key", APPLICATION->getFlameAPIKey().toUtf8() });
- } else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
- request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
- QString token = APPLICATION->getModrinthAPIToken();
- if (!token.isNull())
- hdrs.append({ "Authorization", token.toUtf8() });
- }
- return hdrs;
+ virtual QList<HeaderPair> headers(const QNetworkRequest& request) const override {
+ QList<HeaderPair> hdrs;
+ if (APPLICATION->capabilities() & Application::SupportsFlame && request.url().host() == QUrl(BuildConfig.FLAME_BASE_URL).host()) {
+ hdrs.append({ "x-api-key", APPLICATION->getFlameAPIKey().toUtf8() });
+ } else if (request.url().host() == QUrl(BuildConfig.MODRINTH_PROD_URL).host() ||
+ request.url().host() == QUrl(BuildConfig.MODRINTH_STAGING_URL).host()) {
+ QString token = APPLICATION->getModrinthAPIToken();
+ if (!token.isNull())
+ hdrs.append({ "Authorization", token.toUtf8() });
+ }
+ return hdrs;
};
+
};
} // namespace Net
diff --git a/launcher/net/Download.cpp b/launcher/net/Download.cpp
index 6c217379..071a9659 100644
--- a/launcher/net/Download.cpp
+++ b/launcher/net/Download.cpp
@@ -96,6 +96,8 @@ void Download::addValidator(Validator* v)
void Download::executeTask()
{
+ init();
+
setStatus(tr("Downloading %1").arg(StringUtils::truncateUrlHumanFriendly(m_url, 80)));
if (getState() == Task::State::AbortedByUser) {
@@ -124,7 +126,8 @@ void Download::executeTask()
}
request.setHeader(QNetworkRequest::UserAgentHeader, APPLICATION->getUserAgent().toUtf8());
- for ( auto header_proxy : m_headerProxies ) {
+ for ( auto& header_proxy : m_headerProxies ) {
+
header_proxy->writeHeaders(request);
}
// TODO remove duplication
diff --git a/launcher/net/Download.h b/launcher/net/Download.h
index 920164a3..fee04feb 100644
--- a/launcher/net/Download.h
+++ b/launcher/net/Download.h
@@ -63,6 +63,8 @@ class Download : public NetAction {
static auto makeByteArray(QUrl url, QByteArray* output, Options options = Option::NoOptions) -> Download::Ptr;
static auto makeFile(QUrl url, QString path, Options options = Option::NoOptions) -> Download::Ptr;
+ void init() override {};
+
public:
void addValidator(Validator* v);
auto abort() -> bool override;
@@ -81,7 +83,7 @@ class Download : public NetAction {
public slots:
void executeTask() override;
- private:
+ protected:
std::unique_ptr<Sink> m_sink;
Options m_options;
diff --git a/launcher/net/HeaderProxy.h b/launcher/net/HeaderProxy.h
index e94579e7..bb3c8b03 100644
--- a/launcher/net/HeaderProxy.h
+++ b/launcher/net/HeaderProxy.h
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
- * Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
- * Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2023 Rachel Powers <508861+Ryex@users.noreply.github.com>
*
* This program is free software: you can redistribute it and/or modify
@@ -22,6 +20,7 @@
#pragma once
#include <QNetworkRequest>
+#include <QDebug>
namespace Net {
diff --git a/launcher/net/NetAction.h b/launcher/net/NetAction.h
index acb0672f..93076abc 100644
--- a/launcher/net/NetAction.h
+++ b/launcher/net/NetAction.h
@@ -59,6 +59,7 @@ class NetAction : public Task {
void setNetwork(shared_qobject_ptr<QNetworkAccessManager> network) { m_network = network; }
void addHeaderProxy(Net::HeaderProxy* proxy) { m_headerProxies.push_back(std::shared_ptr<Net::HeaderProxy>(proxy)); }
+ virtual void init() = 0;
protected slots:
virtual void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) = 0;
diff --git a/launcher/net/Upload.h b/launcher/net/Upload.h
index e8f0ea40..48442731 100644
--- a/launcher/net/Upload.h
+++ b/launcher/net/Upload.h
@@ -51,6 +51,7 @@ namespace Net {
static Upload::Ptr makeByteArray(QUrl url, QByteArray *output, QByteArray m_post_data);
auto abort() -> bool override;
auto canAbort() const -> bool override { return true; };
+ virtual void init() override {};
protected slots:
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
diff --git a/launcher/screenshots/ImgurAlbumCreation.h b/launcher/screenshots/ImgurAlbumCreation.h
index 0228b6e4..a2b70d8b 100644
--- a/launcher/screenshots/ImgurAlbumCreation.h
+++ b/launcher/screenshots/ImgurAlbumCreation.h
@@ -57,6 +57,8 @@ public:
return m_id;
}
+ void init() override {};
+
protected
slots:
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal) override;
diff --git a/launcher/screenshots/ImgurUpload.h b/launcher/screenshots/ImgurUpload.h
index 404dc876..e8a6d8d7 100644
--- a/launcher/screenshots/ImgurUpload.h
+++ b/launcher/screenshots/ImgurUpload.h
@@ -46,6 +46,7 @@ public:
static Ptr make(ScreenShot::Ptr shot) {
return Ptr(new ImgurUpload(shot));
}
+ void init() override {};
protected
slots: