| 1 | /* This file is part of the KDE libraries |
| 2 | SPDX-FileCopyrightText: 2011 Mario Bensi <mbensi@ipsquad.net> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.0-or-later |
| 5 | */ |
| 6 | #ifndef K7ZIP_H |
| 7 | #define K7ZIP_H |
| 8 | |
| 9 | #include <karchive.h> |
| 10 | |
| 11 | /*! |
| 12 | * \class K7Zip |
| 13 | * \inmodule KArchive |
| 14 | * |
| 15 | * \brief A class for reading / writing p7zip archives. |
| 16 | */ |
| 17 | class KARCHIVE_EXPORT K7Zip : public KArchive |
| 18 | { |
| 19 | Q_DECLARE_TR_FUNCTIONS(K7Zip) |
| 20 | |
| 21 | public: |
| 22 | /*! |
| 23 | * Creates an instance that operates on the given filename |
| 24 | * using the compression filter associated to given mimetype. |
| 25 | * |
| 26 | * \a filename is a local path (e.g. "/home/user/myfile.7z") |
| 27 | */ |
| 28 | explicit K7Zip(const QString &filename); |
| 29 | |
| 30 | /*! |
| 31 | * Creates an instance that operates on the given device. |
| 32 | * |
| 33 | * The device can be compressed (KCompressionDevice) or not (QFile, etc.). |
| 34 | * |
| 35 | * \warning Do not assume that giving a QFile here will decompress the file, |
| 36 | * in case it's compressed! |
| 37 | * |
| 38 | * \a dev the device to read from. If the source is compressed, the |
| 39 | * QIODevice must take care of decompression |
| 40 | */ |
| 41 | explicit K7Zip(QIODevice *dev); |
| 42 | |
| 43 | /*! |
| 44 | * If the archive is still opened, then it will be |
| 45 | * closed automatically by the destructor. |
| 46 | */ |
| 47 | ~K7Zip() override; |
| 48 | |
| 49 | /*! |
| 50 | * Sets the password to use for encrypted archives. |
| 51 | * |
| 52 | * This method must be called before opening the archive. |
| 53 | * |
| 54 | * \note Currently only AES decryption is supported. |
| 55 | * |
| 56 | * \a password the password to use for encrypted archive |
| 57 | * \since 6.13 |
| 58 | */ |
| 59 | void setPassword(const QString &password); |
| 60 | |
| 61 | /*! |
| 62 | * Whether the archive needs a password to be opened. |
| 63 | * |
| 64 | * \note This can only be called after open() has been called once. |
| 65 | * |
| 66 | * Returns \c true if the archive requires a password to be opened |
| 67 | * \since 6.13 |
| 68 | */ |
| 69 | bool passwordNeeded() const; |
| 70 | |
| 71 | protected: |
| 72 | // Reimplemented from KArchive |
| 73 | bool doWriteSymLink(const QString &name, |
| 74 | const QString &target, |
| 75 | const QString &user, |
| 76 | const QString &group, |
| 77 | mode_t perm, |
| 78 | const QDateTime &atime, |
| 79 | const QDateTime &mtime, |
| 80 | const QDateTime &ctime) override; |
| 81 | // Reimplemented from KArchive |
| 82 | bool doWriteDir(const QString &name, |
| 83 | const QString &user, |
| 84 | const QString &group, |
| 85 | mode_t perm, |
| 86 | const QDateTime &atime, |
| 87 | const QDateTime &mtime, |
| 88 | const QDateTime &ctime) override; |
| 89 | // Reimplemented from KArchive |
| 90 | bool doPrepareWriting(const QString &name, |
| 91 | const QString &user, |
| 92 | const QString &group, |
| 93 | qint64 size, |
| 94 | mode_t perm, |
| 95 | const QDateTime &atime, |
| 96 | const QDateTime &mtime, |
| 97 | const QDateTime &ctime) override; |
| 98 | // Reimplemented from KArchive |
| 99 | bool doFinishWriting(qint64 size) override; |
| 100 | |
| 101 | // Reimplemented from KArchive |
| 102 | bool doWriteData(const char *data, qint64 size) override; |
| 103 | |
| 104 | /*! |
| 105 | * Opens the archive for reading. |
| 106 | * |
| 107 | * Parses the directory listing of the archive |
| 108 | * and creates the KArchiveDirectory/KArchiveFile entries. |
| 109 | * |
| 110 | * \a mode the mode of the file |
| 111 | */ |
| 112 | bool openArchive(QIODevice::OpenMode mode) override; |
| 113 | bool closeArchive() override; |
| 114 | |
| 115 | protected: |
| 116 | void virtual_hook(int id, void *data) override; |
| 117 | |
| 118 | private: |
| 119 | class K7ZipPrivate; |
| 120 | K7ZipPrivate *const d; |
| 121 | }; |
| 122 | |
| 123 | #endif |
| 124 | |