Cleanup downloaders
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
e897032383
commit
f36be3f0e3
@ -433,6 +433,10 @@ set(JAVA_SOURCES
|
|||||||
|
|
||||||
java/JavaRuntime.h
|
java/JavaRuntime.h
|
||||||
java/JavaRuntime.cpp
|
java/JavaRuntime.cpp
|
||||||
|
java/download/ArchiveJavaDownloader.cpp
|
||||||
|
java/download/ArchiveJavaDownloader.h
|
||||||
|
java/download/ManifestJavaDownloader.cpp
|
||||||
|
java/download/ManifestJavaDownloader.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(TRANSLATIONS_SOURCES
|
set(TRANSLATIONS_SOURCES
|
||||||
|
56
launcher/java/JavaRuntime.cpp
Normal file
56
launcher/java/JavaRuntime.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include "java/JavaRuntime.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "Json.h"
|
||||||
|
#include "java/JavaVersion.h"
|
||||||
|
#include "minecraft/ParseUtils.h"
|
||||||
|
|
||||||
|
namespace JavaRuntime {
|
||||||
|
|
||||||
|
DownloadType parseDownloadType(QString javaDownload)
|
||||||
|
{
|
||||||
|
if (javaDownload == "manifest")
|
||||||
|
return DownloadType::Manifest;
|
||||||
|
// if (javaDownload == "archive")
|
||||||
|
return DownloadType::Archive;
|
||||||
|
}
|
||||||
|
QString downloadTypeToString(DownloadType javaDownload)
|
||||||
|
{
|
||||||
|
switch (javaDownload) {
|
||||||
|
case DownloadType::Manifest:
|
||||||
|
return "manifest";
|
||||||
|
case DownloadType::Archive:
|
||||||
|
return "archive";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MetaPtr parseJavaMeta(const QJsonObject& in)
|
||||||
|
{
|
||||||
|
auto meta = std::make_shared<Meta>();
|
||||||
|
|
||||||
|
meta->name = Json::ensureString(in, "name", "");
|
||||||
|
meta->vendor = Json::ensureString(in, "vendor", "");
|
||||||
|
meta->url = Json::ensureString(in, "url", "");
|
||||||
|
meta->releaseTime = timeFromS3Time(Json::ensureString(in, "releaseTime", ""));
|
||||||
|
meta->recommended = Json::ensureBoolean(in, "recommended", false);
|
||||||
|
meta->downloadType = parseDownloadType(Json::ensureString(in, "downloadType", ""));
|
||||||
|
meta->packageType = Json::ensureString(in, "packageType", "");
|
||||||
|
|
||||||
|
if (in.contains("checksum")) {
|
||||||
|
auto obj = Json::requireObject(in, "checksum");
|
||||||
|
meta->checksumHash = Json::ensureString(obj, "hash", "");
|
||||||
|
meta->checksumType = Json::ensureString(obj, "type", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in.contains("version")) {
|
||||||
|
auto obj = Json::requireObject(in, "checksum");
|
||||||
|
auto name = Json::ensureString(obj, "name", "");
|
||||||
|
auto major = Json::ensureInteger(obj, "major", 0);
|
||||||
|
auto minor = Json::ensureInteger(obj, "minor", 0);
|
||||||
|
auto security = Json::ensureInteger(obj, "security", 0);
|
||||||
|
auto build = Json::ensureInteger(obj, "build", 0);
|
||||||
|
meta->version = JavaVersion(major, minor, security, build, name);
|
||||||
|
}
|
||||||
|
return meta;
|
||||||
|
}
|
||||||
|
} // namespace JavaRuntime
|
30
launcher/java/JavaRuntime.h
Normal file
30
launcher/java/JavaRuntime.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "java/JavaVersion.h"
|
||||||
|
|
||||||
|
namespace JavaRuntime {
|
||||||
|
|
||||||
|
enum class DownloadType { Manifest, Archive };
|
||||||
|
|
||||||
|
struct Meta {
|
||||||
|
QString name;
|
||||||
|
QString vendor;
|
||||||
|
QString url;
|
||||||
|
QDateTime releaseTime;
|
||||||
|
QString checksumType;
|
||||||
|
QString checksumHash;
|
||||||
|
bool recommended;
|
||||||
|
DownloadType downloadType;
|
||||||
|
QString packageType;
|
||||||
|
JavaVersion version;
|
||||||
|
};
|
||||||
|
using MetaPtr = std::shared_ptr<Meta>;
|
||||||
|
|
||||||
|
DownloadType parseDownloadType(QString javaDownload);
|
||||||
|
QString downloadTypeToString(DownloadType javaDownload);
|
||||||
|
MetaPtr parseJavaMeta(const QJsonObject& libObj);
|
||||||
|
|
||||||
|
} // namespace JavaRuntime
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "java/providers/AdoptiumJavaDownloader.h"
|
#include "java/download/ArchiveJavaDownloader.h"
|
||||||
#include <quazip.h>
|
#include <quazip.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
@ -24,39 +24,21 @@
|
|||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
void AdoptiumJavaDownloader::executeTask()
|
void ArchiveJavaDownloader::executeTask()
|
||||||
{
|
|
||||||
downloadJava();
|
|
||||||
};
|
|
||||||
|
|
||||||
QString AdoptiumJavaDownloader::getArch() const
|
|
||||||
{
|
|
||||||
if (m_os_arch == "arm64")
|
|
||||||
return "aarch64";
|
|
||||||
if (m_os_arch.isEmpty())
|
|
||||||
return "x86";
|
|
||||||
return m_os_arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AdoptiumJavaDownloader::downloadJava()
|
|
||||||
{
|
{
|
||||||
// JRE found ! download the zip
|
// JRE found ! download the zip
|
||||||
setStatus(tr("Downloading Java from Adoptium"));
|
setStatus(tr("Downloading Java"));
|
||||||
|
|
||||||
auto javaVersion = m_is_legacy ? QString("8") : QString("17");
|
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("java", m_url.toLocalFile());
|
||||||
auto azulOS = m_os_name == "osx" ? "mac" : m_os_name;
|
|
||||||
auto arch = getArch();
|
|
||||||
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("java", "adoptiumJRE.zip");
|
|
||||||
|
|
||||||
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
|
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
|
||||||
download->addNetAction(Net::Download::makeCached(
|
download->addNetAction(Net::Download::makeCached(m_url, entry));
|
||||||
QString("https://api.adoptium.net/v3/binary/latest/%1/ga/%2/%3/jre/hotspot/normal/eclipse").arg(javaVersion, azulOS, arch), entry));
|
|
||||||
auto fullPath = entry->getFullPath();
|
auto fullPath = entry->getFullPath();
|
||||||
|
|
||||||
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
|
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
|
||||||
// connect(download.get(), &NetJob::aborted, [path] { APPLICATION->instances()->destroyStagingPath(path); });
|
// connect(download.get(), &NetJob::aborted, [path] { APPLICATION->instances()->destroyStagingPath(path); });
|
||||||
connect(download.get(), &NetJob::progress, this, &AdoptiumJavaDownloader::progress);
|
connect(download.get(), &NetJob::progress, this, &ArchiveJavaDownloader::progress);
|
||||||
connect(download.get(), &NetJob::failed, this, &AdoptiumJavaDownloader::emitFailed);
|
connect(download.get(), &NetJob::failed, this, &ArchiveJavaDownloader::emitFailed);
|
||||||
connect(this, &Task::aborted, download.get(), &NetJob::abort);
|
connect(this, &Task::aborted, download.get(), &NetJob::abort);
|
||||||
connect(download.get(), &NetJob::succeeded, [this, fullPath] {
|
connect(download.get(), &NetJob::succeeded, [this, fullPath] {
|
||||||
// This should do all of the extracting and creating folders
|
// This should do all of the extracting and creating folders
|
||||||
@ -65,7 +47,7 @@ void AdoptiumJavaDownloader::downloadJava()
|
|||||||
download->start();
|
download->start();
|
||||||
};
|
};
|
||||||
|
|
||||||
void AdoptiumJavaDownloader::extractJava(QString input)
|
void ArchiveJavaDownloader::extractJava(QString input)
|
||||||
{
|
{
|
||||||
setStatus(tr("Extracting java"));
|
setStatus(tr("Extracting java"));
|
||||||
auto zip = std::make_shared<QuaZip>(input);
|
auto zip = std::make_shared<QuaZip>(input);
|
||||||
@ -85,14 +67,14 @@ void AdoptiumJavaDownloader::extractJava(QString input)
|
|||||||
connect(this, &Task::aborted, zipTask.get(), &Task::abort);
|
connect(this, &Task::aborted, zipTask.get(), &Task::abort);
|
||||||
connect(zipTask.get(), &Task::finished, [zipTask, this] { disconnect(this, &Task::aborted, zipTask.get(), &Task::abort); });
|
connect(zipTask.get(), &Task::finished, [zipTask, this] { disconnect(this, &Task::aborted, zipTask.get(), &Task::abort); });
|
||||||
|
|
||||||
connect(zipTask.get(), &Task::succeeded, this, &AdoptiumJavaDownloader::emitSucceeded);
|
connect(zipTask.get(), &Task::succeeded, this, &ArchiveJavaDownloader::emitSucceeded);
|
||||||
connect(zipTask.get(), &Task::aborted, this, &AdoptiumJavaDownloader::emitAborted);
|
connect(zipTask.get(), &Task::aborted, this, &ArchiveJavaDownloader::emitAborted);
|
||||||
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
|
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
|
||||||
progressStep->state = TaskStepState::Failed;
|
progressStep->state = TaskStepState::Failed;
|
||||||
stepProgress(*progressStep);
|
stepProgress(*progressStep);
|
||||||
emitFailed(reason);
|
emitFailed(reason);
|
||||||
});
|
});
|
||||||
connect(zipTask.get(), &Task::stepProgress, this, &AdoptiumJavaDownloader::propagateStepProgress);
|
connect(zipTask.get(), &Task::stepProgress, this, &ArchiveJavaDownloader::propagateStepProgress);
|
||||||
|
|
||||||
connect(zipTask.get(), &Task::progress, this, [this, progressStep](qint64 current, qint64 total) {
|
connect(zipTask.get(), &Task::progress, this, [this, progressStep](qint64 current, qint64 total) {
|
||||||
progressStep->update(current, total);
|
progressStep->update(current, total);
|
||||||
@ -104,16 +86,3 @@ void AdoptiumJavaDownloader::extractJava(QString input)
|
|||||||
});
|
});
|
||||||
zipTask->start();
|
zipTask->start();
|
||||||
};
|
};
|
||||||
|
|
||||||
static const QStringList supportedOs = {
|
|
||||||
"linux", "windows", "mac", "solaris", "aix", "alpine-linux",
|
|
||||||
};
|
|
||||||
|
|
||||||
static const QStringList supportedArch = {
|
|
||||||
"x64", "x86", "x32", "ppc64", "ppc64le", "s390x", "aarch64", "arm", "sparcv9", "riscv64",
|
|
||||||
};
|
|
||||||
|
|
||||||
bool AdoptiumJavaDownloader::isSupported() const
|
|
||||||
{
|
|
||||||
return supportedOs.contains(m_os_name == "osx" ? "mac" : m_os_name) && supportedArch.contains(getArch());
|
|
||||||
};
|
|
@ -18,24 +18,24 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QUrl>
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
class BasicJavaDownloader : public Task {
|
class ArchiveJavaDownloader : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
BasicJavaDownloader(QString final_path, bool m_is_legacy = false, QObject* parent = nullptr);
|
ArchiveJavaDownloader(QUrl url, QString final_path);
|
||||||
virtual ~BasicJavaDownloader() = default;
|
virtual ~ArchiveJavaDownloader() = default;
|
||||||
|
|
||||||
[[nodiscard]] bool canAbort() const override { return true; }
|
[[nodiscard]] bool canAbort() const override { return true; }
|
||||||
|
void executeTask() override;
|
||||||
|
|
||||||
virtual QString name() const = 0;
|
private slots:
|
||||||
virtual bool isSupported() const = 0;
|
void extractJava(QString input);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QString m_os_name;
|
QUrl m_url;
|
||||||
QString m_os_arch;
|
|
||||||
QString m_final_path;
|
QString m_final_path;
|
||||||
bool m_is_legacy;
|
|
||||||
|
|
||||||
Task::Ptr m_current_task;
|
Task::Ptr m_current_task;
|
||||||
};
|
};
|
@ -15,7 +15,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "java/providers/MojanglJavaDownloader.h"
|
#include "java/download/ManifestJavaDownloader.h"
|
||||||
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
@ -30,89 +30,18 @@ struct File {
|
|||||||
bool isExec;
|
bool isExec;
|
||||||
};
|
};
|
||||||
|
|
||||||
void MojangJavaDownloader::executeTask()
|
ManifestJavaDownloader::ManifestJavaDownloader(QUrl url, QString final_path) : m_url(url), m_final_path(final_path){};
|
||||||
|
void ManifestJavaDownloader::executeTask()
|
||||||
{
|
{
|
||||||
downloadJavaList();
|
setStatus(tr("Downloading Java"));
|
||||||
};
|
|
||||||
|
|
||||||
void MojangJavaDownloader::downloadJavaList()
|
|
||||||
{
|
|
||||||
auto netJob = makeShared<NetJob>(QString("JRE::QueryVersions"), APPLICATION->network());
|
|
||||||
auto response = std::make_shared<QByteArray>();
|
|
||||||
setStatus(tr("Querying mojang meta"));
|
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(
|
|
||||||
QUrl("https://piston-meta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json"), response));
|
|
||||||
|
|
||||||
connect(netJob.get(), &NetJob::finished, [netJob, this] {
|
|
||||||
// delete so that it's not called on a deleted job
|
|
||||||
// FIXME: is this needed? qt should handle this
|
|
||||||
disconnect(this, &Task::aborted, netJob.get(), &NetJob::abort);
|
|
||||||
});
|
|
||||||
connect(this, &Task::aborted, netJob.get(), &NetJob::abort);
|
|
||||||
|
|
||||||
connect(netJob.get(), &NetJob::progress, this, &MojangJavaDownloader::progress);
|
|
||||||
connect(netJob.get(), &NetJob::failed, this, &MojangJavaDownloader::emitFailed);
|
|
||||||
connect(netJob.get(), &NetJob::succeeded, [response, this, netJob] {
|
|
||||||
QJsonParseError parse_error{};
|
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
|
||||||
qWarning() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
|
|
||||||
qWarning() << *response;
|
|
||||||
emitFailed(parse_error.errorString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto versionArray = Json::ensureArray(Json::ensureObject(doc.object(), getOS()), m_is_legacy ? "jre-legacy" : "java-runtime-gamma");
|
|
||||||
if (!versionArray.empty()) {
|
|
||||||
parseManifest(versionArray);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// mojang does not have a JRE for us, so fail
|
|
||||||
emitFailed("No suitable JRE found");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
netJob->start();
|
|
||||||
};
|
|
||||||
|
|
||||||
QString MojangJavaDownloader::getOS() const
|
|
||||||
{
|
|
||||||
if (m_os_name == "windows") {
|
|
||||||
if (m_os_arch == "x86_64") {
|
|
||||||
return "windows-x64";
|
|
||||||
}
|
|
||||||
if (m_os_arch == "i386") {
|
|
||||||
return "windows-x86";
|
|
||||||
}
|
|
||||||
// Unknown, maybe arm, appending arch for downloader
|
|
||||||
return "windows-" + m_os_arch;
|
|
||||||
}
|
|
||||||
if (m_os_name == "osx") {
|
|
||||||
if (m_os_arch == "arm64") {
|
|
||||||
return "mac-os-arm64";
|
|
||||||
}
|
|
||||||
return "mac-os";
|
|
||||||
}
|
|
||||||
if (m_os_name == "linux") {
|
|
||||||
if (m_os_arch == "x86_64") {
|
|
||||||
return "linux";
|
|
||||||
}
|
|
||||||
// will work for i386, and arm(64)
|
|
||||||
return "linux-" + m_os_arch;
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
void MojangJavaDownloader::parseManifest(const QJsonArray& versionArray)
|
|
||||||
{
|
|
||||||
setStatus(tr("Downloading Java from Mojang"));
|
|
||||||
auto url = Json::ensureString(Json::ensureObject(Json::ensureObject(versionArray[0]), "manifest"), "url");
|
|
||||||
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
|
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
|
||||||
auto files = std::make_shared<QByteArray>();
|
auto files = std::make_shared<QByteArray>();
|
||||||
|
|
||||||
download->addNetAction(Net::Download::makeByteArray(QUrl(url), files));
|
download->addNetAction(Net::Download::makeByteArray(m_url, files));
|
||||||
|
|
||||||
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
|
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
|
||||||
connect(download.get(), &NetJob::progress, this, &MojangJavaDownloader::progress);
|
connect(download.get(), &NetJob::progress, this, &ManifestJavaDownloader::progress);
|
||||||
connect(download.get(), &NetJob::failed, this, &MojangJavaDownloader::emitFailed);
|
connect(download.get(), &NetJob::failed, this, &ManifestJavaDownloader::emitFailed);
|
||||||
connect(this, &Task::aborted, download.get(), &NetJob::abort);
|
connect(this, &Task::aborted, download.get(), &NetJob::abort);
|
||||||
|
|
||||||
connect(download.get(), &NetJob::succeeded, [files, this] {
|
connect(download.get(), &NetJob::succeeded, [files, this] {
|
||||||
@ -129,7 +58,7 @@ void MojangJavaDownloader::parseManifest(const QJsonArray& versionArray)
|
|||||||
download->start();
|
download->start();
|
||||||
};
|
};
|
||||||
|
|
||||||
void MojangJavaDownloader::downloadJava(const QJsonDocument& doc)
|
void ManifestJavaDownloader::downloadJava(const QJsonDocument& doc)
|
||||||
{
|
{
|
||||||
// valid json doc, begin making jre spot
|
// valid json doc, begin making jre spot
|
||||||
FS::ensureFolderPathExists(m_final_path);
|
FS::ensureFolderPathExists(m_final_path);
|
||||||
@ -176,10 +105,10 @@ void MojangJavaDownloader::downloadJava(const QJsonDocument& doc)
|
|||||||
disconnect(this, &Task::aborted, elementDownload, &NetJob::abort);
|
disconnect(this, &Task::aborted, elementDownload, &NetJob::abort);
|
||||||
elementDownload->deleteLater();
|
elementDownload->deleteLater();
|
||||||
});
|
});
|
||||||
connect(elementDownload, &NetJob::progress, this, &MojangJavaDownloader::progress);
|
connect(elementDownload, &NetJob::progress, this, &ManifestJavaDownloader::progress);
|
||||||
connect(elementDownload, &NetJob::failed, this, &MojangJavaDownloader::emitFailed);
|
connect(elementDownload, &NetJob::failed, this, &ManifestJavaDownloader::emitFailed);
|
||||||
|
|
||||||
connect(this, &Task::aborted, elementDownload, &NetJob::abort);
|
connect(this, &Task::aborted, elementDownload, &NetJob::abort);
|
||||||
connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
|
connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
|
||||||
elementDownload->start();
|
elementDownload->start();
|
||||||
};
|
};
|
@ -18,20 +18,24 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "java/providers/BasicJavaDownloader.h"
|
#include <QUrl>
|
||||||
|
#include "tasks/Task.h"
|
||||||
|
|
||||||
class MojangJavaDownloader : public BasicJavaDownloader {
|
class ManifestJavaDownloader : public Task {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
ManifestJavaDownloader(QUrl url, QString final_path);
|
||||||
|
virtual ~ManifestJavaDownloader() = default;
|
||||||
|
|
||||||
|
[[nodiscard]] bool canAbort() const override { return true; }
|
||||||
void executeTask() override;
|
void executeTask() override;
|
||||||
|
|
||||||
virtual QString name() const override { return "Mojang"; };
|
|
||||||
virtual bool isSupported() const override { return !getOS().isEmpty(); };
|
|
||||||
private slots:
|
private slots:
|
||||||
void downloadJavaList();
|
|
||||||
void parseManifest(const QJsonArray& versionArray);
|
|
||||||
void downloadJava(const QJsonDocument& doc);
|
void downloadJava(const QJsonDocument& doc);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
QString getOS() const;
|
QUrl m_url;
|
||||||
|
QString m_final_path;
|
||||||
|
|
||||||
|
Task::Ptr m_current_task;
|
||||||
};
|
};
|
@ -1,36 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
/*
|
|
||||||
* Prism Launcher - Minecraft Launcher
|
|
||||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "java/providers/BasicJavaDownloader.h"
|
|
||||||
|
|
||||||
class AdoptiumJavaDownloader : public BasicJavaDownloader {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
void executeTask() override;
|
|
||||||
|
|
||||||
virtual QString name() const override { return "Adoptium"; };
|
|
||||||
virtual bool isSupported() const override;
|
|
||||||
private slots:
|
|
||||||
void downloadJava();
|
|
||||||
void extractJava(QString input);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString getArch() const;
|
|
||||||
};
|
|
@ -1,159 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
/*
|
|
||||||
* Prism Launcher - Minecraft Launcher
|
|
||||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.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 "java/providers/AzulJavaDownloader.h"
|
|
||||||
#include <qcontainerfwd.h>
|
|
||||||
#include "MMCZip.h"
|
|
||||||
|
|
||||||
#include "Application.h"
|
|
||||||
#include "Json.h"
|
|
||||||
#include "net/NetJob.h"
|
|
||||||
#include "tasks/Task.h"
|
|
||||||
|
|
||||||
void AzulJavaDownloader::executeTask()
|
|
||||||
{
|
|
||||||
downloadJavaList();
|
|
||||||
};
|
|
||||||
|
|
||||||
void AzulJavaDownloader::downloadJavaList()
|
|
||||||
{
|
|
||||||
setStatus(tr("Querying Azul meta"));
|
|
||||||
|
|
||||||
auto javaVersion = m_is_legacy ? QString("8.0") : QString("17.0");
|
|
||||||
auto azulOS = m_os_name == "osx" ? "macos" : m_os_name;
|
|
||||||
auto arch = getArch();
|
|
||||||
auto metaResponse = std::make_shared<QByteArray>();
|
|
||||||
auto downloadJob = makeShared<NetJob>(QString("JRE::QueryAzulMeta"), APPLICATION->network());
|
|
||||||
downloadJob->addNetAction(Net::Download::makeByteArray(QString("https://api.azul.com/metadata/v1/zulu/packages/?"
|
|
||||||
"java_version=%1"
|
|
||||||
"&os=%2"
|
|
||||||
"&arch=%3"
|
|
||||||
"&archive_type=zip"
|
|
||||||
"&java_package_type=jre"
|
|
||||||
"&support_term=lts"
|
|
||||||
"&latest=true"
|
|
||||||
"status=ga"
|
|
||||||
"&availability_types=CA"
|
|
||||||
"&page=1"
|
|
||||||
"&page_size=1")
|
|
||||||
.arg(javaVersion, azulOS, arch),
|
|
||||||
metaResponse));
|
|
||||||
connect(downloadJob.get(), &NetJob::finished,
|
|
||||||
[downloadJob, metaResponse, this] { disconnect(this, &Task::aborted, downloadJob.get(), &NetJob::abort); });
|
|
||||||
connect(this, &Task::aborted, downloadJob.get(), &NetJob::abort);
|
|
||||||
connect(downloadJob.get(), &NetJob::failed, this, &AzulJavaDownloader::emitFailed);
|
|
||||||
connect(downloadJob.get(), &NetJob::progress, this, &AzulJavaDownloader::progress);
|
|
||||||
connect(downloadJob.get(), &NetJob::succeeded, [metaResponse, this] {
|
|
||||||
QJsonParseError parse_error{};
|
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*metaResponse, &parse_error);
|
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
|
||||||
qWarning() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
|
|
||||||
qWarning() << *metaResponse;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto array = Json::ensureArray(doc.array());
|
|
||||||
if (!array.empty()) {
|
|
||||||
downloadJava(array);
|
|
||||||
} else {
|
|
||||||
emitFailed(tr("No suitable JRE found"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
downloadJob->start();
|
|
||||||
};
|
|
||||||
|
|
||||||
QString AzulJavaDownloader::getArch() const
|
|
||||||
{
|
|
||||||
if (m_os_arch == "arm64")
|
|
||||||
return "aarch64";
|
|
||||||
if (m_os_arch == "arm")
|
|
||||||
return "aarch32";
|
|
||||||
if (m_os_arch.isEmpty())
|
|
||||||
return "x86";
|
|
||||||
return m_os_arch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AzulJavaDownloader::downloadJava(const QJsonArray& array)
|
|
||||||
{
|
|
||||||
// JRE found ! download the zip
|
|
||||||
setStatus(tr("Downloading Java from Azul"));
|
|
||||||
|
|
||||||
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("java", "azulJRE.zip");
|
|
||||||
|
|
||||||
auto downloadURL = QUrl(array[0].toObject()["url"].toString());
|
|
||||||
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
|
|
||||||
download->addNetAction(Net::Download::makeCached(downloadURL, entry));
|
|
||||||
auto fullPath = entry->getFullPath();
|
|
||||||
|
|
||||||
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
|
|
||||||
// connect(download.get(), &NetJob::aborted, [path] { APPLICATION->instances()->destroyStagingPath(path); });
|
|
||||||
connect(download.get(), &NetJob::progress, this, &AzulJavaDownloader::progress);
|
|
||||||
connect(download.get(), &NetJob::failed, this, &AzulJavaDownloader::emitFailed);
|
|
||||||
connect(this, &Task::aborted, download.get(), &NetJob::abort);
|
|
||||||
connect(download.get(), &NetJob::succeeded, [downloadURL, this, fullPath] {
|
|
||||||
// This should do all of the extracting and creating folders
|
|
||||||
extractJava(fullPath, downloadURL.fileName().chopped(4));
|
|
||||||
});
|
|
||||||
download->start();
|
|
||||||
};
|
|
||||||
|
|
||||||
void AzulJavaDownloader::extractJava(QString input, QString subdirectory)
|
|
||||||
{
|
|
||||||
setStatus(tr("Extracting java"));
|
|
||||||
auto zipTask = makeShared<MMCZip::ExtractZipTask>(input, m_final_path, subdirectory);
|
|
||||||
|
|
||||||
auto progressStep = std::make_shared<TaskStepProgress>();
|
|
||||||
connect(zipTask.get(), &Task::finished, this, [this, progressStep] {
|
|
||||||
progressStep->state = TaskStepState::Succeeded;
|
|
||||||
stepProgress(*progressStep);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(this, &Task::aborted, zipTask.get(), &Task::abort);
|
|
||||||
connect(zipTask.get(), &Task::finished, [zipTask, this] { disconnect(this, &Task::aborted, zipTask.get(), &Task::abort); });
|
|
||||||
|
|
||||||
connect(zipTask.get(), &Task::succeeded, this, &AzulJavaDownloader::emitSucceeded);
|
|
||||||
connect(zipTask.get(), &Task::aborted, this, &AzulJavaDownloader::emitAborted);
|
|
||||||
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
|
|
||||||
progressStep->state = TaskStepState::Failed;
|
|
||||||
stepProgress(*progressStep);
|
|
||||||
emitFailed(reason);
|
|
||||||
});
|
|
||||||
connect(zipTask.get(), &Task::stepProgress, this, &AzulJavaDownloader::propagateStepProgress);
|
|
||||||
|
|
||||||
connect(zipTask.get(), &Task::progress, this, [this, progressStep](qint64 current, qint64 total) {
|
|
||||||
progressStep->update(current, total);
|
|
||||||
stepProgress(*progressStep);
|
|
||||||
});
|
|
||||||
connect(zipTask.get(), &Task::status, this, [this, progressStep](QString status) {
|
|
||||||
progressStep->status = status;
|
|
||||||
stepProgress(*progressStep);
|
|
||||||
});
|
|
||||||
zipTask->start();
|
|
||||||
};
|
|
||||||
|
|
||||||
static const QStringList supportedOs = {
|
|
||||||
"macos", "linux", "windows", "linux-musl", "linux-glibc", "qnx", "solaris", "aix",
|
|
||||||
};
|
|
||||||
|
|
||||||
static const QStringList supportedArch = {
|
|
||||||
"x86", "x64", "amd64", "i686", "arm", "aarch64", "aarch32", "aarch32sf", "aarch32hf", "ppc",
|
|
||||||
"ppc64", "ppc32", "ppc32hf", "ppc32spe", "sparc", "sparc64", "sparc32", "sparcv9", "sparcv9-64", "sparcv9-32",
|
|
||||||
};
|
|
||||||
|
|
||||||
bool AzulJavaDownloader::isSupported() const
|
|
||||||
{
|
|
||||||
return supportedOs.contains(m_os_name == "osx" ? "macos" : m_os_name) && supportedArch.contains(getArch());
|
|
||||||
};
|
|
@ -1,37 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
/*
|
|
||||||
* Prism Launcher - Minecraft Launcher
|
|
||||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "java/providers/BasicJavaDownloader.h"
|
|
||||||
|
|
||||||
class AzulJavaDownloader : public BasicJavaDownloader {
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
void executeTask() override;
|
|
||||||
|
|
||||||
virtual QString name() const override { return "Azul"; };
|
|
||||||
virtual bool isSupported() const override;
|
|
||||||
private slots:
|
|
||||||
void downloadJavaList();
|
|
||||||
void downloadJava(const QJsonArray& doc);
|
|
||||||
void extractJava(QString input, QString subdirectory);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QString getArch() const;
|
|
||||||
};
|
|
@ -1,29 +0,0 @@
|
|||||||
// SPDX-License-Identifier: GPL-3.0-only
|
|
||||||
/*
|
|
||||||
* Prism Launcher - Minecraft Launcher
|
|
||||||
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.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 "java/providers/BasicJavaDownloader.h"
|
|
||||||
|
|
||||||
#include "SysInfo.h"
|
|
||||||
#include "tasks/Task.h"
|
|
||||||
|
|
||||||
BasicJavaDownloader::BasicJavaDownloader(QString final_path, bool m_is_legacy, QObject* parent)
|
|
||||||
: Task(parent)
|
|
||||||
, m_os_name(SysInfo::currentSystem())
|
|
||||||
, m_os_arch(SysInfo::useQTForArch())
|
|
||||||
, m_final_path(final_path)
|
|
||||||
, m_is_legacy(m_is_legacy)
|
|
||||||
{}
|
|
Loading…
Reference in New Issue
Block a user