Fix Java downloader bugs + Add a test button in JavaPage
Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
parent
98a82cd484
commit
89ce80b279
@ -1,6 +1,7 @@
|
|||||||
#include "JavaDownloader.h"
|
#include "JavaDownloader.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
#include "Json.h"
|
||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
#include "net/ChecksumValidator.h"
|
#include "net/ChecksumValidator.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
@ -11,6 +12,7 @@ struct File {
|
|||||||
QString path;
|
QString path;
|
||||||
QString url;
|
QString url;
|
||||||
QByteArray hash;
|
QByteArray hash;
|
||||||
|
bool isExec;
|
||||||
};
|
};
|
||||||
|
|
||||||
void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
||||||
@ -23,7 +25,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
|||||||
netJob->deleteLater();
|
netJob->deleteLater();
|
||||||
delete response;
|
delete response;
|
||||||
});
|
});
|
||||||
QObject::connect(netJob, &NetJob::succeeded, [response, &OS, isLegacy] {
|
QObject::connect(netJob, &NetJob::succeeded, [response, OS, isLegacy] {
|
||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*response, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
@ -31,7 +33,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
|||||||
qWarning() << *response;
|
qWarning() << *response;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto versionArray = doc.object()[OS].toObject()[isLegacy ? "jre-legacy" : "java-runtime-gamma"].toArray();
|
auto versionArray = Json::ensureArray(Json::ensureObject(doc.object(), OS), isLegacy ? "jre-legacy" : "java-runtime-gamma");
|
||||||
if (!versionArray.empty()) {
|
if (!versionArray.empty()) {
|
||||||
auto url = versionArray[0].toObject()["manifest"].toObject()["url"].toString();
|
auto url = versionArray[0].toObject()["manifest"].toObject()["url"].toString();
|
||||||
auto download = new NetJob(QString("JRE::DownloadJava"), APPLICATION->network());
|
auto download = new NetJob(QString("JRE::DownloadJava"), APPLICATION->network());
|
||||||
@ -53,35 +55,37 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// valid json doc, begin making jre spot
|
// valid json doc, begin making jre spot
|
||||||
auto output =
|
auto output = FS::PathCombine(QString("java"), (isLegacy ? "java-legacy" : "java-current"));
|
||||||
FS::PathCombine(QCoreApplication::applicationDirPath(), QString("java/") + (isLegacy ? "java-legacy" : "java-current"));
|
|
||||||
FS::ensureFolderPathExists(output);
|
FS::ensureFolderPathExists(output);
|
||||||
std::vector<File> toDownload;
|
std::vector<File> toDownload;
|
||||||
auto list = doc.object()["files"].toObject();
|
auto list = doc.object()["files"].toObject();
|
||||||
for (auto element : list) {
|
for (const auto& paths : list.keys()) {
|
||||||
auto obj = element.toObject();
|
auto file = FS::PathCombine(output, paths);
|
||||||
for (const auto& paths : obj.keys()) {
|
|
||||||
auto file = FS::PathCombine(output, paths);
|
|
||||||
|
|
||||||
auto type = obj[paths].toObject()["type"].toString();
|
auto type = list[paths].toObject()["type"].toString();
|
||||||
if (type == "directory") {
|
if (type == "directory") {
|
||||||
FS::ensureFolderPathExists(file);
|
FS::ensureFolderPathExists(file);
|
||||||
} else if (type == "link") {
|
} else if (type == "link") {
|
||||||
// this is linux only !
|
// this is linux only !
|
||||||
auto target = FS::PathCombine(file, "../" + obj[paths].toObject()["target"].toString());
|
auto target = FS::PathCombine(file, "../" + list[paths].toObject()["target"].toString());
|
||||||
QFile(target).link(file);
|
QFile(target).link(file);
|
||||||
} else if (type == "file") {
|
} else if (type == "file") {
|
||||||
// TODO download compressed version if it exists ?
|
// TODO download compressed version if it exists ?
|
||||||
auto raw = obj[paths].toObject()["downloads"].toObject()["raw"].toObject();
|
auto raw = list[paths].toObject()["downloads"].toObject()["raw"].toObject();
|
||||||
auto f = File{ file, raw["url"].toString(), QByteArray::fromHex(raw["sha1"].toString().toLatin1()) };
|
auto isExec = list[paths].toObject()["executable"].toBool();
|
||||||
toDownload.push_back(f);
|
auto f = File{ file, raw["url"].toString(), QByteArray::fromHex(raw["sha1"].toString().toLatin1()), isExec };
|
||||||
}
|
toDownload.push_back(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto elementDownload = new NetJob("JRE::FileDownload", APPLICATION->network());
|
auto elementDownload = new NetJob("JRE::FileDownload", APPLICATION->network());
|
||||||
for (const auto& file : toDownload) {
|
for (const auto& file : toDownload) {
|
||||||
auto dl = Net::Download::makeFile(file.url, file.path);
|
auto dl = Net::Download::makeFile(file.url, file.path);
|
||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, file.hash));
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, file.hash));
|
||||||
|
if (file.isExec) {
|
||||||
|
QObject::connect(dl.get(), &Net::Download::succeeded, [file] {
|
||||||
|
QFile(file.path).setPermissions(QFile(file.path).permissions() | QFileDevice::Permissions(0x1111));
|
||||||
|
});
|
||||||
|
}
|
||||||
elementDownload->addNetAction(dl);
|
elementDownload->addNetAction(dl);
|
||||||
}
|
}
|
||||||
QObject::connect(elementDownload, &NetJob::finished, [elementDownload] { elementDownload->deleteLater(); });
|
QObject::connect(elementDownload, &NetJob::finished, [elementDownload] { elementDownload->deleteLater(); });
|
||||||
@ -90,7 +94,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
|||||||
download->start();
|
download->start();
|
||||||
} else {
|
} else {
|
||||||
// mojang does not have a JRE for us, let's get azul zulu
|
// mojang does not have a JRE for us, let's get azul zulu
|
||||||
QString javaVersion = isLegacy ? QString("8.0") : QString("17.0");
|
QString javaVersion = isLegacy ? QString("8.0") : QString("18.0");
|
||||||
QString azulOS;
|
QString azulOS;
|
||||||
QString arch;
|
QString arch;
|
||||||
QString bitness;
|
QString bitness;
|
||||||
@ -100,11 +104,16 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
|||||||
azulOS = "macos";
|
azulOS = "macos";
|
||||||
arch = "arm";
|
arch = "arm";
|
||||||
bitness = "64";
|
bitness = "64";
|
||||||
} else if (OS == "linux-aarch64") {
|
} else if (OS == "linux-arm64") {
|
||||||
// linux aarch64
|
// linux arm64
|
||||||
azulOS = "linux";
|
azulOS = "linux";
|
||||||
arch = "arm";
|
arch = "arm";
|
||||||
bitness = "64";
|
bitness = "64";
|
||||||
|
} else if (OS == "linux-arm") {
|
||||||
|
// linux arm (32)
|
||||||
|
azulOS = "linux";
|
||||||
|
arch = "arm";
|
||||||
|
bitness = "32";
|
||||||
}
|
}
|
||||||
auto metaResponse = new QByteArray();
|
auto metaResponse = new QByteArray();
|
||||||
auto downloadJob = new NetJob(QString("JRE::QueryAzulMeta"), APPLICATION->network());
|
auto downloadJob = new NetJob(QString("JRE::QueryAzulMeta"), APPLICATION->network());
|
||||||
@ -143,16 +152,18 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
|||||||
download->addNetAction(Net::Download::makeCached(downloadURL, entry));
|
download->addNetAction(Net::Download::makeCached(downloadURL, entry));
|
||||||
auto zippath = entry->getFullPath();
|
auto zippath = entry->getFullPath();
|
||||||
QObject::connect(download, &NetJob::finished, [download] { download->deleteLater(); });
|
QObject::connect(download, &NetJob::finished, [download] { download->deleteLater(); });
|
||||||
QObject::connect(download, &NetJob::succeeded, [isLegacy, zippath] {
|
QObject::connect(download, &NetJob::succeeded, [isLegacy, zippath, downloadURL] {
|
||||||
auto output = FS::PathCombine(FS::PathCombine(QCoreApplication::applicationDirPath(), "java"),
|
auto output = FS::PathCombine(FS::PathCombine(QCoreApplication::applicationDirPath(), "java"),
|
||||||
isLegacy ? "java-legacy" : "java-current");
|
isLegacy ? "java-legacy" : "java-current");
|
||||||
// This should do all of the extracting and creating folders
|
// This should do all of the extracting and creating folders
|
||||||
MMCZip::extractDir(zippath, output);
|
MMCZip::extractDir(zippath, downloadURL.fileName().chopped(4), output);
|
||||||
});
|
});
|
||||||
|
download->start();
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "No suitable JRE found !!";
|
qWarning() << "No suitable JRE found !!";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
downloadJob->start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -52,6 +52,9 @@
|
|||||||
#include <FileSystem.h>
|
#include <FileSystem.h>
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include <sys.h>
|
#include <sys.h>
|
||||||
|
#include "SysInfo.h"
|
||||||
|
#include "JavaDownloader.h"
|
||||||
|
|
||||||
|
|
||||||
JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage)
|
JavaPage::JavaPage(QWidget *parent) : QWidget(parent), ui(new Ui::JavaPage)
|
||||||
{
|
{
|
||||||
@ -177,6 +180,44 @@ void JavaPage::on_javaTestBtn_clicked()
|
|||||||
checker->run();
|
checker->run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JavaPage::on_javaDownloadBtn_clicked(){
|
||||||
|
QString sys = SysInfo::currentSystem();
|
||||||
|
if(sys == "osx"){
|
||||||
|
sys = "mac-os";
|
||||||
|
}
|
||||||
|
QString arch = SysInfo::useQTForArch();
|
||||||
|
QString version;
|
||||||
|
if(sys == "windows"){
|
||||||
|
if(arch == "x86_64"){
|
||||||
|
version = "windows-x64";
|
||||||
|
}else if(arch == "i386"){
|
||||||
|
version = "windows-x86";
|
||||||
|
}else{
|
||||||
|
//Unknown, maybe arm, appending arch for downloader
|
||||||
|
version = "windows-"+arch;
|
||||||
|
}
|
||||||
|
}else if(sys == "mac-os"){
|
||||||
|
if(arch == "arm64"){
|
||||||
|
version = "mac-os-arm64";
|
||||||
|
}else{
|
||||||
|
version = "mac-os";
|
||||||
|
}
|
||||||
|
}else if(sys == "linux"){
|
||||||
|
if(arch == "x86_64"){
|
||||||
|
version = "linux";
|
||||||
|
}else {
|
||||||
|
// will work for i386, and arm(64)
|
||||||
|
version = "linux-" + arch;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
// ? ? ? ? ? unknown os, at least it won't have a java version on mojang or azul, display warning
|
||||||
|
QMessageBox::warning(this, tr("Unknown OS"), tr("The OS you are running is not supported by Mojang or Azul. Please install Java manually."));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//TODO display a selection for java 8 or 18
|
||||||
|
JavaDownloader::downloadJava(false, version);
|
||||||
|
}
|
||||||
|
|
||||||
void JavaPage::checkerFinished()
|
void JavaPage::checkerFinished()
|
||||||
{
|
{
|
||||||
checker.reset();
|
checker.reset();
|
||||||
|
@ -85,6 +85,7 @@ slots:
|
|||||||
void on_javaDetectBtn_clicked();
|
void on_javaDetectBtn_clicked();
|
||||||
void on_javaTestBtn_clicked();
|
void on_javaTestBtn_clicked();
|
||||||
void on_javaBrowseBtn_clicked();
|
void on_javaBrowseBtn_clicked();
|
||||||
|
void on_javaDownloadBtn_clicked();
|
||||||
void checkerFinished();
|
void checkerFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>545</width>
|
<width>559</width>
|
||||||
<height>580</height>
|
<height>659</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -279,6 +279,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QPushButton" name="javaDownloadBtn">
|
||||||
|
<property name="text">
|
||||||
|
<string>Download Java</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user