use shared pointer

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>

use shared pointer
This commit is contained in:
Trial97 2023-07-16 21:12:53 +03:00
parent cadb7142f0
commit 79222a56e3
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
2 changed files with 8 additions and 18 deletions

View File

@ -451,7 +451,7 @@ void ExportToZipTask::executeTask()
absolute = file.canonicalFilePath(); absolute = file.canonicalFilePath();
} }
if (!JlCompress::compressFile(m_output, absolute, m_destinationPrefix + relative)) { if (!JlCompress::compressFile(m_output.get(), absolute, m_destinationPrefix + relative)) {
emitFailed(tr("Could not read and compress %1").arg(relative)); emitFailed(tr("Could not read and compress %1").arg(relative));
return; return;
} }

View File

@ -43,6 +43,7 @@
#include <QSet> #include <QSet>
#include <QString> #include <QString>
#include <functional> #include <functional>
#include <memory>
#include <optional> #include <optional>
#include "minecraft/mod/Mod.h" #include "minecraft/mod/Mod.h"
#include "tasks/Task.h" #include "tasks/Task.h"
@ -145,39 +146,28 @@ bool collectFileListRecursively(const QString& rootDir, const QString& subDir, Q
class ExportToZipTask : public Task { class ExportToZipTask : public Task {
public: public:
ExportToZipTask(QuaZip* output, ExportToZipTask(std::shared_ptr<QuaZip> output,
QDir dir, QDir dir,
QFileInfoList files, QFileInfoList files,
QString destinationPrefix = "", QString destinationPrefix = "",
bool followSymlinks = false, bool followSymlinks = false)
bool cleanUp = false) : m_output(output), m_dir(dir), m_files(files), m_destinationPrefix(destinationPrefix), m_followSymlinks(followSymlinks)
: m_output(output)
, m_dir(dir)
, m_files(files)
, m_destinationPrefix(destinationPrefix)
, m_followSymlinks(followSymlinks)
, m_cleanUp(cleanUp)
{ {
setAbortable(true); setAbortable(true);
}; };
ExportToZipTask(QString outputPath, QString dir, QFileInfoList files, QString destinationPrefix = "", bool followSymlinks = false) ExportToZipTask(QString outputPath, QString dir, QFileInfoList files, QString destinationPrefix = "", bool followSymlinks = false)
: ExportToZipTask(new QuaZip(outputPath), QDir(dir), files, destinationPrefix, followSymlinks, true){}; : ExportToZipTask(std::make_shared<QuaZip>(outputPath), QDir(dir), files, destinationPrefix, followSymlinks){};
virtual ~ExportToZipTask() virtual ~ExportToZipTask() = default;
{
if (m_cleanUp)
delete m_output;
}
protected: protected:
virtual void executeTask() override; virtual void executeTask() override;
private: private:
QuaZip* m_output; std::shared_ptr<QuaZip> m_output;
QDir m_dir; QDir m_dir;
QFileInfoList m_files; QFileInfoList m_files;
QString m_destinationPrefix; QString m_destinationPrefix;
bool m_followSymlinks; bool m_followSymlinks;
bool m_cleanUp;
}; };
} // namespace MMCZip } // namespace MMCZip