Clang format
Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
parent
3433c102b7
commit
9a4a92de4f
@ -1,10 +1,10 @@
|
|||||||
#include "JavaDownloader.h"
|
#include "JavaDownloader.h"
|
||||||
#include "net/NetJob.h"
|
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
#include "quazip.h"
|
|
||||||
#include "MMCZip.h"
|
#include "MMCZip.h"
|
||||||
#include "net/ChecksumValidator.h"
|
#include "net/ChecksumValidator.h"
|
||||||
|
#include "net/NetJob.h"
|
||||||
|
#include "quazip.h"
|
||||||
|
|
||||||
// Quick & dirty struct to store files
|
// Quick & dirty struct to store files
|
||||||
struct File {
|
struct File {
|
||||||
@ -13,10 +13,12 @@ struct File{
|
|||||||
QByteArray hash;
|
QByteArray hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
void JavaDownloader::downloadJava(bool isLegacy, const QString& OS)
|
||||||
|
{
|
||||||
auto netJob = new NetJob(QString("JRE::QueryVersions"), APPLICATION->network());
|
auto netJob = new NetJob(QString("JRE::QueryVersions"), APPLICATION->network());
|
||||||
auto response = new QByteArray();
|
auto response = new QByteArray();
|
||||||
netJob->addNetAction(Net::Download::makeByteArray(QUrl("https://piston-meta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json"), response));
|
netJob->addNetAction(Net::Download::makeByteArray(
|
||||||
|
QUrl("https://piston-meta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json"), response));
|
||||||
QObject::connect(netJob, &NetJob::finished, [netJob, response] {
|
QObject::connect(netJob, &NetJob::finished, [netJob, response] {
|
||||||
netJob->deleteLater();
|
netJob->deleteLater();
|
||||||
delete response;
|
delete response;
|
||||||
@ -25,8 +27,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
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) {
|
||||||
qWarning() << "Error while parsing JSON response at " << parse_error.offset
|
qWarning() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
|
||||||
<< " reason: " << parse_error.errorString();
|
|
||||||
qWarning() << *response;
|
qWarning() << *response;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -46,14 +47,14 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*files, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*files, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
qWarning() << "Error while parsing JSON response at " << parse_error.offset
|
qWarning() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
|
||||||
<< " reason: " << parse_error.errorString();
|
|
||||||
qWarning() << *files;
|
qWarning() << *files;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// valid json doc, begin making jre spot
|
// valid json doc, begin making jre spot
|
||||||
auto output = FS::PathCombine(QCoreApplication::applicationDirPath(), QString("java/") + (isLegacy ? "java-legacy" : "java-current"));
|
auto output =
|
||||||
|
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();
|
||||||
@ -83,9 +84,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, file.hash));
|
dl->addValidator(new Net::ChecksumValidator(QCryptographicHash::Sha1, file.hash));
|
||||||
elementDownload->addNetAction(dl);
|
elementDownload->addNetAction(dl);
|
||||||
}
|
}
|
||||||
QObject::connect(elementDownload, &NetJob::finished,[elementDownload]{
|
QObject::connect(elementDownload, &NetJob::finished, [elementDownload] { elementDownload->deleteLater(); });
|
||||||
elementDownload->deleteLater();
|
|
||||||
});
|
|
||||||
elementDownload->start();
|
elementDownload->start();
|
||||||
});
|
});
|
||||||
download->start();
|
download->start();
|
||||||
@ -109,8 +108,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
}
|
}
|
||||||
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());
|
||||||
downloadJob->addNetAction(Net::Download::makeByteArray(QString(
|
downloadJob->addNetAction(Net::Download::makeByteArray(QString("https://api.azul.com/zulu/download/community/v1.0/bundles/?"
|
||||||
"https://api.azul.com/zulu/download/community/v1.0/bundles/?"
|
|
||||||
"java_version=%1"
|
"java_version=%1"
|
||||||
"&os=%2"
|
"&os=%2"
|
||||||
"&arch=%3"
|
"&arch=%3"
|
||||||
@ -118,7 +116,9 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
"&ext=zip" // as a zip for all os, even linux
|
"&ext=zip" // as a zip for all os, even linux
|
||||||
"&bundle_type=jre" // jre only
|
"&bundle_type=jre" // jre only
|
||||||
"&latest=true" // only get the one latest entry
|
"&latest=true" // only get the one latest entry
|
||||||
).arg(javaVersion,azulOS,arch,bitness), metaResponse));
|
)
|
||||||
|
.arg(javaVersion, azulOS, arch, bitness),
|
||||||
|
metaResponse));
|
||||||
QObject::connect(downloadJob, &NetJob::finished, [downloadJob, metaResponse] {
|
QObject::connect(downloadJob, &NetJob::finished, [downloadJob, metaResponse] {
|
||||||
downloadJob->deleteLater();
|
downloadJob->deleteLater();
|
||||||
delete metaResponse;
|
delete metaResponse;
|
||||||
@ -128,8 +128,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
QJsonParseError parse_error{};
|
QJsonParseError parse_error{};
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(*metaResponse, &parse_error);
|
QJsonDocument doc = QJsonDocument::fromJson(*metaResponse, &parse_error);
|
||||||
if (parse_error.error != QJsonParseError::NoError) {
|
if (parse_error.error != QJsonParseError::NoError) {
|
||||||
qWarning() << "Error while parsing JSON response at " << parse_error.offset
|
qWarning() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
|
||||||
<< " reason: " << parse_error.errorString();
|
|
||||||
qWarning() << *metaResponse;
|
qWarning() << *metaResponse;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,12 +142,10 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
entry->setStale(true);
|
entry->setStale(true);
|
||||||
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]{
|
QObject::connect(download, &NetJob::finished, [download] { download->deleteLater(); });
|
||||||
download->deleteLater();
|
|
||||||
|
|
||||||
});
|
|
||||||
QObject::connect(download, &NetJob::succeeded, [isLegacy, zippath] {
|
QObject::connect(download, &NetJob::succeeded, [isLegacy, zippath] {
|
||||||
auto output = FS::PathCombine(FS::PathCombine(QCoreApplication::applicationDirPath(), "java"),isLegacy ? "java-legacy" : "java-current");
|
auto output = FS::PathCombine(FS::PathCombine(QCoreApplication::applicationDirPath(), "java"),
|
||||||
|
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, output);
|
||||||
});
|
});
|
||||||
@ -160,5 +157,4 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
netJob->start();
|
netJob->start();
|
||||||
|
|
||||||
}
|
}
|
@ -5,4 +5,4 @@
|
|||||||
namespace JavaDownloader {
|
namespace JavaDownloader {
|
||||||
/*Downloads the java to the runtimes folder*/
|
/*Downloads the java to the runtimes folder*/
|
||||||
void downloadJava(bool isLegacy, const QString& OS);
|
void downloadJava(bool isLegacy, const QString& OS);
|
||||||
}
|
} // namespace JavaDownloader
|
||||||
|
Loading…
x
Reference in New Issue
Block a user