diff options
author | kh1 <karsten.heimrich@digia.com> | 2014-10-14 17:03:54 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2014-10-15 17:10:18 +0200 |
commit | 84875396b75f5615afa637f9633d19bbc79e08e0 (patch) | |
tree | 012fe931425ae267361a608c0c63e0d05e4ee03e /src/libs/installer/binaryformat.h | |
parent | ec92e19193eb9d69a3cf18979d6434cf04764902 (diff) |
Overhaul the binary format API.
Adjust some naming. Add documentation. Make the Resource class
handle files only, this is sufficient to read and map inbuild
resources. Keep the QResources inside the manager as well, no
need to handle them separate. Remove read, write functions from
collection class, the API was just unclear how to use. Still it
is far from intuitive in the manager class either. If we open a
Resource, we need to close it on our own case they are pointers.
Change-Id: Ic8aa32a84a15ac774fe1194ba0dbb5733f7216d6
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@digia.com>
Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/binaryformat.h')
-rw-r--r-- | src/libs/installer/binaryformat.h | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/src/libs/installer/binaryformat.h b/src/libs/installer/binaryformat.h index d2fc68987..e09e79318 100644 --- a/src/libs/installer/binaryformat.h +++ b/src/libs/installer/binaryformat.h @@ -42,11 +42,13 @@ #ifndef BINARYFORMAT_H #define BINARYFORMAT_H +#include "installer_global.h" #include "range.h" -#include "qinstallerglobal.h" +#include <QCoreApplication> #include <QFile> #include <QList> +#include <QSharedPointer> namespace QInstaller { @@ -65,12 +67,8 @@ class INSTALLER_EXPORT Resource : public QIODevice public: explicit Resource(const QString &path); - Resource(const QByteArray &name, const QString &path); - - explicit Resource(const QSharedPointer<QIODevice> &device); - Resource(const QSharedPointer<QIODevice> &device, const Range<qint64> &segment); - Resource(const QByteArray &name, const QSharedPointer<QIODevice> &device, - const Range<qint64> &segment); + Resource(const QString &path, const QByteArray &name); + Resource(const QString &path, const Range<qint64> &segment); ~Resource(); bool open(); @@ -83,6 +81,7 @@ public: void setName(const QByteArray &name); Range<qint64> segment() const { return m_segment; } + void setSegment(const Range<qint64> &segment) { m_segment = segment; } void copyData(QFileDevice *out) { copyData(this, out); } static void copyData(Resource *archive, QFileDevice *out); @@ -90,14 +89,14 @@ public: private: qint64 readData(char *data, qint64 maxSize); qint64 writeData(const char *data, qint64 maxSize); + bool open(OpenMode mode) { return QIODevice::open(mode); } + void setOpenMode(OpenMode mode) { QIODevice::setOpenMode(mode); } private: - QSharedPointer<QIODevice> m_device; - Range<qint64> m_segment; - QFile m_inputFile; + QFile m_file; QByteArray m_name; - bool m_deviceOpened; + Range<qint64> m_segment; }; @@ -106,39 +105,33 @@ class INSTALLER_EXPORT ResourceCollection Q_DECLARE_TR_FUNCTIONS(ResourceCollection) public: - ResourceCollection() {} + ResourceCollection(); explicit ResourceCollection(const QByteArray &name); QByteArray name() const; void setName(const QByteArray &ba); - Range<qint64> segment() const { return m_segment; } - void setSegment(const Range<qint64> &segment) const { m_segment = segment; } - - void write(QFileDevice *dev, qint64 positionOffset) const; - void read(const QSharedPointer<QFile> &dev, qint64 offset); - QList<QSharedPointer<Resource> > resources() const; QSharedPointer<Resource> resourceByName(const QByteArray &name) const; void appendResource(const QSharedPointer<Resource> &resource); void appendResources(const QList<QSharedPointer<Resource> > &resources); - private: QByteArray m_name; - mutable Range<qint64> m_segment; QList<QSharedPointer<Resource> > m_resources; }; class INSTALLER_EXPORT ResourceCollectionManager { + Q_DECLARE_TR_FUNCTIONS(ResourceCollectionManager) + public: + void read(QFileDevice *dev, qint64 offset); Range<qint64> write(QFileDevice *dev, qint64 offset) const; - void read(const QSharedPointer<QFile> &dev, qint64 offset); - void reset(); + void clear(); int collectionCount() const; QList<ResourceCollection> collections() const; @@ -148,10 +141,6 @@ public: void insertCollection(const ResourceCollection &collection); private: - void writeIndexEntry(const ResourceCollection &coll, QFileDevice *dev) const; - ResourceCollection readIndexEntry(const QSharedPointer<QFile> &dev, qint64 offset); - -private: QHash<QByteArray, ResourceCollection> m_collections; }; |