Autodetect Java?

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97
2024-01-26 00:22:05 +02:00
parent f36be3f0e3
commit 81282bf7e0
8 changed files with 112 additions and 20 deletions

View File

@ -1,3 +1,21 @@
// 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/JavaRuntime.h"
#include <memory>
@ -23,6 +41,7 @@ QString downloadTypeToString(DownloadType javaDownload)
case DownloadType::Archive:
return "archive";
}
return "";
}
MetaPtr parseJavaMeta(const QJsonObject& in)
{

View File

@ -1,8 +1,27 @@
// 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 <QDateTime>
#include <QString>
#include <memory>
#include "java/JavaVersion.h"
namespace JavaRuntime {

View File

@ -393,6 +393,7 @@ QList<QString> JavaUtils::FindJavaPaths()
scanJavaDir(snap + dirPath);
}
};
scanJavaDir(FS::PathCombine(APPLICATION->dataRoot(), "java"));
// oracle RPMs
scanJavaDirs("/usr/java");
// general locations used by distro packaging

View File

@ -21,9 +21,13 @@
#include "MMCZip.h"
#include "Application.h"
#include "net/ChecksumValidator.h"
#include "net/NetJob.h"
#include "tasks/Task.h"
ArchiveJavaDownloader::ArchiveJavaDownloader(QUrl url, QString final_path, QString checksumType, QString checksumHash)
: m_url(url), m_final_path(final_path), m_checksum_type(checksumType), m_checksum_hash(checksumHash){};
void ArchiveJavaDownloader::executeTask()
{
// JRE found ! download the zip
@ -32,7 +36,15 @@ void ArchiveJavaDownloader::executeTask()
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("java", m_url.toLocalFile());
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
download->addNetAction(Net::Download::makeCached(m_url, entry));
auto action = Net::Download::makeCached(m_url, entry);
if (!m_checksum_hash.isEmpty() && !m_checksum_type.isEmpty()) {
auto hashType = QCryptographicHash::Algorithm::Sha1;
if (m_checksum_type == "sha256") {
hashType = QCryptographicHash::Algorithm::Sha256;
}
action->addValidator(new Net::ChecksumValidator(hashType, m_checksum_hash.toLatin1()));
}
download->addNetAction(action);
auto fullPath = entry->getFullPath();
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
@ -45,7 +57,7 @@ void ArchiveJavaDownloader::executeTask()
extractJava(fullPath);
});
download->start();
};
}
void ArchiveJavaDownloader::extractJava(QString input)
{
@ -85,4 +97,4 @@ void ArchiveJavaDownloader::extractJava(QString input)
stepProgress(*progressStep);
});
zipTask->start();
};
}

View File

@ -24,7 +24,7 @@
class ArchiveJavaDownloader : public Task {
Q_OBJECT
public:
ArchiveJavaDownloader(QUrl url, QString final_path);
ArchiveJavaDownloader(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
virtual ~ArchiveJavaDownloader() = default;
[[nodiscard]] bool canAbort() const override { return true; }
@ -36,6 +36,8 @@ class ArchiveJavaDownloader : public Task {
protected:
QUrl m_url;
QString m_final_path;
QString m_checksum_type;
QString m_checksum_hash;
Task::Ptr m_current_task;
};

View File

@ -30,14 +30,24 @@ struct File {
bool isExec;
};
ManifestJavaDownloader::ManifestJavaDownloader(QUrl url, QString final_path) : m_url(url), m_final_path(final_path){};
ManifestJavaDownloader::ManifestJavaDownloader(QUrl url, QString final_path, QString checksumType, QString checksumHash)
: m_url(url), m_final_path(final_path), m_checksum_type(checksumType), m_checksum_hash(checksumHash){};
void ManifestJavaDownloader::executeTask()
{
setStatus(tr("Downloading Java"));
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
auto files = std::make_shared<QByteArray>();
download->addNetAction(Net::Download::makeByteArray(m_url, files));
auto action = Net::Download::makeByteArray(m_url, files);
if (!m_checksum_hash.isEmpty() && !m_checksum_type.isEmpty()) {
auto hashType = QCryptographicHash::Algorithm::Sha1;
if (m_checksum_type == "sha256") {
hashType = QCryptographicHash::Algorithm::Sha256;
}
action->addValidator(new Net::ChecksumValidator(hashType, m_checksum_hash.toLatin1()));
}
download->addNetAction(action);
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
connect(download.get(), &NetJob::progress, this, &ManifestJavaDownloader::progress);
@ -56,7 +66,7 @@ void ManifestJavaDownloader::executeTask()
downloadJava(doc);
});
download->start();
};
}
void ManifestJavaDownloader::downloadJava(const QJsonDocument& doc)
{
@ -111,4 +121,4 @@ void ManifestJavaDownloader::downloadJava(const QJsonDocument& doc)
connect(this, &Task::aborted, elementDownload, &NetJob::abort);
connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
elementDownload->start();
};
}

View File

@ -24,7 +24,7 @@
class ManifestJavaDownloader : public Task {
Q_OBJECT
public:
ManifestJavaDownloader(QUrl url, QString final_path);
ManifestJavaDownloader(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
virtual ~ManifestJavaDownloader() = default;
[[nodiscard]] bool canAbort() const override { return true; }
@ -36,6 +36,8 @@ class ManifestJavaDownloader : public Task {
protected:
QUrl m_url;
QString m_final_path;
QString m_checksum_type;
QString m_checksum_hash;
Task::Ptr m_current_task;
};