handle file removal in ExportToZipTask

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-07-17 16:55:26 +03:00
parent 78ee63af38
commit 64041a84a2
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
5 changed files with 26 additions and 16 deletions

View File

@ -480,4 +480,15 @@ void ExportToZipTask::exportZip()
emitSucceeded();
}
void ExportToZipTask::emitAborted()
{
QFile::remove(m_output_path);
Task::emitAborted();
}
void ExportToZipTask::emitFailed(QString reason)
{
QFile::remove(m_output_path);
Task::emitFailed(reason);
}
} // namespace MMCZip

View File

@ -148,7 +148,12 @@ bool collectFileListRecursively(const QString& rootDir, const QString& subDir, Q
class ExportToZipTask : public Task {
public:
ExportToZipTask(QString outputPath, QDir dir, QFileInfoList files, QString destinationPrefix = "", bool followSymlinks = false)
: m_output(outputPath), m_dir(dir), m_files(files), m_destination_prefix(destinationPrefix), m_follow_symlinks(followSymlinks)
: m_output_path(outputPath)
, m_output(outputPath)
, m_dir(dir)
, m_files(files)
, m_destination_prefix(destinationPrefix)
, m_follow_symlinks(followSymlinks)
{
setAbortable(true);
};
@ -164,7 +169,12 @@ class ExportToZipTask : public Task {
virtual void executeTask() override;
void exportZip();
protected slots:
virtual void emitAborted() override;
virtual void emitFailed(QString reason = "") override;
private:
QString m_output_path;
QuaZip m_output;
QDir m_dir;
QFileInfoList m_files;

View File

@ -344,14 +344,10 @@ void FlamePackExportTask::buildZip()
});
connect(zipTask.get(), &Task::succeeded, this, &FlamePackExportTask::emitSucceeded);
connect(zipTask.get(), &Task::aborted, this, [this]() {
QFile::remove(output);
emitAborted();
});
connect(zipTask.get(), &Task::aborted, this, &FlamePackExportTask::emitAborted);
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
progressStep->state = TaskStepState::Failed;
stepProgress(*progressStep);
QFile::remove(output);
emitFailed(reason);
});
connect(zipTask.get(), &Task::stepProgress, this, &FlamePackExportTask::propogateStepProgress);

View File

@ -208,14 +208,10 @@ void ModrinthPackExportTask::buildZip()
});
connect(zipTask.get(), &Task::succeeded, this, &ModrinthPackExportTask::emitSucceeded);
connect(zipTask.get(), &Task::aborted, this, [this]() {
QFile::remove(output);
emitAborted();
});
connect(zipTask.get(), &Task::aborted, this, &ModrinthPackExportTask::emitAborted);
connect(zipTask.get(), &Task::failed, this, [this, progressStep](QString reason) {
progressStep->state = TaskStepState::Failed;
stepProgress(*progressStep);
QFile::remove(output);
emitFailed(reason);
});
connect(zipTask.get(), &Task::stepProgress, this, &ModrinthPackExportTask::propogateStepProgress);

View File

@ -146,11 +146,8 @@ void ExportInstanceDialog::doExport()
auto task = makeShared<MMCZip::ExportToZipTask>(output, m_instance->instanceRoot(), files, "", true);
connect(task.get(), &Task::failed, this, [this, output](QString reason) {
CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show();
QFile::remove(output);
});
connect(task.get(), &Task::aborted, this, [output] { QFile::remove(output); });
connect(task.get(), &Task::failed, this,
[this, output](QString reason) { CustomMessageBox::selectable(this, tr("Error"), reason, QMessageBox::Critical)->show(); });
connect(task.get(), &Task::finished, this, [task] { task->deleteLater(); });
ProgressDialog progress(this);