Clang format

Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
timoreo 2022-07-01 08:52:56 +02:00
parent 3433c102b7
commit 9a4a92de4f
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
2 changed files with 63 additions and 67 deletions

View File

@ -1,10 +1,10 @@
#include "JavaDownloader.h"
#include "net/NetJob.h"
#include "Application.h"
#include "FileSystem.h"
#include "quazip.h"
#include "MMCZip.h"
#include "net/ChecksumValidator.h"
#include "net/NetJob.h"
#include "quazip.h"
// Quick & dirty struct to store files
struct File {
@ -13,10 +13,12 @@ struct File{
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 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] {
netJob->deleteLater();
delete response;
@ -25,8 +27,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
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() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
qWarning() << *response;
return;
}
@ -46,14 +47,14 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
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() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
qWarning() << *files;
return;
}
// 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);
std::vector<File> toDownload;
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));
elementDownload->addNetAction(dl);
}
QObject::connect(elementDownload, &NetJob::finished,[elementDownload]{
elementDownload->deleteLater();
});
QObject::connect(elementDownload, &NetJob::finished, [elementDownload] { elementDownload->deleteLater(); });
elementDownload->start();
});
download->start();
@ -109,8 +108,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
}
auto metaResponse = new QByteArray();
auto downloadJob = new NetJob(QString("JRE::QueryAzulMeta"), APPLICATION->network());
downloadJob->addNetAction(Net::Download::makeByteArray(QString(
"https://api.azul.com/zulu/download/community/v1.0/bundles/?"
downloadJob->addNetAction(Net::Download::makeByteArray(QString("https://api.azul.com/zulu/download/community/v1.0/bundles/?"
"java_version=%1"
"&os=%2"
"&arch=%3"
@ -118,7 +116,9 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
"&ext=zip" // as a zip for all os, even linux
"&bundle_type=jre" // jre only
"&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] {
downloadJob->deleteLater();
delete metaResponse;
@ -128,8 +128,7 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
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() << "Error while parsing JSON response at " << parse_error.offset << " reason: " << parse_error.errorString();
qWarning() << *metaResponse;
return;
}
@ -143,12 +142,10 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
entry->setStale(true);
download->addNetAction(Net::Download::makeCached(downloadURL, entry));
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] {
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
MMCZip::extractDir(zippath, output);
});
@ -160,5 +157,4 @@ void JavaDownloader::downloadJava(bool isLegacy, const QString& OS) {
});
netJob->start();
}

View File

@ -5,4 +5,4 @@
namespace JavaDownloader {
/*Downloads the java to the runtimes folder*/
void downloadJava(bool isLegacy, const QString& OS);
}
} // namespace JavaDownloader