feat: add mod index updating to ModDownloadTask
This makes ModDownloadTask into a SequentialTask with 2 subtasks: Downloading the mod files and updating the index with the new information. The index updating is done first so that, in the future, we can prompt the user before download if, for instance, we discover there's another version already installed.
This commit is contained in:
parent
b30b88716e
commit
c86c719e1a
@ -1,24 +1,28 @@
|
|||||||
#include "ModDownloadTask.h"
|
#include "ModDownloadTask.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
#include "minecraft/mod/LocalModUpdateTask.h"
|
||||||
|
|
||||||
ModDownloadTask::ModDownloadTask(const QUrl sourceUrl,const QString filename, const std::shared_ptr<ModFolderModel> mods)
|
ModDownloadTask::ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods)
|
||||||
: m_sourceUrl(sourceUrl), mods(mods), filename(filename) {
|
: m_mod(mod), m_mod_version(version), mods(mods)
|
||||||
}
|
{
|
||||||
|
m_update_task.reset(new LocalModUpdateTask(mods->dir(), m_mod, m_mod_version));
|
||||||
|
|
||||||
void ModDownloadTask::executeTask() {
|
addTask(m_update_task);
|
||||||
setStatus(tr("Downloading mod:\n%1").arg(m_sourceUrl.toString()));
|
|
||||||
|
|
||||||
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
|
m_filesNetJob.reset(new NetJob(tr("Mod download"), APPLICATION->network()));
|
||||||
m_filesNetJob->addNetAction(Net::Download::makeFile(m_sourceUrl, mods->dir().absoluteFilePath(filename)));
|
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::succeeded, this, &ModDownloadTask::downloadSucceeded);
|
||||||
connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged);
|
connect(m_filesNetJob.get(), &NetJob::progress, this, &ModDownloadTask::downloadProgressChanged);
|
||||||
connect(m_filesNetJob.get(), &NetJob::failed, this, &ModDownloadTask::downloadFailed);
|
connect(m_filesNetJob.get(), &NetJob::failed, this, &ModDownloadTask::downloadFailed);
|
||||||
m_filesNetJob->start();
|
|
||||||
|
addTask(m_filesNetJob);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModDownloadTask::downloadSucceeded()
|
void ModDownloadTask::downloadSucceeded()
|
||||||
{
|
{
|
||||||
emitSucceeded();
|
|
||||||
m_filesNetJob.reset();
|
m_filesNetJob.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,8 +36,3 @@ void ModDownloadTask::downloadProgressChanged(qint64 current, qint64 total)
|
|||||||
{
|
{
|
||||||
emit progress(current, total);
|
emit progress(current, total);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModDownloadTask::abort() {
|
|
||||||
return m_filesNetJob->abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -1,28 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "QObjectPtr.h"
|
#include "QObjectPtr.h"
|
||||||
#include "tasks/Task.h"
|
#include "minecraft/mod/LocalModUpdateTask.h"
|
||||||
|
#include "modplatform/ModIndex.h"
|
||||||
|
#include "tasks/SequentialTask.h"
|
||||||
#include "minecraft/mod/ModFolderModel.h"
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
#include "net/NetJob.h"
|
#include "net/NetJob.h"
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
|
class ModDownloadTask : public SequentialTask {
|
||||||
class ModDownloadTask : public Task {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ModDownloadTask(const QUrl sourceUrl, const QString filename, const std::shared_ptr<ModFolderModel> mods);
|
explicit ModDownloadTask(ModPlatform::IndexedPack mod, ModPlatform::IndexedVersion version, const std::shared_ptr<ModFolderModel> mods);
|
||||||
const QString& getFilename() const { return filename; }
|
const QString& getFilename() const { return m_mod_version.fileName; }
|
||||||
|
|
||||||
public slots:
|
|
||||||
bool abort() override;
|
|
||||||
protected:
|
|
||||||
//! Entry point for tasks.
|
|
||||||
void executeTask() override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QUrl m_sourceUrl;
|
ModPlatform::IndexedPack m_mod;
|
||||||
NetJob::Ptr m_filesNetJob;
|
ModPlatform::IndexedVersion m_mod_version;
|
||||||
const std::shared_ptr<ModFolderModel> mods;
|
const std::shared_ptr<ModFolderModel> mods;
|
||||||
const QString filename;
|
|
||||||
|
NetJob::Ptr m_filesNetJob;
|
||||||
|
LocalModUpdateTask::Ptr m_update_task;
|
||||||
|
|
||||||
void downloadProgressChanged(qint64 current, qint64 total);
|
void downloadProgressChanged(qint64 current, qint64 total);
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ void ModPage::onModSelected()
|
|||||||
if (dialog->isModSelected(current.name, version.fileName)) {
|
if (dialog->isModSelected(current.name, version.fileName)) {
|
||||||
dialog->removeSelectedMod(current.name);
|
dialog->removeSelectedMod(current.name);
|
||||||
} else {
|
} else {
|
||||||
dialog->addSelectedMod(current.name, new ModDownloadTask(version.downloadUrl, version.fileName, dialog->mods));
|
dialog->addSelectedMod(current.name, new ModDownloadTask(current, version, dialog->mods));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSelectionButton();
|
updateSelectionButton();
|
||||||
|
Loading…
Reference in New Issue
Block a user