PrismLauncher/launcher/ModDownloadTask.cpp
flow 5a34e8fd7c
refactor: move mod tasks to their own subfolder
Makes the launcher/minecraft/mod/ folder a little more organized.
2022-05-23 14:42:27 -03:00

40 lines
1.3 KiB
C++

#include "ModDownloadTask.h"
#include "Application.h"
#include "minecraft/mod/tasks/LocalModUpdateTask.h"
ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods)
: m_mod(mod), m_mod_version(version), mods(mods)
{
m_update_task.reset(new LocalModUpdateTask(mods->indexDir(), m_mod, m_mod_version));
addTask(m_update_task);
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
m_filesNetJob->setStatus(tr("Downloading mod:\n%1").arg(m_mod_version.downloadUrl));
m_filesNetJob->addNetAction(Net::Download::makeFile(m_mod_version.downloadUrl, mods->dir().absoluteFilePath(getFilename())));
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);
addTask(m_filesNetJob);
}
void ModDownloadTask::downloadSucceeded()
{
m_filesNetJob.reset();
}
void ModDownloadTask::downloadFailed(QString reason)
{
emitFailed(reason);
m_filesNetJob.reset();
}
void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total)
{
emit progress(current, total);
}