File indexing completed on 2024-05-12 05:50:22
0001 /* 0002 SPDX-FileCopyrightText: 2007 Henrique Pinto <henrique.pinto@kdemail.net> 0003 SPDX-FileCopyrightText: 2008-2009 Harald Hvaal <haraldhv@stud.ntnu.no> 0004 SPDX-FileCopyrightText: 2016 Vladyslav Batyrenko <mvlabat@gmail.com> 0005 0006 SPDX-License-Identifier: BSD-2-Clause 0007 */ 0008 0009 #ifndef LIBARCHIVEPLUGIN_H 0010 #define LIBARCHIVEPLUGIN_H 0011 0012 #include "archiveinterface.h" 0013 0014 #include <archive.h> 0015 0016 #include <QScopedPointer> 0017 0018 using namespace Kerfuffle; 0019 0020 class LibarchivePlugin : public ReadWriteArchiveInterface 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 explicit LibarchivePlugin(QObject *parent, const QVariantList &args); 0026 ~LibarchivePlugin() override; 0027 0028 bool list() override; 0029 bool doKill() override; 0030 bool extractFiles(const QVector<Archive::Entry *> &files, const QString &destinationDirectory, const ExtractionOptions &options) override; 0031 0032 bool addFiles(const QVector<Archive::Entry *> &files, 0033 const Archive::Entry *destination, 0034 const CompressionOptions &options, 0035 uint numberOfEntriesToAdd = 0) override; 0036 bool moveFiles(const QVector<Archive::Entry *> &files, Archive::Entry *destination, const CompressionOptions &options) override; 0037 bool copyFiles(const QVector<Archive::Entry *> &files, Archive::Entry *destination, const CompressionOptions &options) override; 0038 bool deleteFiles(const QVector<Archive::Entry *> &files) override; 0039 bool addComment(const QString &comment) override; 0040 bool testArchive() override; 0041 bool hasBatchExtractionProgress() const override; 0042 0043 protected: 0044 struct ArchiveReadCustomDeleter { 0045 static inline void cleanup(struct archive *a) 0046 { 0047 if (a) { 0048 archive_read_free(a); 0049 } 0050 } 0051 }; 0052 0053 struct ArchiveWriteCustomDeleter { 0054 static inline void cleanup(struct archive *a) 0055 { 0056 if (a) { 0057 archive_write_free(a); 0058 } 0059 } 0060 }; 0061 0062 typedef QScopedPointer<struct archive, ArchiveReadCustomDeleter> ArchiveRead; 0063 typedef QScopedPointer<struct archive, ArchiveWriteCustomDeleter> ArchiveWrite; 0064 0065 bool initializeReader(); 0066 void emitEntryFromArchiveEntry(struct archive_entry *entry, bool isRawFormat = false); 0067 void copyData(const QString &filename, struct archive *dest, bool partialprogress = true); 0068 void copyData(const QString &filename, struct archive *source, struct archive *dest, bool partialprogress = true); 0069 0070 ArchiveRead m_archiveReader; 0071 ArchiveRead m_archiveReadDisk; 0072 0073 private Q_SLOTS: 0074 void slotRestoreWorkingDir(); 0075 0076 private: 0077 int extractionFlags() const; 0078 QString convertCompressionName(const QString &method); 0079 bool emitCorruptArchive(); 0080 const QString uncompressedFileName() const; 0081 void copyDataBlock(const QString &filename, struct archive *source, struct archive *dest, bool partialprogress = true); 0082 0083 int m_cachedArchiveEntryCount; 0084 qlonglong m_currentExtractedFilesSize; 0085 bool m_emitNoEntries; 0086 qlonglong m_extractedFilesSize; 0087 QVector<Archive::Entry *> m_emittedEntries; 0088 QString m_oldWorkingDir; 0089 QStringList m_rawMimetypes; 0090 }; 0091 0092 #endif // LIBARCHIVEPLUGIN_H