MythTV master
unzip2.h
Go to the documentation of this file.
1/*
2 * Class UnZip
3 *
4 * Copyright (c) David Hampton 2021
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21// libzip
22#include "zip.h"
23
24// Qt headers
25#include <QDir>
26#include <QString>
27#include <QFileInfo>
28
29class UnZip
30{
31 // NOLINTNEXTLINE(readability-uppercase-literal-suffix)
32 static constexpr uint64_t kSTATS_REQUIRED {ZIP_STAT_NAME|ZIP_STAT_INDEX|ZIP_STAT_SIZE|ZIP_STAT_MTIME|ZIP_STAT_ENCRYPTION_METHOD};
33
34 struct zipEntry
35 {
36 int m_index {0};
37 zip_stat_t m_stats {};
38 zip_uint32_t m_attributes {0};
39 QFileInfo m_fi;
40 };
41
42 public:
43 explicit UnZip(QString zipFile);
44 ~UnZip();
45 bool extractFile(const QString& outDir);
46
47 private:
48 bool isValid() { return m_zip != nullptr; };
49 bool getEntryStats(zipEntry& entry);
50 void getEntryAttrs(zipEntry& entry);
51 static QFileDevice::Permissions zipToQtPerms(const zipEntry& entry);
52 static bool zipCreateDirectory(const zipEntry& entry);
53 bool zipValidateFilename(const QFileInfo& fi);
54 static void zipSetFileAttributes(const zipEntry& entry, QFile& outfile);
55 bool zipCreateSymlink(const zipEntry& entry);
56 bool zipWriteOneFile(const zipEntry& entry);
57
59
60 // Info about zip file itself
62 zip_t *m_zip {nullptr};
63 zip_int64_t m_zipFileCount {-1};
64};
Definition: unzip2.h:30
zip_t * m_zip
Definition: unzip2.h:62
static QFileDevice::Permissions zipToQtPerms(const zipEntry &entry)
Definition: unzip2.cpp:118
UnZip(QString zipFile)
Definition: unzip2.cpp:38
bool zipCreateSymlink(const zipEntry &entry)
Definition: unzip2.cpp:163
static bool zipCreateDirectory(const zipEntry &entry)
Definition: unzip2.cpp:91
zip_int64_t m_zipFileCount
Definition: unzip2.h:63
bool zipWriteOneFile(const zipEntry &entry)
Definition: unzip2.cpp:201
QDir m_outDir
Definition: unzip2.h:58
bool getEntryStats(zipEntry &entry)
Definition: unzip2.cpp:62
bool extractFile(const QString &outDir)
Definition: unzip2.cpp:264
QString m_zipFileName
Definition: unzip2.h:61
static void zipSetFileAttributes(const zipEntry &entry, QFile &outfile)
Definition: unzip2.cpp:148
~UnZip()
Definition: unzip2.cpp:51
bool isValid()
Definition: unzip2.h:48
bool zipValidateFilename(const QFileInfo &fi)
Definition: unzip2.cpp:107
static constexpr uint64_t kSTATS_REQUIRED
Definition: unzip2.h:32
void getEntryAttrs(zipEntry &entry)
Definition: unzip2.cpp:82
zip_stat_t m_stats
Definition: unzip2.h:37
zip_uint32_t m_attributes
Definition: unzip2.h:38
QFileInfo m_fi
Definition: unzip2.h:39