Added progeess dialog to autodownload java

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-02-17 11:14:32 +02:00
parent 2941307581
commit ea2adf909d
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
4 changed files with 56 additions and 19 deletions

View File

@ -50,9 +50,12 @@ void ArchiveDownloadTask::executeTask()
auto fullPath = entry->getFullPath();
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
connect(download.get(), &NetJob::progress, this, &ArchiveDownloadTask::progress);
connect(download.get(), &NetJob::failed, this, &ArchiveDownloadTask::emitFailed);
connect(this, &Task::aborted, download.get(), &NetJob::abort);
connect(download.get(), &Task::progress, this, &ArchiveDownloadTask::setProgress);
connect(download.get(), &Task::stepProgress, this, &ArchiveDownloadTask::propagateStepProgress);
connect(download.get(), &Task::status, this, &ArchiveDownloadTask::setStatus);
connect(download.get(), &Task::details, this, &ArchiveDownloadTask::setDetails);
connect(download.get(), &NetJob::succeeded, [this, fullPath] {
// This should do all of the extracting and creating folders
extractJava(fullPath);

View File

@ -52,9 +52,12 @@ void ManifestDownloadTask::executeTask()
download->addNetAction(action);
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
connect(download.get(), &NetJob::progress, this, &ManifestDownloadTask::progress);
connect(download.get(), &NetJob::failed, this, &ManifestDownloadTask::emitFailed);
connect(this, &Task::aborted, download.get(), &NetJob::abort);
connect(download.get(), &Task::progress, this, &ManifestDownloadTask::setProgress);
connect(download.get(), &Task::stepProgress, this, &ManifestDownloadTask::propagateStepProgress);
connect(download.get(), &Task::status, this, &ManifestDownloadTask::setStatus);
connect(download.get(), &Task::details, this, &ManifestDownloadTask::setDetails);
connect(download.get(), &NetJob::succeeded, [files, this] {
QJsonParseError parse_error{};
@ -117,8 +120,11 @@ void ManifestDownloadTask::downloadJava(const QJsonDocument& doc)
disconnect(this, &Task::aborted, elementDownload, &NetJob::abort);
elementDownload->deleteLater();
});
connect(elementDownload, &NetJob::progress, this, &ManifestDownloadTask::progress);
connect(elementDownload, &NetJob::failed, this, &ManifestDownloadTask::emitFailed);
connect(elementDownload, &Task::progress, this, &ManifestDownloadTask::setProgress);
connect(elementDownload, &Task::stepProgress, this, &ManifestDownloadTask::propagateStepProgress);
connect(elementDownload, &Task::status, this, &ManifestDownloadTask::setStatus);
connect(elementDownload, &Task::details, this, &ManifestDownloadTask::setDetails);
connect(this, &Task::aborted, elementDownload, &NetJob::abort);
connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });

View File

@ -34,8 +34,8 @@
*/
#include "AutoInstallJava.h"
#include <qdir.h>
#include <qfileinfo.h>
#include <QDir>
#include <QFileInfo>
#include <memory>
#include "Application.h"
@ -61,7 +61,8 @@ void AutoInstallJava::executeTask()
{
auto settings = m_instance->settings();
if (!APPLICATION->settings()->get("AutomaticJavaSwitch").toBool() ||
(settings->get("OverrideJava").toBool() && settings->get("OverrideJavaLocation").toBool())) {
(settings->get("OverrideJava").toBool() && settings->get("OverrideJavaLocation").toBool() &&
QFileInfo::exists(settings->get("JavaPath").toString()))) {
emitSucceeded();
return;
}
@ -80,6 +81,11 @@ void AutoInstallJava::executeTask()
emit logLine(tr("No comptatible java version was found. Using the default one."), MessageLevel::Warning);
emitSucceeded();
});
connect(m_current_task.get(), &Task::progress, this, &AutoInstallJava::setProgress);
connect(m_current_task.get(), &Task::stepProgress, this, &AutoInstallJava::propagateStepProgress);
connect(m_current_task.get(), &Task::status, this, &AutoInstallJava::setStatus);
connect(m_current_task.get(), &Task::details, this, &AutoInstallJava::setDetails);
emit progressReportingRequest();
return;
}
auto wantedJavaName = packProfile->getProfile()->getCompatibleJavaName();
@ -93,6 +99,11 @@ void AutoInstallJava::executeTask()
m_current_task = versionList->getLoadTask();
connect(m_current_task.get(), &Task::succeeded, this, &AutoInstallJava::tryNextMajorJava);
connect(m_current_task.get(), &Task::failed, this, &AutoInstallJava::emitFailed);
connect(m_current_task.get(), &Task::progress, this, &AutoInstallJava::setProgress);
connect(m_current_task.get(), &Task::stepProgress, this, &AutoInstallJava::propagateStepProgress);
connect(m_current_task.get(), &Task::status, this, &AutoInstallJava::setStatus);
connect(m_current_task.get(), &Task::details, this, &AutoInstallJava::setDetails);
emit progressReportingRequest();
}
void AutoInstallJava::setJavaPath(QString path)
@ -134,29 +145,34 @@ void AutoInstallJava::downloadJava(Meta::Version::Ptr version, QString javaName)
if (runtimes.contains(m_supported_arch)) {
for (auto java : runtimes.value(m_supported_arch)) {
if (java->name() == javaName) {
Task::Ptr task;
QDir javaDir(APPLICATION->javaPath());
auto final_path = javaDir.absoluteFilePath(java->m_name);
switch (java->downloadType) {
case Java::DownloadType::Manifest:
task = makeShared<Java::ManifestDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash);
m_current_task =
makeShared<Java::ManifestDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash);
break;
case Java::DownloadType::Archive:
task = makeShared<Java::ArchiveDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash);
m_current_task =
makeShared<Java::ArchiveDownloadTask>(java->url, final_path, java->checksumType, java->checksumHash);
break;
}
QEventLoop loop;
auto deletePath = [final_path] { FS::deletePath(final_path); };
connect(task.get(), &Task::failed, this, [this, deletePath](QString reason) {
connect(m_current_task.get(), &Task::failed, this, [this, deletePath](QString reason) {
deletePath();
emitFailed(reason);
});
connect(this, &Task::aborted, this, [task, deletePath] {
task->abort();
connect(this, &Task::aborted, this, [this, deletePath] {
m_current_task->abort();
deletePath();
});
connect(task.get(), &Task::succeeded, this, &AutoInstallJava::setJavaPathFromPartial);
task->start();
connect(m_current_task.get(), &Task::succeeded, this, &AutoInstallJava::setJavaPathFromPartial);
connect(m_current_task.get(), &Task::failed, this, &AutoInstallJava::tryNextMajorJava);
connect(m_current_task.get(), &Task::progress, this, &AutoInstallJava::setProgress);
connect(m_current_task.get(), &Task::stepProgress, this, &AutoInstallJava::propagateStepProgress);
connect(m_current_task.get(), &Task::status, this, &AutoInstallJava::setStatus);
connect(m_current_task.get(), &Task::details, this, &AutoInstallJava::setDetails);
m_current_task->start();
return;
}
}
@ -182,11 +198,22 @@ void AutoInstallJava::tryNextMajorJava()
auto javaMajor = versionList->getVersion(QString("java%1").arg(majorJavaVersion));
javaMajor->load(Net::Mode::Online);
auto task = javaMajor->getCurrentTask();
if (javaMajor->isLoaded() || !task) {
m_current_task = javaMajor->getCurrentTask();
if (javaMajor->isLoaded() || !m_current_task) {
downloadJava(javaMajor, wantedJavaName);
} else {
connect(task.get(), &Task::succeeded, this, [this, javaMajor, wantedJavaName] { downloadJava(javaMajor, wantedJavaName); });
connect(task.get(), &Task::failed, this, &AutoInstallJava::tryNextMajorJava);
connect(m_current_task.get(), &Task::succeeded, this,
[this, javaMajor, wantedJavaName] { downloadJava(javaMajor, wantedJavaName); });
connect(m_current_task.get(), &Task::failed, this, &AutoInstallJava::tryNextMajorJava);
connect(m_current_task.get(), &Task::progress, this, &AutoInstallJava::setProgress);
connect(m_current_task.get(), &Task::stepProgress, this, &AutoInstallJava::propagateStepProgress);
connect(m_current_task.get(), &Task::status, this, &AutoInstallJava::setStatus);
connect(m_current_task.get(), &Task::details, this, &AutoInstallJava::setDetails);
}
}
bool AutoInstallJava::abort()
{
if (m_current_task && m_current_task->canAbort())
return m_current_task->abort();
return true;
}

View File

@ -51,6 +51,7 @@ class AutoInstallJava : public LaunchStep {
void executeTask() override;
bool canAbort() const override { return m_current_task ? m_current_task->canAbort() : false; }
bool abort() override;
protected:
void setJavaPath(QString path);