1 /*****************************************************************************
2  * Copyright (C) 2000 David Faure <faure@kde.org>                            *
3  * Copyright (C) 2002 Szombathelyi György <gyurco@users.sourceforge.net>     *
4  * Copyright (C) 2003 Leo Savernik <l.savernik@aon.at>                       *
5  * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org]              *
6  *                                                                           *
7  * This file is heavily based on ktar from kdelibs                           *
8  *                                                                           *
9  * This file is part of Krusader [https://krusader.org].                     *
10  *                                                                           *
11  * Krusader is free software: you can redistribute it and/or modify          *
12  * it under the terms of the GNU General Public License as published by      *
13  * the Free Software Foundation, either version 2 of the License, or         *
14  * (at your option) any later version.                                       *
15  *                                                                           *
16  * Krusader is distributed in the hope that it will be useful,               *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
19  * GNU General Public License for more details.                              *
20  *                                                                           *
21  * You should have received a copy of the GNU General Public License         *
22  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
23  *****************************************************************************/
24 
25 #ifndef KISO_H
26 #define KISO_H
27 
28 // QtCore
29 #include <QDateTime>
30 #include <QString>
31 #include <QStringList>
32 
33 #include "../krusader/krdebuglogger.h"
34 #include "kisofile.h"
35 #include "kisodirectory.h"
36 
37 /**
38  * @short A class for reading (optionally compressed) iso9660 files.
39  */
40 class KIso : public KArchive
41 {
42 public:
43     /**
44      * Creates an instance that operates on the given filename.
45      * using the compression filter associated to given mimetype.
46      *
47      * @param filename is a local path (e.g. "/home/weis/myfile.tgz")
48      * @param mimetype "application/x-gzip" or "application/x-bzip2"
49      * Do not use application/x-tgz or so. Only the compression layer !
50      * If the mimetype is omitted, it will be determined from the filename.
51      */
52     explicit KIso(const QString& filename, const QString & mimetype = QString());
53 
54     /**
55      * Creates an instance that operates on the given device.
56      * The device can be compressed (KFilterDev) or not (QFile, etc.).
57      * WARNING: don't assume that giving a QFile here will decompress the file,
58      * in case it's compressed!
59      */
60     explicit KIso(QIODevice * dev);
61 
62     /**
63      * If the .iso is still opened, then it will be
64      * closed automatically by the destructor.
65      */
66     virtual ~KIso();
67 
68     /**
69      * The name of the os file, as passed to the constructor
70      * Null if you used the QIODevice constructor.
71      */
fileName()72     QString fileName() {
73         return m_filename;
74     }
75 
76     bool writeDir(const QString& , const QString& , const QString&, mode_t, time_t, time_t, time_t);
77     bool writeSymLink(const QString &, const QString &, const QString &, const QString &, mode_t, time_t, time_t, time_t);
78     bool prepareWriting(const QString& , const QString& , const QString& , qint64, mode_t, time_t, time_t, time_t);
79     bool finishWriting(qint64);
80 
setStartSec(int startsec)81     void setStartSec(int startsec) {
82         m_startsec = startsec;
83     }
startSec()84     int startSec() {
85         return m_startsec;
86     }
87 
88     bool showhidden, showrr;
89     int level, joliet;
90     KIsoDirectory *dirent;
91 protected:
92     /**
93      * Opens the archive for reading.
94      * Parses the directory listing of the archive
95      * and creates the KArchiveDirectory/KArchiveFile entries.
96      *
97      */
98     void readParams();
99     virtual bool openArchive(QIODevice::OpenMode mode) Q_DECL_OVERRIDE;
100     virtual bool closeArchive() Q_DECL_OVERRIDE;
101     virtual bool doWriteDir(const QString&, const QString&, const QString&, mode_t, const QDateTime &, const QDateTime &, const QDateTime &) Q_DECL_OVERRIDE;
102     virtual bool doWriteSymLink(const QString &, const QString &, const QString &, const QString &, mode_t, const QDateTime &, const QDateTime &, const QDateTime &) Q_DECL_OVERRIDE;
103     virtual bool doPrepareWriting(const QString& , const QString& , const QString& , qint64, mode_t, const QDateTime &, const QDateTime &, const QDateTime &) Q_DECL_OVERRIDE;
104     virtual bool doFinishWriting(qint64) Q_DECL_OVERRIDE;
105 
106 private:
107     /**
108      * @internal
109      */
110     void addBoot(struct el_torito_boot_descriptor* bootdesc);
111     void prepareDevice(const QString & filename, const QString & mimetype, bool forced = false);
112     int m_startsec;
113 
114     QString m_filename;
115 protected:
116 
117     virtual void virtual_hook(int id, void* data) Q_DECL_OVERRIDE;
118 
119 private:
120     class KIsoPrivate;
121     KIsoPrivate * d;
122 };
123 
124 #endif
125