2022-01-14 14:13:42 +05:30
|
|
|
#include "ModDownloadTask.h"
|
2022-04-16 05:05:17 +05:30
|
|
|
|
2022-01-14 17:17:18 +05:30
|
|
|
#include "Application.h"
|
2022-04-16 05:05:17 +05:30
|
|
|
#include "minecraft/mod/tasks/LocalModUpdateTask.h"
|
2022-01-14 14:13:42 +05:30
|
|
|
|
2022-04-14 03:48:28 +05:30
|
|
|
ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods)
|
|
|
|
: m_mod(mod), m_mod_version(version), mods(mods)
|
|
|
|
{
|
2022-04-15 06:32:41 +05:30
|
|
|
m_update_task.reset(new LocalModUpdateTask(mods->indexDir(), m_mod, m_mod_version));
|
2022-01-14 14:13:42 +05:30
|
|
|
|
2022-04-14 03:48:28 +05:30
|
|
|
addTask(m_update_task);
|
2022-01-14 17:17:18 +05:30
|
|
|
|
2022-01-15 14:55:24 +05:30
|
|
|
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
|
2022-04-14 03:48:28 +05:30
|
|
|
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())));
|
2022-01-14 17:17:18 +05:30
|
|
|
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);
|
2022-04-14 03:48:28 +05:30
|
|
|
|
|
|
|
addTask(m_filesNetJob);
|
|
|
|
|
2022-01-14 17:17:18 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
void ModDownloadTask::downloadSucceeded()
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|