File indexing completed on 2024-12-01 05:20:02

0001 /*
0002     SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
0003     SPDX-FileCopyrightText: 2002 Szombathelyi György <gyurco@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2003 Leo Savernik <l.savernik@aon.at>
0005     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0006 
0007     This file is heavily based on ktar from kdelibs
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #ifndef KISO_H
0013 #define KISO_H
0014 
0015 // QtCore
0016 #include <QDateTime>
0017 #include <QString>
0018 #include <QStringList>
0019 
0020 #include "../../app/krdebuglogger.h"
0021 #include "kisodirectory.h"
0022 #include "kisofile.h"
0023 
0024 /**
0025  * @short A class for reading (optionally compressed) iso9660 files.
0026  */
0027 class KIso : public KArchive
0028 {
0029 public:
0030     /**
0031      * Creates an instance that operates on the given filename.
0032      * using the compression filter associated to given mimetype.
0033      *
0034      * @param filename is a local path (e.g. "/home/weis/myfile.tgz")
0035      * @param mimetype "application/x-gzip" or "application/x-bzip2"
0036      * Do not use application/x-tgz or so. Only the compression layer !
0037      * If the mimetype is omitted, it will be determined from the filename.
0038      */
0039     explicit KIso(const QString &filename, const QString &mimetype = QString());
0040 
0041     /**
0042      * Creates an instance that operates on the given device.
0043      * The device can be compressed (KFilterDev) or not (QFile, etc.).
0044      * WARNING: don't assume that giving a QFile here will decompress the file,
0045      * in case it's compressed!
0046      */
0047     explicit KIso(QIODevice *dev);
0048 
0049     /**
0050      * If the .iso is still opened, then it will be
0051      * closed automatically by the destructor.
0052      */
0053     virtual ~KIso();
0054 
0055     /**
0056      * The name of the os file, as passed to the constructor
0057      * Null if you used the QIODevice constructor.
0058      */
0059     QString fileName()
0060     {
0061         return m_filename;
0062     }
0063 
0064     bool writeDir(const QString &, const QString &, const QString &, mode_t, time_t, time_t, time_t);
0065     bool writeSymLink(const QString &, const QString &, const QString &, const QString &, mode_t, time_t, time_t, time_t);
0066     bool prepareWriting(const QString &, const QString &, const QString &, qint64, mode_t, time_t, time_t, time_t);
0067     bool finishWriting(qint64);
0068 
0069     void setStartSec(int startsec)
0070     {
0071         m_startsec = startsec;
0072     }
0073     int startSec()
0074     {
0075         return m_startsec;
0076     }
0077 
0078     bool showhidden, showrr;
0079     int level, joliet;
0080     KIsoDirectory *dirent;
0081 
0082 protected:
0083     /**
0084      * Opens the archive for reading.
0085      * Parses the directory listing of the archive
0086      * and creates the KArchiveDirectory/KArchiveFile entries.
0087      *
0088      */
0089     void readParams();
0090     virtual bool openArchive(QIODevice::OpenMode mode) override;
0091     virtual bool closeArchive() override;
0092     virtual bool doWriteDir(const QString &, const QString &, const QString &, mode_t, const QDateTime &, const QDateTime &, const QDateTime &) override;
0093     virtual bool
0094     doWriteSymLink(const QString &, const QString &, const QString &, const QString &, mode_t, const QDateTime &, const QDateTime &, const QDateTime &)
0095         override;
0096     virtual bool
0097     doPrepareWriting(const QString &, const QString &, const QString &, qint64, mode_t, const QDateTime &, const QDateTime &, const QDateTime &) override;
0098     virtual bool doFinishWriting(qint64) override;
0099 
0100 private:
0101     /**
0102      * @internal
0103      */
0104     void addBoot(struct el_torito_boot_descriptor *bootdesc);
0105     void prepareDevice(const QString &filename, const QString &mimetype, bool forced = false);
0106     int m_startsec;
0107 
0108     QString m_filename;
0109 
0110 protected:
0111     virtual void virtual_hook(int id, void *data) override;
0112 
0113 private:
0114     class KIsoPrivate;
0115     KIsoPrivate *d;
0116 };
0117 
0118 #endif