handle file removal in ExportToZipTask
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
		| @@ -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 | ||||
| @@ -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; | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Trial97
					Trial97