00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef OSDAB_UNZIP__H
00029 #define OSDAB_UNZIP__H
00030
00031 #include <QtGlobal>
00032 #include <QMap>
00033 #include <QDateTime>
00034
00035 #include <zlib.h>
00036
00037 #include "mythbaseexp.h"
00038
00039 class UnzipPrivate;
00040 class QIODevice;
00041 class QFile;
00042 class QDir;
00043 class QStringList;
00044 class QString;
00045
00046
00047 class MBASE_PUBLIC UnZip
00048 {
00049 public:
00050 enum ErrorCode
00051 {
00052 Ok,
00053 ZlibInit,
00054 ZlibError,
00055 OpenFailed,
00056 PartiallyCorrupted,
00057 Corrupted,
00058 WrongPassword,
00059 NoOpenArchive,
00060 FileNotFound,
00061 ReadFailed,
00062 WriteFailed,
00063 SeekFailed,
00064 CreateDirFailed,
00065 InvalidDevice,
00066 InvalidArchive,
00067 HeaderConsistencyError,
00068
00069 Skip, SkipAll
00070 };
00071
00072 enum ExtractionOption
00073 {
00075 ExtractPaths = 0x0001,
00077 SkipPaths = 0x0002
00078 };
00079 Q_DECLARE_FLAGS(ExtractionOptions, ExtractionOption)
00080
00081 enum CompressionMethod
00082 {
00083 NoCompression, Deflated, UnknownCompression
00084 };
00085
00086 enum FileType
00087 {
00088 File, Directory
00089 };
00090
00091 struct ZipEntry
00092 {
00093 ZipEntry();
00094
00095 QString filename;
00096 QString comment;
00097
00098 quint32 compressedSize;
00099 quint32 uncompressedSize;
00100 quint32 crc32;
00101
00102 QDateTime lastModified;
00103
00104 CompressionMethod compression;
00105 FileType type;
00106
00107 bool encrypted;
00108 };
00109
00110 UnZip();
00111 virtual ~UnZip();
00112
00113 bool isOpen() const;
00114
00115 ErrorCode openArchive(const QString& filename);
00116 ErrorCode openArchive(QIODevice* device);
00117 void closeArchive();
00118
00119 QString archiveComment() const;
00120
00121 QString formatError(UnZip::ErrorCode c) const;
00122
00123 bool contains(const QString& file) const;
00124
00125 QStringList fileList() const;
00126 QList<ZipEntry> entryList() const;
00127
00128 ErrorCode extractAll(const QString& dirname, ExtractionOptions options = ExtractPaths);
00129 ErrorCode extractAll(const QDir& dir, ExtractionOptions options = ExtractPaths);
00130
00131 ErrorCode extractFile(const QString& filename, const QString& dirname, ExtractionOptions options = ExtractPaths);
00132 ErrorCode extractFile(const QString& filename, const QDir& dir, ExtractionOptions options = ExtractPaths);
00133 ErrorCode extractFile(const QString& filename, QIODevice* device, ExtractionOptions options = ExtractPaths);
00134
00135 ErrorCode extractFiles(const QStringList& filenames, const QString& dirname, ExtractionOptions options = ExtractPaths);
00136 ErrorCode extractFiles(const QStringList& filenames, const QDir& dir, ExtractionOptions options = ExtractPaths);
00137
00138 void setPassword(const QString& pwd);
00139
00140 private:
00141 UnzipPrivate* d;
00142 };
00143
00144 Q_DECLARE_OPERATORS_FOR_FLAGS(UnZip::ExtractionOptions)
00145
00146 #endif // OSDAB_UNZIP__H