Merge pull request #3925 from jamierocks/fix-1949

GH-1949 Allow modpack downloads to be aborted
This commit is contained in:
Petr Mrázek 2021-07-06 22:01:33 +02:00 committed by GitHub
commit df1d3dbae2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 61 additions and 2 deletions

View File

@ -28,7 +28,11 @@ PackInstallTask::PackInstallTask(UserInteractionSupport *support, QString pack,
bool PackInstallTask::abort() bool PackInstallTask::abort()
{ {
return true; if(abortable)
{
return jobPtr->abort();
}
return false;
} }
void PackInstallTask::executeTask() void PackInstallTask::executeTask()
@ -418,16 +422,19 @@ void PackInstallTask::installConfigs()
connect(jobPtr.get(), &NetJob::succeeded, this, [&]() connect(jobPtr.get(), &NetJob::succeeded, this, [&]()
{ {
abortable = false;
jobPtr.reset(); jobPtr.reset();
extractConfigs(); extractConfigs();
}); });
connect(jobPtr.get(), &NetJob::failed, [&](QString reason) connect(jobPtr.get(), &NetJob::failed, [&](QString reason)
{ {
abortable = false;
jobPtr.reset(); jobPtr.reset();
emitFailed(reason); emitFailed(reason);
}); });
connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total) connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total)
{ {
abortable = true;
setProgress(current, total); setProgress(current, total);
}); });
@ -576,11 +583,13 @@ void PackInstallTask::downloadMods()
connect(jobPtr.get(), &NetJob::succeeded, this, &PackInstallTask::onModsDownloaded); connect(jobPtr.get(), &NetJob::succeeded, this, &PackInstallTask::onModsDownloaded);
connect(jobPtr.get(), &NetJob::failed, [&](QString reason) connect(jobPtr.get(), &NetJob::failed, [&](QString reason)
{ {
abortable = false;
jobPtr.reset(); jobPtr.reset();
emitFailed(reason); emitFailed(reason);
}); });
connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total) connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total)
{ {
abortable = true;
setProgress(current, total); setProgress(current, total);
}); });
@ -588,6 +597,8 @@ void PackInstallTask::downloadMods()
} }
void PackInstallTask::onModsDownloaded() { void PackInstallTask::onModsDownloaded() {
abortable = false;
qDebug() << "PackInstallTask::onModsDownloaded: " << QThread::currentThreadId(); qDebug() << "PackInstallTask::onModsDownloaded: " << QThread::currentThreadId();
jobPtr.reset(); jobPtr.reset();

View File

@ -39,6 +39,7 @@ public:
explicit PackInstallTask(UserInteractionSupport *support, QString pack, QString version); explicit PackInstallTask(UserInteractionSupport *support, QString pack, QString version);
virtual ~PackInstallTask(){} virtual ~PackInstallTask(){}
bool canAbort() const override { return true; }
bool abort() override; bool abort() override;
protected: protected:
@ -72,6 +73,8 @@ private:
private: private:
UserInteractionSupport *m_support; UserInteractionSupport *m_support;
bool abortable = false;
NetJobPtr jobPtr; NetJobPtr jobPtr;
QByteArray response; QByteArray response;

View File

@ -20,6 +20,7 @@ public:
explicit PackInstallTask(Modpack pack, QString version); explicit PackInstallTask(Modpack pack, QString version);
virtual ~PackInstallTask(){} virtual ~PackInstallTask(){}
bool canAbort() const override { return true; }
bool abort() override; bool abort() override;
protected: protected:

View File

@ -19,7 +19,11 @@ PackInstallTask::PackInstallTask(Modpack pack, QString version)
bool PackInstallTask::abort() bool PackInstallTask::abort()
{ {
return true; if(abortable)
{
return jobPtr->abort();
}
return false;
} }
void PackInstallTask::executeTask() void PackInstallTask::executeTask()
@ -117,16 +121,19 @@ void PackInstallTask::downloadPack()
connect(jobPtr.get(), &NetJob::succeeded, this, [&]() connect(jobPtr.get(), &NetJob::succeeded, this, [&]()
{ {
abortable = false;
jobPtr.reset(); jobPtr.reset();
install(); install();
}); });
connect(jobPtr.get(), &NetJob::failed, [&](QString reason) connect(jobPtr.get(), &NetJob::failed, [&](QString reason)
{ {
abortable = false;
jobPtr.reset(); jobPtr.reset();
emitFailed(reason); emitFailed(reason);
}); });
connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total) connect(jobPtr.get(), &NetJob::progress, [&](qint64 current, qint64 total)
{ {
abortable = true;
setProgress(current, total); setProgress(current, total);
}); });

View File

@ -16,6 +16,7 @@ public:
explicit PackInstallTask(Modpack pack, QString version); explicit PackInstallTask(Modpack pack, QString version);
virtual ~PackInstallTask(){} virtual ~PackInstallTask(){}
bool canAbort() const override { return true; }
bool abort() override; bool abort() override;
protected: protected:
@ -30,6 +31,8 @@ private:
void install(); void install();
private: private:
bool abortable = false;
NetJobPtr jobPtr; NetJobPtr jobPtr;
QByteArray response; QByteArray response;

View File

@ -28,6 +28,14 @@ Technic::SingleZipPackInstallTask::SingleZipPackInstallTask(const QUrl &sourceUr
m_minecraftVersion = minecraftVersion; m_minecraftVersion = minecraftVersion;
} }
bool Technic::SingleZipPackInstallTask::abort() {
if(m_abortable)
{
return m_filesNetJob->abort();
}
return false;
}
void Technic::SingleZipPackInstallTask::executeTask() void Technic::SingleZipPackInstallTask::executeTask()
{ {
setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString())); setStatus(tr("Downloading modpack:\n%1").arg(m_sourceUrl.toString()));
@ -47,6 +55,8 @@ void Technic::SingleZipPackInstallTask::executeTask()
void Technic::SingleZipPackInstallTask::downloadSucceeded() void Technic::SingleZipPackInstallTask::downloadSucceeded()
{ {
m_abortable = false;
setStatus(tr("Extracting modpack")); setStatus(tr("Extracting modpack"));
QDir extractDir(FS::PathCombine(m_stagingPath, ".minecraft")); QDir extractDir(FS::PathCombine(m_stagingPath, ".minecraft"));
qDebug() << "Attempting to create instance from" << m_archivePath; qDebug() << "Attempting to create instance from" << m_archivePath;
@ -67,12 +77,14 @@ void Technic::SingleZipPackInstallTask::downloadSucceeded()
void Technic::SingleZipPackInstallTask::downloadFailed(QString reason) void Technic::SingleZipPackInstallTask::downloadFailed(QString reason)
{ {
m_abortable = false;
emitFailed(reason); emitFailed(reason);
m_filesNetJob.reset(); m_filesNetJob.reset();
} }
void Technic::SingleZipPackInstallTask::downloadProgressChanged(qint64 current, qint64 total) void Technic::SingleZipPackInstallTask::downloadProgressChanged(qint64 current, qint64 total)
{ {
m_abortable = true;
setProgress(current / 2, total); setProgress(current / 2, total);
} }

View File

@ -36,6 +36,9 @@ class MULTIMC_LOGIC_EXPORT SingleZipPackInstallTask : public InstanceTask
public: public:
SingleZipPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion); SingleZipPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion);
bool canAbort() const override { return true; }
bool abort() override;
protected: protected:
void executeTask() override; void executeTask() override;
@ -48,6 +51,8 @@ private slots:
void extractAborted(); void extractAborted();
private: private:
bool m_abortable = false;
QUrl m_sourceUrl; QUrl m_sourceUrl;
QString m_minecraftVersion; QString m_minecraftVersion;
QString m_archivePath; QString m_archivePath;

View File

@ -27,6 +27,14 @@ Technic::SolderPackInstallTask::SolderPackInstallTask(const QUrl &sourceUrl, con
m_minecraftVersion = minecraftVersion; m_minecraftVersion = minecraftVersion;
} }
bool Technic::SolderPackInstallTask::abort() {
if(m_abortable)
{
return m_filesNetJob->abort();
}
return false;
}
void Technic::SolderPackInstallTask::executeTask() void Technic::SolderPackInstallTask::executeTask()
{ {
setStatus(tr("Finding recommended version:\n%1").arg(m_sourceUrl.toString())); setStatus(tr("Finding recommended version:\n%1").arg(m_sourceUrl.toString()));
@ -106,6 +114,8 @@ void Technic::SolderPackInstallTask::fileListSucceeded()
void Technic::SolderPackInstallTask::downloadSucceeded() void Technic::SolderPackInstallTask::downloadSucceeded()
{ {
m_abortable = false;
setStatus(tr("Extracting modpack")); setStatus(tr("Extracting modpack"));
m_filesNetJob.reset(); m_filesNetJob.reset();
m_extractFuture = QtConcurrent::run([this]() m_extractFuture = QtConcurrent::run([this]()
@ -132,12 +142,14 @@ void Technic::SolderPackInstallTask::downloadSucceeded()
void Technic::SolderPackInstallTask::downloadFailed(QString reason) void Technic::SolderPackInstallTask::downloadFailed(QString reason)
{ {
m_abortable = false;
emitFailed(reason); emitFailed(reason);
m_filesNetJob.reset(); m_filesNetJob.reset();
} }
void Technic::SolderPackInstallTask::downloadProgressChanged(qint64 current, qint64 total) void Technic::SolderPackInstallTask::downloadProgressChanged(qint64 current, qint64 total)
{ {
m_abortable = true;
setProgress(current / 2, total); setProgress(current / 2, total);
} }

View File

@ -29,6 +29,9 @@ namespace Technic
public: public:
explicit SolderPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion); explicit SolderPackInstallTask(const QUrl &sourceUrl, const QString &minecraftVersion);
bool canAbort() const override { return true; }
bool abort() override;
protected: protected:
//! Entry point for tasks. //! Entry point for tasks.
virtual void executeTask() override; virtual void executeTask() override;
@ -43,6 +46,8 @@ namespace Technic
void extractAborted(); void extractAborted();
private: private:
bool m_abortable = false;
NetJobPtr m_filesNetJob; NetJobPtr m_filesNetJob;
QUrl m_sourceUrl; QUrl m_sourceUrl;
QString m_minecraftVersion; QString m_minecraftVersion;