2022-05-10 23:57:47 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (c) 2022 flowln <flowlnlnln@gmail.com>
|
2022-06-12 12:50:58 +01:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2022-05-10 23:57:47 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-01-14 08:43:42 +00:00
|
|
|
#include "ModDownloadTask.h"
|
2022-04-16 00:35:17 +01:00
|
|
|
|
2022-01-14 11:47:18 +00:00
|
|
|
#include "Application.h"
|
2022-05-10 23:57:47 +01:00
|
|
|
#include "minecraft/mod/ModFolderModel.h"
|
2022-01-14 08:43:42 +00:00
|
|
|
|
2022-06-04 14:30:34 +01:00
|
|
|
ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods, bool is_indexed)
|
2022-04-13 23:18:28 +01:00
|
|
|
: m_mod(mod), m_mod_version(version), mods(mods)
|
|
|
|
{
|
2022-06-04 14:30:34 +01:00
|
|
|
if (is_indexed) {
|
|
|
|
m_update_task.reset(new LocalModUpdateTask(mods->indexDir(), m_mod, m_mod_version));
|
2022-01-14 08:43:42 +00:00
|
|
|
|
2022-06-04 14:30:34 +01:00
|
|
|
addTask(m_update_task);
|
|
|
|
}
|
2022-01-14 11:47:18 +00:00
|
|
|
|
2022-01-15 09:25:24 +00:00
|
|
|
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
|
2022-04-13 23:18:28 +01:00
|
|
|
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 11:47:18 +00:00
|
|
|
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-13 23:18:28 +01:00
|
|
|
|
|
|
|
addTask(m_filesNetJob);
|
|
|
|
|
2022-01-14 11:47:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModDownloadTask::downloadSucceeded()
|
|
|
|
{
|
|
|
|
m_filesNetJob.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModDownloadTask::downloadFailed(QString reason)
|
|
|
|
{
|
|
|
|
emitFailed(reason);
|
|
|
|
m_filesNetJob.reset();
|
2022-01-14 08:43:42 +00:00
|
|
|
}
|
2022-01-14 11:47:18 +00:00
|
|
|
|
|
|
|
void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total)
|
|
|
|
{
|
|
|
|
emit progress(current, total);
|
|
|
|
}
|