pollymc/launcher/ModDownloadTask.cpp

40 lines
1.2 KiB
C++
Raw Normal View History

2022-01-14 14:13:42 +05:30
#include "ModDownloadTask.h"
2022-01-14 17:17:18 +05:30
#include "Application.h"
2022-01-14 14:13:42 +05:30
2022-01-14 17:17:18 +05:30
ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, const std::shared_ptr<ModFolderModel> mods)
: m_sourceUrl(sourceUrl), mods(mods), filename(filename) {
2022-01-14 14:13:42 +05:30
}
void ModDownloadTask::executeTask() {
2022-01-14 17:17:18 +05:30
setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString()));
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
2022-01-14 17:17:18 +05:30
m_filesNetJob->addNetAction(Net::Download::makeFile(m_sourceUrl, mods->dir().absoluteFilePath(filename)));
connect(m_filesNetJob.get(), &NetJob::succeeded, this, &ModDownloadTask::downloadSucceeded);
connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged);
connect(m_filesNetJob.get(), &NetJob::failed, this, &ModDownloadTask::downloadFailed);
m_filesNetJob->start();
}
void ModDownloadTask::downloadSucceeded()
{
2022-01-14 14:13:42 +05:30
emitSucceeded();
2022-01-14 17:17:18 +05:30
m_filesNetJob.reset();
}
void ModDownloadTask::downloadFailed(QString reason)
{
emitFailed(reason);
m_filesNetJob.reset();
2022-01-14 14:13:42 +05:30
}
2022-01-14 17:17:18 +05:30
void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total)
{
emit progress(current, total);
}
bool ModDownloadTask::abort() {
return m_filesNetJob->abort();
}