mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-06-12 13:17:41 +02:00
@ -21,9 +21,13 @@
|
||||
#include "MMCZip.h"
|
||||
|
||||
#include "Application.h"
|
||||
#include "net/ChecksumValidator.h"
|
||||
#include "net/NetJob.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
ArchiveJavaDownloader::ArchiveJavaDownloader(QUrl url, QString final_path, QString checksumType, QString checksumHash)
|
||||
: m_url(url), m_final_path(final_path), m_checksum_type(checksumType), m_checksum_hash(checksumHash){};
|
||||
|
||||
void ArchiveJavaDownloader::executeTask()
|
||||
{
|
||||
// JRE found ! download the zip
|
||||
@ -32,7 +36,15 @@ void ArchiveJavaDownloader::executeTask()
|
||||
MetaEntryPtr entry = APPLICATION->metacache()->resolveEntry("java", m_url.toLocalFile());
|
||||
|
||||
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
|
||||
download->addNetAction(Net::Download::makeCached(m_url, entry));
|
||||
auto action = Net::Download::makeCached(m_url, entry);
|
||||
if (!m_checksum_hash.isEmpty() && !m_checksum_type.isEmpty()) {
|
||||
auto hashType = QCryptographicHash::Algorithm::Sha1;
|
||||
if (m_checksum_type == "sha256") {
|
||||
hashType = QCryptographicHash::Algorithm::Sha256;
|
||||
}
|
||||
action->addValidator(new Net::ChecksumValidator(hashType, m_checksum_hash.toLatin1()));
|
||||
}
|
||||
download->addNetAction(action);
|
||||
auto fullPath = entry->getFullPath();
|
||||
|
||||
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
|
||||
@ -45,7 +57,7 @@ void ArchiveJavaDownloader::executeTask()
|
||||
extractJava(fullPath);
|
||||
});
|
||||
download->start();
|
||||
};
|
||||
}
|
||||
|
||||
void ArchiveJavaDownloader::extractJava(QString input)
|
||||
{
|
||||
@ -85,4 +97,4 @@ void ArchiveJavaDownloader::extractJava(QString input)
|
||||
stepProgress(*progressStep);
|
||||
});
|
||||
zipTask->start();
|
||||
};
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
class ArchiveJavaDownloader : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ArchiveJavaDownloader(QUrl url, QString final_path);
|
||||
ArchiveJavaDownloader(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
|
||||
virtual ~ArchiveJavaDownloader() = default;
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
@ -36,6 +36,8 @@ class ArchiveJavaDownloader : public Task {
|
||||
protected:
|
||||
QUrl m_url;
|
||||
QString m_final_path;
|
||||
QString m_checksum_type;
|
||||
QString m_checksum_hash;
|
||||
|
||||
Task::Ptr m_current_task;
|
||||
};
|
@ -30,14 +30,24 @@ struct File {
|
||||
bool isExec;
|
||||
};
|
||||
|
||||
ManifestJavaDownloader::ManifestJavaDownloader(QUrl url, QString final_path) : m_url(url), m_final_path(final_path){};
|
||||
ManifestJavaDownloader::ManifestJavaDownloader(QUrl url, QString final_path, QString checksumType, QString checksumHash)
|
||||
: m_url(url), m_final_path(final_path), m_checksum_type(checksumType), m_checksum_hash(checksumHash){};
|
||||
|
||||
void ManifestJavaDownloader::executeTask()
|
||||
{
|
||||
setStatus(tr("Downloading Java"));
|
||||
auto download = makeShared<NetJob>(QString("JRE::DownloadJava"), APPLICATION->network());
|
||||
auto files = std::make_shared<QByteArray>();
|
||||
|
||||
download->addNetAction(Net::Download::makeByteArray(m_url, files));
|
||||
auto action = Net::Download::makeByteArray(m_url, files);
|
||||
if (!m_checksum_hash.isEmpty() && !m_checksum_type.isEmpty()) {
|
||||
auto hashType = QCryptographicHash::Algorithm::Sha1;
|
||||
if (m_checksum_type == "sha256") {
|
||||
hashType = QCryptographicHash::Algorithm::Sha256;
|
||||
}
|
||||
action->addValidator(new Net::ChecksumValidator(hashType, m_checksum_hash.toLatin1()));
|
||||
}
|
||||
download->addNetAction(action);
|
||||
|
||||
connect(download.get(), &NetJob::finished, [download, this] { disconnect(this, &Task::aborted, download.get(), &NetJob::abort); });
|
||||
connect(download.get(), &NetJob::progress, this, &ManifestJavaDownloader::progress);
|
||||
@ -56,7 +66,7 @@ void ManifestJavaDownloader::executeTask()
|
||||
downloadJava(doc);
|
||||
});
|
||||
download->start();
|
||||
};
|
||||
}
|
||||
|
||||
void ManifestJavaDownloader::downloadJava(const QJsonDocument& doc)
|
||||
{
|
||||
@ -111,4 +121,4 @@ void ManifestJavaDownloader::downloadJava(const QJsonDocument& doc)
|
||||
connect(this, &Task::aborted, elementDownload, &NetJob::abort);
|
||||
connect(elementDownload, &NetJob::succeeded, [this] { emitSucceeded(); });
|
||||
elementDownload->start();
|
||||
};
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
class ManifestJavaDownloader : public Task {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ManifestJavaDownloader(QUrl url, QString final_path);
|
||||
ManifestJavaDownloader(QUrl url, QString final_path, QString checksumType = "", QString checksumHash = "");
|
||||
virtual ~ManifestJavaDownloader() = default;
|
||||
|
||||
[[nodiscard]] bool canAbort() const override { return true; }
|
||||
@ -36,6 +36,8 @@ class ManifestJavaDownloader : public Task {
|
||||
protected:
|
||||
QUrl m_url;
|
||||
QString m_final_path;
|
||||
QString m_checksum_type;
|
||||
QString m_checksum_hash;
|
||||
|
||||
Task::Ptr m_current_task;
|
||||
};
|
Reference in New Issue
Block a user