Changed to a temporary file

Signed-off-by: timoreo <contact@timoreo.fr>
This commit is contained in:
timoreo 2022-09-12 08:19:42 +02:00
parent 24dc154856
commit a902f29ccf
No known key found for this signature in database
GPG Key ID: 121A72C3512BA288
2 changed files with 15 additions and 8 deletions

View File

@ -1,6 +1,7 @@
#include "JavaDownloader.h"
#include <QMessageBox>
#include <QPushButton>
#include <memory>
#include "Application.h"
#include "FileSystem.h"
#include "Json.h"
@ -127,6 +128,11 @@ void JavaDownloader::executeTask()
azulOS = "linux";
arch = "arm";
bitness = "32";
} else if (OS == "linux"){
// linux x86 64 (used for debugging, should never reach here)
azulOS = "linux";
arch = "x86";
bitness = "64";
}
auto metaResponse = new QByteArray();
auto downloadJob = new NetJob(QString("JRE::QueryAzulMeta"), APPLICATION->network());
@ -161,19 +167,20 @@ void JavaDownloader::executeTask()
setStatus(tr("Downloading java from Azul"));
auto downloadURL = QUrl(array[0].toObject()["url"].toString());
auto download = new NetJob(QString("JRE::DownloadJava"), APPLICATION->network());
const QString path = downloadURL.host() + '/' + downloadURL.path();
auto entry = APPLICATION->metacache()->resolveEntry("general", path);
entry->setStale(true);
download->addNetAction(Net::Download::makeCached(downloadURL, entry));
auto zippath = entry->getFullPath();
auto temp = std::make_unique<QTemporaryFile>(FS::PathCombine(APPLICATION->root(), "temp", "XXXXXX.zip"));
FS::ensureFolderPathExists(FS::PathCombine(APPLICATION->root(),"temp"));
// Have to open at least once to generate path
temp->open();
temp->close();
download->addNetAction(Net::Download::makeFile(downloadURL, temp->fileName()));
QObject::connect(download, &NetJob::finished, [download] { download->deleteLater(); });
QObject::connect(download, &NetJob::progress, this, &JavaDownloader::progress);
QObject::connect(download, &NetJob::succeeded, [isLegacy, zippath, downloadURL, this] {
QObject::connect(download, &NetJob::succeeded, [isLegacy, file = std::move(temp), downloadURL, this] {
setStatus(tr("Extracting java"));
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, downloadURL.fileName().chopped(4), output);
MMCZip::extractDir(file->fileName(), downloadURL.fileName().chopped(4), output);
emitSucceeded();
});
download->start();

View File

@ -118,7 +118,7 @@ void JavaSettingsWidget::setupUi()
m_verticalLayout->addWidget(m_memoryGroupBox);
m_javaDownloadBtn = new QPushButton("Download Java",this);
m_javaDownloadBtn = new QPushButton(tr("Download Java"), this);
m_verticalLayout->addWidget(m_javaDownloadBtn);