mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 13:17:41 +02:00
Started workin on stuff
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
@ -40,14 +40,13 @@
|
||||
#include <QMap>
|
||||
#include <QProcess>
|
||||
|
||||
#include "Application.h"
|
||||
#include "Commandline.h"
|
||||
#include "FileSystem.h"
|
||||
#include "JavaUtils.h"
|
||||
#include "java/JavaUtils.h"
|
||||
|
||||
JavaChecker::JavaChecker(QObject* parent) : QObject(parent) {}
|
||||
JavaChecker::JavaChecker(QString path, QString args, int minMem, int maxMem, int permGen, int id, QObject* parent)
|
||||
: Task(parent), m_path(path), m_args(args), m_minMem(minMem), m_maxMem(maxMem), m_permGen(permGen), m_id(id){};
|
||||
|
||||
void JavaChecker::performCheck()
|
||||
void JavaChecker::executeTask()
|
||||
{
|
||||
QString checkerJar = JavaUtils::getJavaCheckPath();
|
||||
|
||||
@ -69,7 +68,7 @@ void JavaChecker::performCheck()
|
||||
if (m_maxMem != 0) {
|
||||
args << QString("-Xmx%1m").arg(m_maxMem);
|
||||
}
|
||||
if (m_permGen != 64) {
|
||||
if (m_permGen != 64 && m_permGen != 0) {
|
||||
args << QString("-XX:PermSize=%1m").arg(m_permGen);
|
||||
}
|
||||
|
||||
@ -112,11 +111,10 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
QProcessPtr _process = process;
|
||||
process.reset();
|
||||
|
||||
JavaCheckResult result;
|
||||
{
|
||||
result.path = m_path;
|
||||
result.id = m_id;
|
||||
}
|
||||
Result result = {
|
||||
m_path,
|
||||
m_id,
|
||||
};
|
||||
result.errorLog = m_stderr;
|
||||
result.outLog = m_stdout;
|
||||
qDebug() << "STDOUT" << m_stdout;
|
||||
@ -124,8 +122,9 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
qDebug() << "Java checker finished with status" << status << "exit code" << exitcode;
|
||||
|
||||
if (status == QProcess::CrashExit || exitcode == 1) {
|
||||
result.validity = JavaCheckResult::Validity::Errored;
|
||||
result.validity = Result::Validity::Errored;
|
||||
emit checkFinished(result);
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -158,8 +157,9 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
}
|
||||
|
||||
if (!results.contains("os.arch") || !results.contains("java.version") || !results.contains("java.vendor") || !success) {
|
||||
result.validity = JavaCheckResult::Validity::ReturnedInvalidData;
|
||||
result.validity = Result::Validity::ReturnedInvalidData;
|
||||
emit checkFinished(result);
|
||||
emitSucceeded();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
auto java_vendor = results["java.vendor"];
|
||||
bool is_64 = os_arch == "x86_64" || os_arch == "amd64" || os_arch == "aarch64" || os_arch == "arm64";
|
||||
|
||||
result.validity = JavaCheckResult::Validity::Valid;
|
||||
result.validity = Result::Validity::Valid;
|
||||
result.is_64bit = is_64;
|
||||
result.mojangPlatform = is_64 ? "64" : "32";
|
||||
result.realPlatform = os_arch;
|
||||
@ -176,6 +176,7 @@ void JavaChecker::finished(int exitcode, QProcess::ExitStatus status)
|
||||
result.javaVendor = java_vendor;
|
||||
qDebug() << "Java checker succeeded.";
|
||||
emit checkFinished(result);
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void JavaChecker::error(QProcess::ProcessError err)
|
||||
@ -187,15 +188,9 @@ void JavaChecker::error(QProcess::ProcessError err)
|
||||
qDebug() << "Native environment:";
|
||||
qDebug() << QProcessEnvironment::systemEnvironment().toStringList();
|
||||
killTimer.stop();
|
||||
JavaCheckResult result;
|
||||
{
|
||||
result.path = m_path;
|
||||
result.id = m_id;
|
||||
}
|
||||
|
||||
emit checkFinished(result);
|
||||
return;
|
||||
emit checkFinished({ m_path, m_id });
|
||||
}
|
||||
emitSucceeded();
|
||||
}
|
||||
|
||||
void JavaChecker::timeout()
|
||||
|
@ -3,49 +3,51 @@
|
||||
#include <QTimer>
|
||||
#include <memory>
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
|
||||
#include "JavaVersion.h"
|
||||
#include "QObjectPtr.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
class JavaChecker;
|
||||
|
||||
struct JavaCheckResult {
|
||||
QString path;
|
||||
QString mojangPlatform;
|
||||
QString realPlatform;
|
||||
JavaVersion javaVersion;
|
||||
QString javaVendor;
|
||||
QString outLog;
|
||||
QString errorLog;
|
||||
bool is_64bit = false;
|
||||
int id;
|
||||
enum class Validity { Errored, ReturnedInvalidData, Valid } validity = Validity::Errored;
|
||||
};
|
||||
|
||||
using QProcessPtr = shared_qobject_ptr<QProcess>;
|
||||
using JavaCheckerPtr = shared_qobject_ptr<JavaChecker>;
|
||||
class JavaChecker : public QObject {
|
||||
class JavaChecker : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit JavaChecker(QObject* parent = 0);
|
||||
void performCheck();
|
||||
using QProcessPtr = shared_qobject_ptr<QProcess>;
|
||||
using Ptr = shared_qobject_ptr<JavaChecker>;
|
||||
|
||||
QString m_path;
|
||||
QString m_args;
|
||||
int m_id = 0;
|
||||
int m_minMem = 0;
|
||||
int m_maxMem = 0;
|
||||
int m_permGen = 64;
|
||||
struct Result {
|
||||
QString path;
|
||||
int id;
|
||||
QString mojangPlatform;
|
||||
QString realPlatform;
|
||||
JavaVersion javaVersion;
|
||||
QString javaVendor;
|
||||
QString outLog;
|
||||
QString errorLog;
|
||||
bool is_64bit = false;
|
||||
enum class Validity { Errored, ReturnedInvalidData, Valid } validity = Validity::Errored;
|
||||
};
|
||||
|
||||
explicit JavaChecker(QString path, QString args, int minMem = 0, int maxMem = 0, int permGen = 0, int id = 0, QObject* parent = 0);
|
||||
|
||||
signals:
|
||||
void checkFinished(JavaCheckResult result);
|
||||
void checkFinished(Result result);
|
||||
|
||||
protected:
|
||||
virtual void executeTask() override;
|
||||
|
||||
private:
|
||||
QProcessPtr process;
|
||||
QTimer killTimer;
|
||||
QString m_stdout;
|
||||
QString m_stderr;
|
||||
public slots:
|
||||
|
||||
QString m_path;
|
||||
QString m_args;
|
||||
int m_minMem = 0;
|
||||
int m_maxMem = 0;
|
||||
int m_permGen = 64;
|
||||
int m_id = 0;
|
||||
|
||||
private slots:
|
||||
void timeout();
|
||||
void finished(int exitcode, QProcess::ExitStatus);
|
||||
void error(QProcess::ProcessError);
|
||||
|
@ -1,41 +0,0 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "JavaCheckerJob.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
void JavaCheckerJob::partFinished(JavaCheckResult result)
|
||||
{
|
||||
num_finished++;
|
||||
qDebug() << m_job_name.toLocal8Bit() << "progress:" << num_finished << "/" << javacheckers.size();
|
||||
setProgress(num_finished, javacheckers.size());
|
||||
|
||||
javaresults.replace(result.id, result);
|
||||
|
||||
if (num_finished == javacheckers.size()) {
|
||||
emitSucceeded();
|
||||
}
|
||||
}
|
||||
|
||||
void JavaCheckerJob::executeTask()
|
||||
{
|
||||
qDebug() << m_job_name.toLocal8Bit() << " started.";
|
||||
for (auto iter : javacheckers) {
|
||||
javaresults.append(JavaCheckResult());
|
||||
connect(iter.get(), &JavaChecker::checkFinished, this, &JavaCheckerJob::partFinished);
|
||||
iter->performCheck();
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QtNetwork>
|
||||
#include "JavaChecker.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
class JavaCheckerJob;
|
||||
using JavaCheckerJobPtr = shared_qobject_ptr<JavaCheckerJob>;
|
||||
|
||||
// FIXME: this just seems horribly redundant
|
||||
class JavaCheckerJob : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit JavaCheckerJob(QString job_name) : Task(), m_job_name(job_name){};
|
||||
virtual ~JavaCheckerJob(){};
|
||||
|
||||
bool addJavaCheckerAction(JavaCheckerPtr base)
|
||||
{
|
||||
javacheckers.append(base);
|
||||
// if this is already running, the action needs to be started right away!
|
||||
if (isRunning()) {
|
||||
setProgress(num_finished, javacheckers.size());
|
||||
connect(base.get(), &JavaChecker::checkFinished, this, &JavaCheckerJob::partFinished);
|
||||
base->performCheck();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
QList<JavaCheckResult> getResults() { return javaresults; }
|
||||
|
||||
private slots:
|
||||
void partFinished(JavaCheckResult result);
|
||||
|
||||
protected:
|
||||
virtual void executeTask() override;
|
||||
|
||||
private:
|
||||
QString m_job_name;
|
||||
QList<JavaCheckerPtr> javacheckers;
|
||||
QList<JavaCheckResult> javaresults;
|
||||
int num_finished = 0;
|
||||
};
|
@ -38,11 +38,13 @@
|
||||
#include <QtXml>
|
||||
|
||||
#include <QDebug>
|
||||
#include <algorithm>
|
||||
|
||||
#include "java/JavaCheckerJob.h"
|
||||
#include "Application.h"
|
||||
#include "java/JavaChecker.h"
|
||||
#include "java/JavaInstallList.h"
|
||||
#include "java/JavaUtils.h"
|
||||
#include "minecraft/VersionFilterData.h"
|
||||
#include "tasks/ConcurrentTask.h"
|
||||
|
||||
JavaInstallList::JavaInstallList(QObject* parent) : BaseVersionList(parent) {}
|
||||
|
||||
@ -55,7 +57,7 @@ Task::Ptr JavaInstallList::getLoadTask()
|
||||
Task::Ptr JavaInstallList::getCurrentTask()
|
||||
{
|
||||
if (m_status == Status::InProgress) {
|
||||
return m_loadTask;
|
||||
return m_load_task;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -64,8 +66,8 @@ void JavaInstallList::load()
|
||||
{
|
||||
if (m_status != Status::InProgress) {
|
||||
m_status = Status::InProgress;
|
||||
m_loadTask.reset(new JavaListLoadTask(this));
|
||||
m_loadTask->start();
|
||||
m_load_task.reset(new JavaListLoadTask(this));
|
||||
m_load_task->start();
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,7 +131,7 @@ void JavaInstallList::updateListData(QList<BaseVersion::Ptr> versions)
|
||||
}
|
||||
endResetModel();
|
||||
m_status = Status::Done;
|
||||
m_loadTask.reset();
|
||||
m_load_task.reset();
|
||||
}
|
||||
|
||||
bool sortJavas(BaseVersion::Ptr left, BaseVersion::Ptr right)
|
||||
@ -149,11 +151,9 @@ void JavaInstallList::sortVersions()
|
||||
JavaListLoadTask::JavaListLoadTask(JavaInstallList* vlist) : Task()
|
||||
{
|
||||
m_list = vlist;
|
||||
m_currentRecommended = NULL;
|
||||
m_current_recommended = NULL;
|
||||
}
|
||||
|
||||
JavaListLoadTask::~JavaListLoadTask() {}
|
||||
|
||||
void JavaListLoadTask::executeTask()
|
||||
{
|
||||
setStatus(tr("Detecting Java installations..."));
|
||||
@ -161,20 +161,17 @@ void JavaListLoadTask::executeTask()
|
||||
JavaUtils ju;
|
||||
QList<QString> candidate_paths = ju.FindJavaPaths();
|
||||
|
||||
m_job.reset(new JavaCheckerJob("Java detection"));
|
||||
ConcurrentTask::Ptr job(new ConcurrentTask(this, "Java detection", APPLICATION->settings()->get("NumberOfConcurrentTasks").toInt()));
|
||||
m_job.reset(job);
|
||||
connect(m_job.get(), &Task::finished, this, &JavaListLoadTask::javaCheckerFinished);
|
||||
connect(m_job.get(), &Task::progress, this, &Task::setProgress);
|
||||
|
||||
qDebug() << "Probing the following Java paths: ";
|
||||
int id = 0;
|
||||
for (QString candidate : candidate_paths) {
|
||||
qDebug() << " " << candidate;
|
||||
|
||||
auto candidate_checker = new JavaChecker();
|
||||
candidate_checker->m_path = candidate;
|
||||
candidate_checker->m_id = id;
|
||||
m_job->addJavaCheckerAction(JavaCheckerPtr(candidate_checker));
|
||||
|
||||
auto checker = new JavaChecker(candidate, "", 0, 0, 0, id, this);
|
||||
connect(checker, &JavaChecker::checkFinished, [this](JavaChecker::Result result) { m_results << result; });
|
||||
job->addTask(Task::Ptr(checker));
|
||||
id++;
|
||||
}
|
||||
|
||||
@ -184,11 +181,11 @@ void JavaListLoadTask::executeTask()
|
||||
void JavaListLoadTask::javaCheckerFinished()
|
||||
{
|
||||
QList<JavaInstallPtr> candidates;
|
||||
auto results = m_job->getResults();
|
||||
std::sort(m_results.begin(), m_results.end(), [](JavaChecker::Result a, JavaChecker::Result b) { return a.id < b.id; });
|
||||
|
||||
qDebug() << "Found the following valid Java installations:";
|
||||
for (JavaCheckResult result : results) {
|
||||
if (result.validity == JavaCheckResult::Validity::Valid) {
|
||||
for (auto result : m_results) {
|
||||
if (result.validity == JavaChecker::Result::Validity::Valid) {
|
||||
JavaInstallPtr javaVersion(new JavaInstall());
|
||||
|
||||
javaVersion->id = result.javaVersion;
|
||||
|
@ -19,9 +19,9 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "BaseVersionList.h"
|
||||
#include "java/JavaChecker.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include "JavaCheckerJob.h"
|
||||
#include "JavaInstall.h"
|
||||
|
||||
#include "QObjectPtr.h"
|
||||
@ -53,7 +53,7 @@ class JavaInstallList : public BaseVersionList {
|
||||
|
||||
protected:
|
||||
Status m_status = Status::NotDone;
|
||||
shared_qobject_ptr<JavaListLoadTask> m_loadTask;
|
||||
shared_qobject_ptr<JavaListLoadTask> m_load_task;
|
||||
QList<BaseVersion::Ptr> m_vlist;
|
||||
};
|
||||
|
||||
@ -62,14 +62,16 @@ class JavaListLoadTask : public Task {
|
||||
|
||||
public:
|
||||
explicit JavaListLoadTask(JavaInstallList* vlist);
|
||||
virtual ~JavaListLoadTask();
|
||||
virtual ~JavaListLoadTask() = default;
|
||||
|
||||
protected:
|
||||
void executeTask() override;
|
||||
public slots:
|
||||
void javaCheckerFinished();
|
||||
|
||||
protected:
|
||||
shared_qobject_ptr<JavaCheckerJob> m_job;
|
||||
Task::Ptr m_job;
|
||||
JavaInstallList* m_list;
|
||||
JavaInstall* m_currentRecommended;
|
||||
JavaInstall* m_current_recommended;
|
||||
QList<JavaChecker::Result> m_results;
|
||||
};
|
||||
|
@ -15,10 +15,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QProcess>
|
||||
#include <QStringList>
|
||||
|
||||
#include "JavaChecker.h"
|
||||
#include "JavaInstallList.h"
|
||||
#include "java/JavaInstall.h"
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <windows.h>
|
||||
|
119
launcher/java/providers/AdoptiumJavaDownloader.cpp
Normal file
119
launcher/java/providers/AdoptiumJavaDownloader.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
// 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/AdoptiumJavaDownloader.h"
|
||||
#include <quazip.h>
|
||||
#include <memory>
|
||||
#include "MMCZip.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "net/NetJob.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
void AdoptiumJavaDownloader::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
|
||||
setStatus(tr("Downloading Java from Adoptium"));
|
||||
|
||||
auto javaVersion = m_is_legacy ? QString("8") : QString("17");
|
||||
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());
|
||||
download->addNetAction(Net::Download::makeCached(
|
||||
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();
|
||||
|
||||
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, &AdoptiumJavaDownloader::progress);
|
||||
connect(download.get(), &NetJob::failed, this, &AdoptiumJavaDownloader::emitFailed);
|
||||
connect(this, &Task::aborted, download.get(), &NetJob::abort);
|
||||
connect(download.get(), &NetJob::succeeded, [this, fullPath] {
|
||||
// This should do all of the extracting and creating folders
|
||||
extractJava(fullPath);
|
||||
});
|
||||
download->start();
|
||||
};
|
||||
|
||||
void AdoptiumJavaDownloader::extractJava(QString input)
|
||||
{
|
||||
setStatus(tr("Extracting java"));
|
||||
auto zip = std::make_shared<QuaZip>(input);
|
||||
auto files = zip->getFileNameList();
|
||||
if (files.isEmpty()) {
|
||||
emitFailed("Empty archive");
|
||||
return;
|
||||
}
|
||||
auto zipTask = makeShared<MMCZip::ExtractZipTask>(input, m_final_path, files[0]);
|
||||
|
||||
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, &AdoptiumJavaDownloader::emitSucceeded);
|
||||
connect(zipTask.get(), &Task::aborted, this, &AdoptiumJavaDownloader::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, &AdoptiumJavaDownloader::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 = {
|
||||
"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());
|
||||
};
|
36
launcher/java/providers/AdoptiumJavaDownloader.h
Normal file
36
launcher/java/providers/AdoptiumJavaDownloader.h
Normal file
@ -0,0 +1,36 @@
|
||||
// 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;
|
||||
};
|
159
launcher/java/providers/AzulJavaDownloader.cpp
Normal file
159
launcher/java/providers/AzulJavaDownloader.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
// 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());
|
||||
};
|
37
launcher/java/providers/AzulJavaDownloader.h
Normal file
37
launcher/java/providers/AzulJavaDownloader.h
Normal file
@ -0,0 +1,37 @@
|
||||
// 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;
|
||||
};
|
29
launcher/java/providers/BasicJavaDownloader.cpp
Normal file
29
launcher/java/providers/BasicJavaDownloader.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
// 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)
|
||||
{}
|
41
launcher/java/providers/BasicJavaDownloader.h
Normal file
41
launcher/java/providers/BasicJavaDownloader.h
Normal file
@ -0,0 +1,41 @@
|
||||
// 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 "tasks/Task.h"
|
||||
|
||||
class BasicJavaDownloader : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
BasicJavaDownloader(QString final_path, bool m_is_legacy = false, QObject* parent = nullptr);
|
||||
virtual ~BasicJavaDownloader() = default;
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
|
||||
virtual QString name() const = 0;
|
||||
virtual bool isSupported() const = 0;
|
||||
|
||||
protected:
|
||||
QString m_os_name;
|
||||
QString m_os_arch;
|
||||
QString m_final_path;
|
||||
bool m_is_legacy;
|
||||
|
||||
Task::Ptr m_current_task;
|
||||
};
|
185
launcher/java/providers/MojangJavaDownloader.cpp
Normal file
185
launcher/java/providers/MojangJavaDownloader.cpp
Normal file
@ -0,0 +1,185 @@
|
||||
// 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/MojanglJavaDownloader.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "FileSystem.h"
|
||||
#include "Json.h"
|
||||
#include "net/ChecksumValidator.h"
|
||||
#include "net/NetJob.h"
|
||||
|
||||
struct File {
|
||||
QString path;
|
||||
QString url;
|
||||
QByteArray hash;
|
||||
bool isExec;
|
||||
};
|
||||
|
||||
void MojangJavaDownloader::executeTask()
|
||||
{
|
||||
downloadJavaList();
|
||||
};
|
||||
|
||||
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 files = std::make_shared<QByteArray>();
|
||||
|
||||
download->addNetAction(Net::Download::makeByteArray(QUrl(url), files));
|
||||
|
||||
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::failed, this, &MojangJavaDownloader::emitFailed);
|
||||
connect(this, &Task::aborted, download.get(), &NetJob::abort);
|
||||
|
||||
connect(download.get(), &NetJob::succeeded, [files, this] {
|
||||
QJsonParseError parse_error{};
|
||||
QJsonDocument doc = QJsonDocument::fromJson(*files, &parse_error);
|
||||
if (parse_error.error != QJsonParseError::NoError) {
|
||||
qWarning() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
|
||||
qWarning() << *files;
|
||||
emitFailed(parse_error.errorString());
|
||||
return;
|
||||
}
|
||||
downloadJava(doc);
|
||||
});
|
||||
download->start();
|
||||
};
|
||||
|
||||
void MojangJavaDownloader::downloadJava(const QJsonDocument& doc)
|
||||
{
|
||||
// valid json doc, begin making jre spot
|
||||
FS::ensureFolderPathExists(m_final_path);
|
||||
std::vector<File> toDownload;
|
||||
auto list = Json::ensureObject(Json::ensureObject(doc.object()), "files");
|
||||
for (const auto& paths : list.keys()) {
|
||||
auto file = FS::PathCombine(m_final_path, paths);
|
||||
|
||||
const QJsonObject& meta = Json::ensureObject(list, paths);
|
||||
auto type = Json::ensureString(meta, "type");
|
||||
if (type == "directory") {
|
||||
FS::ensureFolderPathExists(file);
|
||||
} else if (type == "link") {
|
||||
// this is linux only !
|
||||
auto path = Json::ensureString(meta, "target");
|
||||
if (!path.isEmpty()) {
|
||||
auto target = FS::PathCombine(file, "../" + path);
|
||||
QFile(target).link(file);
|
||||
}
|
||||
} else if (type == "file") {
|
||||
// TODO download compressed version if it exists ?
|
||||
auto raw = Json::ensureObject(Json::ensureObject(meta, "downloads"), "raw");
|
||||
auto isExec = Json::ensureBoolean(meta, "executable", false);
|
||||
auto url = Json::ensureString(raw, "url");
|
||||
if (!url.isEmpty() && QUrl(url).isValid()) {
|
||||
auto f = File{ file, url, QByteArray::fromHex(Json::ensureString(raw, "sha1").toLatin1()), isExec };
|
||||
toDownload.push_back(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
auto elementDownload = new NetJob("JRE::FileDownload", APPLICATION->network());
|
||||
for (const auto& file : toDownload) {
|
||||
auto dl = Net::Download::makeFile(file.url, file.path);
|
||||
if (!file.hash.isEmpty()) {
|
||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, file.hash));
|
||||
}
|
||||
if (file.isExec) {
|
||||
connect(dl.get(), &Net::Download::succeeded,
|
||||
[file] { QFile(file.path).setPermissions(QFile(file.path).permissions() | QFileDevice::Permissions(0x1111)); });
|
||||
}
|
||||
elementDownload->addNetAction(dl);
|
||||
}
|
||||
connect(elementDownload, &NetJob::finished, [elementDownload, this] {
|
||||
disconnect(this, &Task::aborted, elementDownload, &NetJob::abort);
|
||||
elementDownload->deleteLater();
|
||||
});
|
||||
connect(elementDownload, &NetJob::progress, this, &MojangJavaDownloader::progress);
|
||||
connect(elementDownload, &NetJob::failed, this, &MojangJavaDownloader::emitFailed);
|
||||
|
||||
connect(this, &Task::aborted, elementDownload, &NetJob::abort);
|
||||
connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
|
||||
elementDownload->start();
|
||||
};
|
37
launcher/java/providers/MojanglJavaDownloader.h
Normal file
37
launcher/java/providers/MojanglJavaDownloader.h
Normal file
@ -0,0 +1,37 @@
|
||||
// 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 MojangJavaDownloader : public BasicJavaDownloader {
|
||||
Q_OBJECT
|
||||
public:
|
||||
void executeTask() override;
|
||||
|
||||
virtual QString name() const override { return "Mojang"; };
|
||||
virtual bool isSupported() const override { return !getOS().isEmpty(); };
|
||||
private slots:
|
||||
void downloadJavaList();
|
||||
void parseManifest(const QJsonArray& versionArray);
|
||||
void downloadJava(const QJsonDocument& doc);
|
||||
|
||||
private:
|
||||
QString getOS() const;
|
||||
};
|
Reference in New Issue
Block a user