fix: prevent crash when aborting import task while extracting pack

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2023-02-24 20:34:43 -03:00
parent fda9ca1e34
commit d5c6704475
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 11 additions and 10 deletions

View File

@ -66,7 +66,12 @@ bool InstanceImportTask::abort()
if (m_filesNetJob)
m_filesNetJob->abort();
m_extractFuture.cancel();
if (m_extractFuture.isRunning()) {
// NOTE: The tasks created by QtConcurrent::run() can't actually get cancelled,
// but we can use this call to check the state when the extraction finishes.
m_extractFuture.cancel();
m_extractFuture.waitForFinished();
}
return Task::abort();
}
@ -185,18 +190,20 @@ void InstanceImportTask::processZipPack()
// make sure we extract just the pack
m_extractFuture = QtConcurrent::run(QThreadPool::globalInstance(), MMCZip::extractSubDir, m_packZip.get(), root, extractDir.absolutePath());
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::finished, this, &InstanceImportTask::extractFinished);
connect(&m_extractFutureWatcher, &QFutureWatcher<QStringList>::canceled, this, &InstanceImportTask::extractAborted);
m_extractFutureWatcher.setFuture(m_extractFuture);
}
void InstanceImportTask::extractFinished()
{
m_packZip.reset();
if (!m_extractFuture.result())
{
if (m_extractFuture.isCanceled())
return;
if (!m_extractFuture.result().has_value()) {
emitFailed(tr("Failed to extract modpack"));
return;
}
QDir extractDir(m_stagingPath);
qDebug() << "Fixing permissions for extracted pack files...";
@ -250,11 +257,6 @@ void InstanceImportTask::extractFinished()
}
}
void InstanceImportTask::extractAborted()
{
emitAborted();
}
void InstanceImportTask::processFlame()
{
FlameCreationTask* inst_creation_task = nullptr;

View File

@ -81,7 +81,6 @@ private slots:
void downloadProgressChanged(qint64 current, qint64 total);
void downloadAborted();
void extractFinished();
void extractAborted();
private: /* data */
NetJob::Ptr m_filesNetJob;