summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libs/installer/binarycontent.cpp66
-rw-r--r--src/libs/installer/binaryformat.cpp357
-rw-r--r--src/libs/installer/binaryformat.h98
-rw-r--r--src/libs/installer/binaryformatengine.cpp78
-rw-r--r--src/libs/installer/binaryformatengine.h20
-rw-r--r--src/libs/installer/binaryformatenginehandler.cpp66
-rw-r--r--src/libs/installer/binaryformatenginehandler.h18
-rw-r--r--src/libs/installer/createlocalrepositoryoperation.cpp28
-rw-r--r--src/libs/installer/downloadarchivesjob.cpp4
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp4
-rw-r--r--tools/binarycreator/binarycreator.cpp38
-rw-r--r--tools/devtool/binarydump.cpp16
-rw-r--r--tools/devtool/binarydump.h2
-rw-r--r--tools/devtool/main.cpp31
14 files changed, 465 insertions, 361 deletions
diff --git a/src/libs/installer/binarycontent.cpp b/src/libs/installer/binarycontent.cpp
index 9bbde5dc4..a60e9ebb5 100644
--- a/src/libs/installer/binarycontent.cpp
+++ b/src/libs/installer/binarycontent.cpp
@@ -146,8 +146,8 @@ public:
QVector<QByteArray> m_resourceMappings;
QVector<Range<qint64> > m_metadataResourceSegments;
- QInstallerCreator::ComponentIndex m_componentIndex;
- QInstallerCreator::BinaryFormatEngineHandler m_binaryFormatEngineHandler;
+ ResourceCollectionManager m_collectionManager;
+ BinaryFormatEngineHandler m_binaryFormatEngineHandler;
};
@@ -156,7 +156,7 @@ BinaryContent::Private::Private()
, m_dataBlockStart(Q_INT64_C(0))
, m_appBinary(0)
, m_binaryDataFile(0)
- , m_binaryFormatEngineHandler(m_componentIndex)
+ , m_binaryFormatEngineHandler(m_collectionManager)
{}
BinaryContent::Private::Private(const QString &path)
@@ -164,7 +164,7 @@ BinaryContent::Private::Private(const QString &path)
, m_dataBlockStart(Q_INT64_C(0))
, m_appBinary(new QFile(path))
, m_binaryDataFile(0)
- , m_binaryFormatEngineHandler(m_componentIndex)
+ , m_binaryFormatEngineHandler(m_collectionManager)
{}
BinaryContent::Private::Private(const Private &other)
@@ -177,7 +177,7 @@ BinaryContent::Private::Private(const Private &other)
, m_performedOperationsData(other.m_performedOperationsData)
, m_resourceMappings(other.m_resourceMappings)
, m_metadataResourceSegments(other.m_metadataResourceSegments)
- , m_componentIndex(other.m_componentIndex)
+ , m_collectionManager(other.m_collectionManager)
, m_binaryFormatEngineHandler(other.m_binaryFormatEngineHandler)
{}
@@ -229,7 +229,7 @@ BinaryContent BinaryContent::readAndRegisterFromBinary(const QString &path)
* \class QInstaller::BinaryContent
*
* BinaryContent handles binary information embedded into executables.
-* Qt resources as well as component information can be stored.
+* Qt resources as well as resource collections can be stored.
*
* Explanation of the binary blob at the end of the installer or separate data file:
*
@@ -397,37 +397,41 @@ void BinaryContent::readBinaryData(BinaryContent &content, const QSharedPointer<
content.d->m_performedOperationsData.append(qMakePair(name, data));
}
- // seek to the position of the component index
+ // seek to the position of the resource collections segment info
const qint64 resourceOffsetAndLengtSize = 2 * sizeof(qint64);
const qint64 resourceSectionSize = resourceOffsetAndLengtSize * layout.resourceCount;
- const qint64 offset = layout.endOfData - layout.indexSize - resourceSectionSize
+ qint64 offset = layout.endOfData - layout.indexSize - resourceSectionSize
- resourceOffsetAndLengtSize;
if (!file->seek(offset)) {
throw Error(QCoreApplication::translate("BinaryContent",
- "Could not seek to component index information."));
+ "Could not seek to read the resource collection segment info."));
}
- const qint64 compIndexStart = QInstaller::retrieveInt64(file.data()) + dataBlockStart;
- if (!file->seek(compIndexStart))
- throw Error(QCoreApplication::translate("BinaryContent", "Could not seek to component index."));
-
- content.d->m_componentIndex = QInstallerCreator::ComponentIndex::read(file, dataBlockStart);
- content.d->m_binaryFormatEngineHandler.setComponentIndex(content.d->m_componentIndex);
-
- if (QInstaller::isVerbose()) {
- const QVector<QInstallerCreator::Component> components = content.d->m_componentIndex.components();
- qDebug() << "Number of components loaded:" << components.count();
- foreach (const QInstallerCreator::Component &component, components) {
- const QVector<QSharedPointer<QInstallerCreator::Archive> > archives = component.archives();
- qDebug() << component.name().data() << "loaded...";
- QStringList archivesWithSize;
- foreach (const QSharedPointer<QInstallerCreator::Archive> &archive, archives) {
- archivesWithSize.append(QString::fromLatin1("%1 - %2")
- .arg(QString::fromUtf8(archive->name()), humanReadableSize(archive->size())));
- }
- if (!archivesWithSize.isEmpty()) {
- qDebug() << " - " << archives.count() << "archives: "
- << qPrintable(archivesWithSize.join(QLatin1String("; ")));
- }
+
+ offset = QInstaller::retrieveInt64(file.data()) + dataBlockStart;
+ if (!file->seek(offset)) {
+ throw Error(QCoreApplication::translate("BinaryContent", "Could not seek to start "
+ "position of resource collection block."));
+ }
+
+ content.d->m_collectionManager.read(file, dataBlockStart);
+ content.d->m_binaryFormatEngineHandler.setResourceCollectionManager(content.d->m_collectionManager);
+
+ if (!QInstaller::isVerbose())
+ return;
+
+ const QList<ResourceCollection> collections = content.d->m_collectionManager.collections();
+ qDebug() << "Number of resource collections loaded:" << collections.count();
+ foreach (const ResourceCollection &collection, collections) {
+ const QList<QSharedPointer<Resource> > resources = collection.resources();
+ qDebug() << collection.name().data() << "loaded...";
+ QStringList resourcesWithSize;
+ foreach (const QSharedPointer<Resource> &resource, resources) {
+ resourcesWithSize.append(QString::fromLatin1("%1 - %2")
+ .arg(QString::fromUtf8(resource->name()), humanReadableSize(resource->size())));
+ }
+ if (!resourcesWithSize.isEmpty()) {
+ qDebug() << " - " << resources.count() << "resources: "
+ << qPrintable(resourcesWithSize.join(QLatin1String("; ")));
}
}
}
diff --git a/src/libs/installer/binaryformat.cpp b/src/libs/installer/binaryformat.cpp
index fca99094d..72abfe713 100644
--- a/src/libs/installer/binaryformat.cpp
+++ b/src/libs/installer/binaryformat.cpp
@@ -45,43 +45,93 @@
#include "fileio.h"
#include <QFileInfo>
+#include <QFlags>
+#include <QUuid>
-namespace QInstallerCreator {
+namespace QInstaller {
/*!
- \class Archive
- \brief The Archive class provides an interface for reading from an underlying device.
+ \class Resource
+ \brief The Resource class provides an interface for reading from an underlying device.
- Archive is an interface for reading inside a binary file, but is not supposed to write to
- the binary it wraps. The Archive class is created by either passing a path to an already
- zipped archive or by passing an identifier and segment inside an already existing binary,
- passed as device.
+ Resource is an interface for reading inside a device, but is not supposed to write to the
+ the device it wraps. The resource class is created by either passing a path to an already
+ existing binary (e.g. a zipped archive, a Qt Resource file etc.) or by passing an name and
+ segment inside an already existing QIODevice, passed as device.
- The archive name can be set at any time using setName(). The segment passed inside the
- constructor represents the offset and size of the archive inside the binary file.
+ The resource name can be set at any time using setName(). The segment passed inside the
+ constructor represents the offset and size of the resource inside the device.
*/
/*!
- Creates an archive providing the data in \a path.
+ Creates a resource providing the data in \a path.
+
+ \sa open()
*/
-Archive::Archive(const QString &path)
+Resource::Resource(const QString &path)
: m_device(0)
, m_name(QFileInfo(path).fileName().toUtf8())
+ , m_deviceOpened(false)
+{
+ m_inputFile.setFileName(path);
+ m_segment = Range<qint64>::fromStartAndLength(0, m_inputFile.size());
+}
+
+/*!
+ Creates a resource identified by \a name providing the data in \a path.
+
+ \sa open()
+*/
+Resource::Resource(const QByteArray &name, const QString &path)
+ : m_device(0)
+ , m_name(name)
+ , m_deviceOpened(false)
{
m_inputFile.setFileName(path);
+ m_segment = Range<qint64>::fromStartAndLength(0, m_inputFile.size());
+}
+
+/*!
+ Creates a resource providing the data in a \a device.
+
+ \sa open()
+*/
+Resource::Resource(const QSharedPointer<QIODevice> &device)
+ : m_device(device)
+ , m_segment(Range<qint64>::fromStartAndLength(0, device->size()))
+ , m_name(QUuid::createUuid().toByteArray())
+ , m_deviceOpened(false)
+{
}
/*!
- Creates an archive identified by \a identifier providing a data \a segment within a \a device.
+ Creates a resource providing a data \a segment within a \a device.
+
+ \sa open()
+*/
+Resource::Resource(const QSharedPointer<QIODevice> &device, const Range<qint64> &segment)
+ : m_device(device)
+ , m_segment(segment)
+ , m_name(QUuid::createUuid().toByteArray())
+ , m_deviceOpened(false)
+{
+}
+
+/*!
+ Creates a resource identified by \a name providing a data \a segment within a \a device.
+
+ \sa open()
*/
-Archive::Archive(const QByteArray &identifier, const QSharedPointer<QFile> &device, const Range<qint64> &segment)
+Resource::Resource(const QByteArray &name, const QSharedPointer<QIODevice> &device,
+ const Range<qint64> &segment)
: m_device(device)
, m_segment(segment)
- , m_name(identifier)
+ , m_name(name)
+ , m_deviceOpened(false)
{
}
-Archive::~Archive()
+Resource::~Resource()
{
if (isOpen())
close();
@@ -90,72 +140,80 @@ Archive::~Archive()
/*!
\reimp
*/
-bool Archive::seek(qint64 pos)
+bool Resource::seek(qint64 pos)
{
if (m_inputFile.isOpen())
return m_inputFile.seek(pos) && QIODevice::seek(pos);
return QIODevice::seek(pos);
}
-QByteArray Archive::name() const
+QByteArray Resource::name() const
{
return m_name;
}
-void Archive::setName(const QByteArray &name)
+void Resource::setName(const QByteArray &name)
{
m_name = name;
}
/*!
- \reimpl
- */
-void Archive::close()
-{
- m_inputFile.close();
- QIODevice::close();
-}
-
-/*!
- \reimp
- */
-bool Archive::open(OpenMode mode)
+ A Resource will always be opened in QIODevice::ReadOnly mode. The function will return true
+ if successful.
+*/
+bool Resource::open()
{
if (isOpen())
return false;
- const bool writeOnly = (mode & QIODevice::WriteOnly) != QIODevice::NotOpen;
- const bool append = (mode & QIODevice::Append) != QIODevice::NotOpen;
-
- // no write support
- if (writeOnly || append)
- return false;
+ if (m_device.isNull()) {
+ if (!m_inputFile.open(QIODevice::ReadOnly)) {
+ setErrorString(m_inputFile.errorString());
+ return false;
+ }
+ return open(QIODevice::ReadOnly);
+ }
- if (m_device != 0)
- return QIODevice::open(mode);
+ if (m_device->isOpen()) {
+ if (!QFlags<QIODevice::OpenModeFlag>(m_device->openMode()).testFlag(QIODevice::ReadOnly)) {
+ setErrorString(tr("Could not open the underlying device. Already opened write only."));
+ return false;
+ }
+ return open(QIODevice::ReadOnly);
+ }
- if (!m_inputFile.open(mode)) {
- setErrorString(m_inputFile.errorString());
+ m_deviceOpened = m_device->open(QIODevice::ReadOnly);
+ if (!m_deviceOpened) {
+ setErrorString(m_device->errorString());
return false;
}
- setOpenMode(mode);
- return true;
+ return open(QIODevice::ReadOnly);
+}
+/*!
+ \reimp
+ */
+void Resource::close()
+{
+ m_inputFile.close();
+ if (!m_device.isNull() && m_deviceOpened) {
+ m_device->close();
+ m_deviceOpened = false;
+ }
+ QIODevice::close();
}
/*!
\reimp
*/
-qint64 Archive::size() const
+qint64 Resource::size() const
{
- if (m_device != 0)
- return m_segment.length();
- return m_inputFile.size();
+ return m_segment.length();
}
/*!
\reimp
*/
-qint64 Archive::readData(char* data, qint64 maxSize)
+qint64 Resource::readData(char* data, qint64 maxSize)
{
if (m_device == 0)
return m_inputFile.read(data, maxSize);
@@ -170,7 +228,7 @@ qint64 Archive::readData(char* data, qint64 maxSize)
/*!
\reimp
*/
-qint64 Archive::writeData(const char* data, qint64 maxSize)
+qint64 Resource::writeData(const char* data, qint64 maxSize)
{
Q_UNUSED(data);
Q_UNUSED(maxSize);
@@ -178,84 +236,79 @@ qint64 Archive::writeData(const char* data, qint64 maxSize)
return -1;
}
-void Archive::copyData(Archive *archive, QFileDevice *out)
+void Resource::copyData(Resource *resource, QFileDevice *out)
{
- qint64 left = archive->size();
+ qint64 left = resource->size();
char data[4096];
while (left > 0) {
const qint64 len = qMin<qint64>(left, 4096);
- const qint64 bytesRead = archive->read(data, len);
+ const qint64 bytesRead = resource->read(data, len);
if (bytesRead != len) {
- throw QInstaller::Error(tr("Read failed after % 1 bytes: % 2")
- .arg(QString::number(archive->size() - left), archive->errorString()));
+ throw QInstaller::Error(tr("Read failed after %1 bytes: %2")
+ .arg(QString::number(resource->size() - left), resource->errorString()));
}
const qint64 bytesWritten = out->write(data, len);
if (bytesWritten != len) {
- throw QInstaller::Error(tr("Write failed after % 1 bytes: % 2")
- .arg(QString::number(archive->size() - left), out->errorString()));
+ throw QInstaller::Error(tr("Write failed after %1 bytes: %2")
+ .arg(QString::number(resource->size() - left), out->errorString()));
}
left -= len;
}
}
-// -- Component
+/*!
+ \class ResourceCollection
+ \brief A Resource Collection is an abstraction that groups together a number of resources.
-QByteArray Component::name() const
-{
- return m_name;
-}
+ The resources are supposed to be sequential, so the collection keeps them ordered once a new
+ resource is added.
+
+ The resources collection can be written to and read from a QFileDevice. The resource
+ collection name can be set at any time using setName().
+*/
-void Component::setName(const QByteArray &ba)
+ResourceCollection::ResourceCollection(const QByteArray &name)
+ : m_name(name)
{
- m_name = ba;
}
-Component Component::readFromIndexEntry(const QSharedPointer<QFile> &in, qint64 offset)
+QByteArray ResourceCollection::name() const
{
- Component c;
- c.m_name = QInstaller::retrieveByteArray(in.data());
- c.m_binarySegment = QInstaller::retrieveInt64Range(in.data()).moved(offset);
-
- c.readData(in, offset);
-
- return c;
+ return m_name;
}
-void Component::writeIndexEntry(QFileDevice *out, qint64 positionOffset) const
+void ResourceCollection::setName(const QByteArray &ba)
{
- QInstaller::appendByteArray(out, m_name);
- m_binarySegment.moved(positionOffset);
- QInstaller::appendInt64(out, m_binarySegment.start());
- QInstaller::appendInt64(out, m_binarySegment.length());
+ m_name = ba;
}
-void Component::writeData(QFileDevice *out, qint64 offset) const
+void ResourceCollection::write(QFileDevice *out, qint64 offset) const
{
const qint64 dataBegin = out->pos();
- QInstaller::appendInt64(out, m_archives.count());
+ QInstaller::appendInt64(out, m_resources.count());
qint64 start = out->pos() + offset;
// Why 16 + 16? This is 24, not 32???
const int foo = 3 * sizeof(qint64);
- // add 16 + 16 + number of name characters for each archive (the size of the table)
- foreach (const QSharedPointer<Archive> &archive, m_archives)
- start += foo + archive->name().count();
+ // add 16 + 16 + number of name characters for each resource (the size of the table)
+ foreach (const QSharedPointer<Resource> &resource, m_resources)
+ start += foo + resource->name().count();
QList<qint64> starts;
- foreach (const QSharedPointer<Archive> &archive, m_archives) {
- QInstaller::appendByteArray(out, archive->name());
+ foreach (const QSharedPointer<Resource> &resource, m_resources) {
+ QInstaller::appendByteArray(out, resource->name());
starts.push_back(start);
- QInstaller::appendInt64Range(out, Range<qint64>::fromStartAndLength(start, archive->size()));
- start += archive->size();
+ QInstaller::appendInt64Range(out, Range<qint64>::fromStartAndLength(start, resource->size()));
+ start += resource->size();
}
- foreach (const QSharedPointer<Archive> &archive, m_archives) {
- if (!archive->open(QIODevice::ReadOnly)) {
- throw QInstaller::Error(tr("Could not open archive %1: %2")
- .arg(QString::fromUtf8(archive->name()), archive->errorString()));
+ foreach (const QSharedPointer<Resource> &resource, m_resources) {
+ if (!resource->open()) {
+ throw QInstaller::Error(tr("Could not open resource %1: %2")
+ .arg(QString::fromUtf8(resource->name()), resource->errorString()));
}
const qint64 expectedStart = starts.takeFirst();
@@ -263,129 +316,157 @@ void Component::writeData(QFileDevice *out, qint64 offset) const
Q_UNUSED(expectedStart);
Q_UNUSED(actualStart);
Q_ASSERT(expectedStart == actualStart);
- archive->copyData(out);
+ resource->copyData(out);
}
- m_binarySegment = Range<qint64>::fromStartAndEnd(dataBegin, out->pos()).moved(offset);
+ m_segment = Range<qint64>::fromStartAndEnd(dataBegin, out->pos()).moved(offset);
}
-void Component::readData(const QSharedPointer<QFile> &in, qint64 offset)
+void ResourceCollection::read(const QSharedPointer<QFile> &in, qint64 offset)
{
const qint64 pos = in->pos();
- in->seek(m_binarySegment.start());
+ in->seek(m_segment.start());
const qint64 count = QInstaller::retrieveInt64(in.data());
- QVector<QByteArray> names;
- QVector<Range<qint64> > ranges;
+ QList<QByteArray> names;
+ QList<Range<qint64> > ranges;
for (int i = 0; i < count; ++i) {
names.push_back(QInstaller::retrieveByteArray(in.data()));
ranges.push_back(QInstaller::retrieveInt64Range(in.data()).moved(offset));
}
for (int i = 0; i < ranges.count(); ++i)
- m_archives.append(QSharedPointer<Archive>(new Archive(names.at(i), in, ranges.at(i))));
+ m_resources.append(QSharedPointer<Resource>(new Resource(names.at(i), in, ranges.at(i))));
in->seek(pos);
}
-bool Component::operator<(const Component& other) const
+bool ResourceCollection::operator<(const ResourceCollection& other) const
{
if (m_name != other.name())
return m_name < other.m_name;
- return m_binarySegment < other.m_binarySegment;
+ return m_segment < other.m_segment;
}
-bool Component::operator==(const Component& other) const
+bool ResourceCollection::operator==(const ResourceCollection& other) const
{
- return m_name == other.m_name && m_binarySegment == other.m_binarySegment;
+ return m_name == other.m_name && m_segment == other.m_segment;
}
/*!
- Appends \a archive to this component. The component takes ownership of \a archive.
+ Appends \a resource to this collection. The collection takes ownership of \a resource.
*/
-void Component::appendArchive(const QSharedPointer<Archive>& archive)
+void ResourceCollection::appendResource(const QSharedPointer<Resource>& resource)
+{
+ Q_ASSERT(resource);
+ resource->setParent(0);
+ m_resources.push_back(resource);
+}
+
+void ResourceCollection::appendResources(const QList<QSharedPointer<Resource> > &resources)
{
- Q_ASSERT(archive);
- archive->setParent(0);
- m_archives.push_back(archive);
+ foreach (const QSharedPointer<Resource> &resource, resources)
+ appendResource(resource);
}
/*!
- Returns the archives associated with this component.
+ Returns the resources associated with this component.
*/
-QVector<QSharedPointer<Archive> > Component::archives() const
+QList<QSharedPointer<Resource> > ResourceCollection::resources() const
{
- return m_archives;
+ return m_resources;
}
-QSharedPointer<Archive> Component::archiveByName(const QByteArray &name) const
+QSharedPointer<Resource> ResourceCollection::resourceByName(const QByteArray &name) const
{
- foreach (const QSharedPointer<Archive>& i, m_archives) {
+ foreach (const QSharedPointer<Resource>& i, m_resources) {
if (i->name() == name)
return i;
}
- return QSharedPointer<Archive>();
+ return QSharedPointer<Resource>();
}
-// -- ComponentIndex
+/*!
+ \class ResourceCollectionManager
+ \brief A Resource Collection Manager is an abstraction that groups together a number of
+ resource collections.
-ComponentIndex::ComponentIndex()
-{
-}
+ The resources collections can be written to and read from a QFileDevice.
+*/
-ComponentIndex ComponentIndex::read(const QSharedPointer<QFile> &dev, qint64 offset)
+void ResourceCollectionManager::read(const QSharedPointer<QFile> &dev, qint64 offset)
{
- ComponentIndex result;
const qint64 size = QInstaller::retrieveInt64(dev.data());
for (int i = 0; i < size; ++i)
- result.insertComponent(Component::readFromIndexEntry(dev, offset));
+ insertCollection(readIndexEntry(dev, offset));
QInstaller::retrieveInt64(dev.data());
- return result;
}
-void ComponentIndex::writeIndex(QFileDevice *out, qint64 offset) const
+Range<qint64> ResourceCollectionManager::write(QFileDevice *out, qint64 offset) const
{
+ QInstaller::appendInt64(out, collectionCount());
+ foreach (const ResourceCollection &collection, m_collections)
+ collection.write(out, offset);
+
+ const qint64 start = out->pos();
+
// Q: why do we write the size twice?
// A: for us to be able to read it beginning from the end of the file as well
- QInstaller::appendInt64(out, componentCount());
- foreach (const Component& i, components())
- i.writeIndexEntry(out, offset);
- QInstaller::appendInt64(out, componentCount());
+ QInstaller::appendInt64(out, collectionCount());
+ foreach (const ResourceCollection &collection, m_collections)
+ writeIndexEntry(collection, out);
+ QInstaller::appendInt64(out, collectionCount());
+
+ return Range<qint64>::fromStartAndEnd(start, out->pos());
}
-void ComponentIndex::writeComponentData(QFileDevice *out, qint64 offset) const
+ResourceCollection ResourceCollectionManager::collectionByName(const QByteArray &name) const
{
- QInstaller::appendInt64(out, componentCount());
+ return m_collections.value(name);
+}
- foreach (const Component &component, m_components)
- component.writeData(out, offset);
+void ResourceCollectionManager::insertCollection(const ResourceCollection& collection)
+{
+ m_collections.insert(collection.name(), collection);
}
-Component ComponentIndex::componentByName(const QByteArray &id) const
+void ResourceCollectionManager::removeCollection(const QByteArray &name)
{
- return m_components.value(id);
+ m_collections.remove(name);
}
-void ComponentIndex::insertComponent(const Component& c)
+QList<ResourceCollection> ResourceCollectionManager::collections() const
{
- m_components.insert(c.name(), c);
+ return m_collections.values();
}
-void ComponentIndex::removeComponent(const QByteArray &name)
+void ResourceCollectionManager::reset()
{
- m_components.remove(name);
+ m_collections.clear();
}
-QVector<Component> ComponentIndex::components() const
+int ResourceCollectionManager::collectionCount() const
{
- return m_components.values().toVector();
+ return m_collections.size();
}
-int ComponentIndex::componentCount() const
+void ResourceCollectionManager::writeIndexEntry(const ResourceCollection &collection,
+ QFileDevice *dev) const
{
- return m_components.size();
+ QInstaller::appendByteArray(dev, collection.name());
+ QInstaller::appendInt64Range(dev, collection.segment());
+}
+
+ResourceCollection ResourceCollectionManager::readIndexEntry(const QSharedPointer<QFile> &in,
+ qint64 offset)
+{
+ ResourceCollection c(QInstaller::retrieveByteArray(in.data()));
+ c.setSegment(QInstaller::retrieveInt64Range(in.data()).moved(offset));
+ c.read(in, offset);
+
+ return c;
}
-} // namespace QInstallerCreator
+} // namespace QInstaller
diff --git a/src/libs/installer/binaryformat.h b/src/libs/installer/binaryformat.h
index 565442248..1097b561f 100644
--- a/src/libs/installer/binaryformat.h
+++ b/src/libs/installer/binaryformat.h
@@ -46,18 +46,26 @@
#include "qinstallerglobal.h"
#include <QFile>
-#include <QVector>
+#include <QList>
-namespace QInstallerCreator {
+namespace QInstaller {
-class INSTALLER_EXPORT Archive : public QIODevice
+class INSTALLER_EXPORT Resource : public QIODevice
{
+ Q_OBJECT
+ Q_DISABLE_COPY(Resource)
+
public:
- explicit Archive(const QString &path);
- Archive(const QByteArray &name, const QSharedPointer<QFile> &device, const Range<qint64> &segment);
- ~Archive();
+ 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();
- bool open(OpenMode mode);
+ bool open();
void close();
bool seek(qint64 pos);
@@ -66,67 +74,81 @@ public:
QByteArray name() const;
void setName(const QByteArray &name);
+ Range<qint64> segment() const { return m_segment; }
+
void copyData(QFileDevice *out) { copyData(this, out); }
- static void copyData(Archive *archive, QFileDevice *out);
+ static void copyData(Resource *archive, QFileDevice *out);
private:
qint64 readData(char *data, qint64 maxSize);
qint64 writeData(const char *data, qint64 maxSize);
+ bool open(OpenMode mode) { return QIODevice::open(mode); }
private:
- QSharedPointer<QFile> m_device;
- const Range<qint64> m_segment;
+ QSharedPointer<QIODevice> m_device;
+ Range<qint64> m_segment;
QFile m_inputFile;
QByteArray m_name;
+ bool m_deviceOpened;
};
-class INSTALLER_EXPORT Component
+
+class INSTALLER_EXPORT ResourceCollection
{
- Q_DECLARE_TR_FUNCTIONS(Component)
+ Q_DECLARE_TR_FUNCTIONS(ResourceCollection)
public:
- static Component readFromIndexEntry(const QSharedPointer<QFile> &dev, qint64 offset);
-
- void writeIndexEntry(QFileDevice *dev, qint64 offset) const;
-
- void writeData(QFileDevice *dev, qint64 positionOffset) const;
- void readData(const QSharedPointer<QFile> &dev, qint64 offset);
+ ResourceCollection() {}
+ explicit ResourceCollection(const QByteArray &name);
QByteArray name() const;
void setName(const QByteArray &ba);
- void appendArchive(const QSharedPointer<Archive> &archive);
- QSharedPointer<Archive> archiveByName(const QByteArray &name) const;
- QVector< QSharedPointer<Archive> > archives() const;
+ 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);
- bool operator<(const Component &other) const;
- bool operator==(const Component &other) const;
+ 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);
+
+ bool operator<(const ResourceCollection &other) const;
+ bool operator==(const ResourceCollection &other) const;
private:
QByteArray m_name;
- QVector<QSharedPointer<Archive> > m_archives;
- mutable Range<qint64> m_binarySegment;
- QString m_dataDirectory;
+ mutable Range<qint64> m_segment;
+ QList<QSharedPointer<Resource> > m_resources;
};
-class INSTALLER_EXPORT ComponentIndex
+class INSTALLER_EXPORT ResourceCollectionManager
{
public:
- ComponentIndex();
- static ComponentIndex read(const QSharedPointer<QFile> &dev, qint64 offset);
- void writeIndex(QFileDevice *dev, qint64 offset) const;
- void writeComponentData(QFileDevice *dev, qint64 offset) const;
- Component componentByName(const QByteArray &name) const;
- void insertComponent(const Component &name);
- void removeComponent(const QByteArray &name);
- QVector<Component> components() const;
- int componentCount() const;
+ Range<qint64> write(QFileDevice *dev, qint64 offset) const;
+ void read(const QSharedPointer<QFile> &dev, qint64 offset);
+
+ void reset();
+ int collectionCount() const;
+
+ QList<ResourceCollection> collections() const;
+ ResourceCollection collectionByName(const QByteArray &name) const;
+
+ void removeCollection(const QByteArray &name);
+ 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, Component> m_components;
+ QHash<QByteArray, ResourceCollection> m_collections;
};
-} // namespace QInstallerCreator
+} // namespace QInstaller
#endif // BINARYFORMAT_H
diff --git a/src/libs/installer/binaryformatengine.cpp b/src/libs/installer/binaryformatengine.cpp
index 416e8ca56..d4ec1d89c 100644
--- a/src/libs/installer/binaryformatengine.cpp
+++ b/src/libs/installer/binaryformatengine.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Installer Framework.
@@ -41,8 +41,6 @@
#include "binaryformatengine.h"
-using namespace QInstallerCreator;
-
namespace {
class StringListIterator : public QAbstractFileEngineIterator
@@ -80,11 +78,14 @@ private:
} // anon namespace
-BinaryFormatEngine::BinaryFormatEngine(const ComponentIndex &index, const QString &fileName)
- : m_index(index)
- , m_hasComponent(false)
- , m_hasArchive(false)
- , m_archive(0)
+namespace QInstaller {
+
+BinaryFormatEngine::BinaryFormatEngine(const ResourceCollectionManager &manager,
+ const QString &fileName)
+ : m_manager(manager)
+ , m_hasCollection(false)
+ , m_hasResource(false)
+ , m_resource(0)
{
setArchive(fileName);
}
@@ -107,14 +108,14 @@ void BinaryFormatEngine::setArchive(const QString &file)
path.chop(1);
QString arch;
- const QString comp = path.section(sep, 0, 0);
- m_hasComponent = !comp.isEmpty();
- m_hasArchive = path.contains(sep);
- if (m_hasArchive)
+ const QString coll = path.section(sep, 0, 0);
+ m_hasCollection = !coll.isEmpty();
+ m_hasResource = path.contains(sep);
+ if (m_hasResource)
arch = path.section(sep, 1, 1);
- m_component = m_index.componentByName(comp.toUtf8());
- m_archive = m_component.archiveByName(arch.toUtf8());
+ m_collection = m_manager.collectionByName(coll.toUtf8());
+ m_resource = m_collection.resourceByName(arch.toUtf8());
}
/**
@@ -130,20 +131,20 @@ void BinaryFormatEngine::setFileName(const QString &file)
*/
bool BinaryFormatEngine::close()
{
- if (m_archive == 0)
+ if (m_resource == 0)
return false;
- const bool result = m_archive->isOpen();
- m_archive->close();
+ const bool result = m_resource->isOpen();
+ m_resource->close();
return result;
}
/**
* \reimp
*/
-bool BinaryFormatEngine::open(QIODevice::OpenMode mode)
+bool BinaryFormatEngine::open(QIODevice::OpenMode /*mode*/)
{
- return m_archive == 0 ? false : m_archive->open(mode);
+ return m_resource == 0 ? false : m_resource->open();
}
/**
@@ -151,7 +152,7 @@ bool BinaryFormatEngine::open(QIODevice::OpenMode mode)
*/
qint64 BinaryFormatEngine::pos() const
{
- return m_archive == 0 ? 0 : m_archive->pos();
+ return m_resource == 0 ? 0 : m_resource->pos();
}
/**
@@ -159,7 +160,7 @@ qint64 BinaryFormatEngine::pos() const
*/
qint64 BinaryFormatEngine::read(char *data, qint64 maxlen)
{
- return m_archive == 0 ? -1 : m_archive->read(data, maxlen);
+ return m_resource == 0 ? -1 : m_resource->read(data, maxlen);
}
/**
@@ -167,7 +168,7 @@ qint64 BinaryFormatEngine::read(char *data, qint64 maxlen)
*/
bool BinaryFormatEngine::seek(qint64 offset)
{
- return m_archive == 0 ? false : m_archive->seek(offset);
+ return m_resource == 0 ? false : m_resource->seek(offset);
}
/**
@@ -233,13 +234,13 @@ bool BinaryFormatEngine::copy(const QString &newName)
QAbstractFileEngine::FileFlags BinaryFormatEngine::fileFlags(FileFlags type) const
{
FileFlags result;
- if ((type & FileType) && m_archive != 0)
+ if ((type & FileType) && m_resource != 0)
result |= FileType;
- if ((type & DirectoryType) && !m_hasArchive)
+ if ((type & DirectoryType) && !m_hasResource)
result |= DirectoryType;
- if ((type & ExistsFlag) && m_hasArchive && m_archive != 0)
+ if ((type & ExistsFlag) && m_hasResource && m_resource != 0)
result |= ExistsFlag;
- if ((type & ExistsFlag) && !m_hasArchive && !m_component.name().isEmpty())
+ if ((type & ExistsFlag) && !m_hasResource && !m_collection.name().isEmpty())
result |= ExistsFlag;
return result;
@@ -259,20 +260,17 @@ QAbstractFileEngineIterator *BinaryFormatEngine::beginEntryList(QDir::Filters fi
*/
QStringList BinaryFormatEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const
{
- if (m_hasArchive)
+ if (m_hasResource)
return QStringList();
-
- QStringList result;
- if (m_hasComponent && (filters & QDir::Files)) {
- const QVector< QSharedPointer<Archive> > archives = m_component.archives();
- foreach (const QSharedPointer<Archive> &i, archives)
- result.push_back(QString::fromUtf8(i->name()));
+ QStringList result;
+ if (m_hasCollection && (filters & QDir::Files)) {
+ foreach (const QSharedPointer<Resource> &resource, m_collection.resources())
+ result.push_back(QString::fromUtf8(resource->name()));
}
- else if (!m_hasComponent && (filters & QDir::Dirs)) {
- const QVector<Component> components = m_index.components();
- foreach (const Component &i, components)
- result.push_back(QString::fromUtf8(i.name()));
+ else if (!m_hasCollection && (filters & QDir::Dirs)) {
+ foreach (const ResourceCollection &collection, m_manager.collections())
+ result.push_back(QString::fromUtf8(collection.name()));
}
if (filterNames.isEmpty())
@@ -296,11 +294,13 @@ QStringList BinaryFormatEngine::entryList(QDir::Filters filters, const QStringLi
return entries;
}
-
+
/**
* \reimp
*/
qint64 BinaryFormatEngine::size() const
{
- return m_archive == 0 ? 0 : m_archive->size();
+ return m_resource == 0 ? 0 : m_resource->size();
}
+
+} // namespace QInstaller
diff --git a/src/libs/installer/binaryformatengine.h b/src/libs/installer/binaryformatengine.h
index b178402b9..be82b3afb 100644
--- a/src/libs/installer/binaryformatengine.h
+++ b/src/libs/installer/binaryformatengine.h
@@ -46,12 +46,14 @@
#include <QtCore/private/qfsfileengine_p.h>
-namespace QInstallerCreator {
+namespace QInstaller {
class BinaryFormatEngine : public QAbstractFileEngine
{
+ Q_DISABLE_COPY(BinaryFormatEngine)
+
public:
- BinaryFormatEngine(const ComponentIndex &index, const QString &fileName);
+ BinaryFormatEngine(const ResourceCollectionManager &manager, const QString &fileName);
~BinaryFormatEngine();
void setFileName(const QString &file);
@@ -74,14 +76,14 @@ protected:
void setArchive(const QString &file);
private:
- const ComponentIndex m_index;
- bool m_hasComponent;
- bool m_hasArchive;
- Component m_component;
- QSharedPointer<Archive> m_archive;
+ const ResourceCollectionManager m_manager;
+ bool m_hasCollection;
+ bool m_hasResource;
+ ResourceCollection m_collection;
+ QSharedPointer<Resource> m_resource;
QString m_fileNamePath;
};
-} // namespace QInstallerCreator
+} // namespace QInstaller
-#endif
+#endif // BINARYFORMATENGINE_H
diff --git a/src/libs/installer/binaryformatenginehandler.cpp b/src/libs/installer/binaryformatenginehandler.cpp
index 247297e13..9e5f75c97 100644
--- a/src/libs/installer/binaryformatenginehandler.cpp
+++ b/src/libs/installer/binaryformatenginehandler.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Installer Framework.
@@ -46,31 +46,31 @@
#include <QDebug>
#include <QFile>
-using namespace QInstallerCreator;
+namespace QInstaller {
static BinaryFormatEngineHandler *s_instance = 0;
-
+
class BinaryFormatEngineHandler::Private
{
public:
- Private(const ComponentIndex &i)
- : index(i)
+ Private(const ResourceCollectionManager &i)
+ : manager(i)
{
}
- ComponentIndex index;
+ ResourceCollectionManager manager;
};
-BinaryFormatEngineHandler::BinaryFormatEngineHandler(const ComponentIndex &index)
- : d(new Private(index))
+BinaryFormatEngineHandler::BinaryFormatEngineHandler(const ResourceCollectionManager &manager)
+ : d(new Private(manager))
{
s_instance = this;
}
BinaryFormatEngineHandler::BinaryFormatEngineHandler(const BinaryFormatEngineHandler &other)
: QAbstractFileEngineHandler()
- , d(new Private(other.d->index))
+ , d(new Private(other.d->manager))
{
s_instance = this;
}
@@ -82,48 +82,50 @@ BinaryFormatEngineHandler::~BinaryFormatEngineHandler()
delete d;
}
-void BinaryFormatEngineHandler::setComponentIndex(const ComponentIndex &index)
+void BinaryFormatEngineHandler::setResourceCollectionManager(const ResourceCollectionManager &manager)
{
- d->index = index;
+ d->manager = manager;
}
QAbstractFileEngine *BinaryFormatEngineHandler::create(const QString &fileName) const
{
- return fileName.startsWith(QLatin1String("installer://"), Qt::CaseInsensitive ) ? new BinaryFormatEngine(d->index, fileName) : 0;
+ return fileName.startsWith(QLatin1String("installer://"), Qt::CaseInsensitive )
+ ? new BinaryFormatEngine(d->manager, fileName) : 0;
}
-
+
+void BinaryFormatEngineHandler::reset()
+{
+ d->manager.reset();
+}
+
BinaryFormatEngineHandler *BinaryFormatEngineHandler::instance()
{
return s_instance;
}
-
-void BinaryFormatEngineHandler::registerArchive(const QString &pathName, const QString &archive)
+
+void
+BinaryFormatEngineHandler::registerResource(const QString &fileName, const QString &resourcePath)
{
static const QChar sep = QChar::fromLatin1('/');
static const QString prefix = QString::fromLatin1("installer://");
- Q_ASSERT(pathName.toLower().startsWith(prefix));
+ Q_ASSERT(fileName.toLower().startsWith(prefix));
// cut the prefix
- QString path = pathName.mid(prefix.length());
+ QString path = fileName.mid(prefix.length());
while (path.endsWith(sep))
path.chop(1);
- const QString comp = path.section(sep, 0, 0);
- const QString archiveName = path.section(sep, 1, 1);
-
- Component c = d->index.componentByName(comp.toUtf8());
+ const QString coll = path.section(sep, 0, 0);
+ const QString resourceName = path.section(sep, 1, 1);
+
+ ResourceCollection c = d->manager.collectionByName(coll.toUtf8());
if (c.name().isEmpty())
- c.setName(comp.toUtf8());
+ c.setName(coll.toUtf8());
- QSharedPointer<Archive> newArchive(new Archive(archive));
- newArchive->setName(archiveName.toUtf8());
- c.appendArchive(newArchive);
- d->index.insertComponent(c);
+ QSharedPointer<Resource> resource(new Resource(resourcePath));
+ resource->setName(resourceName.toUtf8());
+ c.appendResource(resource);
+ d->manager.insertCollection(c);
}
-void BinaryFormatEngineHandler::resetRegisteredArchives()
-{
- QVector<QInstallerCreator::Component> registeredComponents = d->index.components();
- foreach (const QInstallerCreator::Component &component, registeredComponents)
- d->index.removeComponent(component.name());
-}
+} // namespace QInstaller
diff --git a/src/libs/installer/binaryformatenginehandler.h b/src/libs/installer/binaryformatenginehandler.h
index 155d9a588..2a26aa5ba 100644
--- a/src/libs/installer/binaryformatenginehandler.h
+++ b/src/libs/installer/binaryformatenginehandler.h
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Installer Framework.
@@ -46,30 +46,30 @@
#include <QtCore/private/qabstractfileengine_p.h>
-namespace QInstallerCreator {
+namespace QInstaller {
-class ComponentIndex;
+class ResourceCollectionManager;
class INSTALLER_EXPORT BinaryFormatEngineHandler : public QAbstractFileEngineHandler
{
public:
- explicit BinaryFormatEngineHandler(const ComponentIndex &index);
+ explicit BinaryFormatEngineHandler(const ResourceCollectionManager &manager);
BinaryFormatEngineHandler(const BinaryFormatEngineHandler &other);
~BinaryFormatEngineHandler();
QAbstractFileEngine *create(const QString &fileName) const;
- void setComponentIndex(const ComponentIndex &index);
+ void setResourceCollectionManager(const ResourceCollectionManager &manager);
+ void reset();
static BinaryFormatEngineHandler *instance();
- void registerArchive(const QString &fileName, const QString &path);
- void resetRegisteredArchives();
+ void registerResource(const QString &fileName, const QString &resourcePath);
private:
class Private;
Private *const d;
};
-}
+} // namespace QInstaller
-#endif
+#endif // BINARYFORMATENGINEHANDLER_H
diff --git a/src/libs/installer/createlocalrepositoryoperation.cpp b/src/libs/installer/createlocalrepositoryoperation.cpp
index e4c304773..0f8428382 100644
--- a/src/libs/installer/createlocalrepositoryoperation.cpp
+++ b/src/libs/installer/createlocalrepositoryoperation.cpp
@@ -267,8 +267,8 @@ bool CreateLocalRepositoryOperation::performOperation()
const qint64 dataBlockStart = bl.endOfData - bl.dataBlockSize;
file->seek(QInstaller::retrieveInt64(file.data()) + dataBlockStart);
- QInstallerCreator::ComponentIndex componentIndex = QInstallerCreator::ComponentIndex::read(file,
- dataBlockStart);
+ ResourceCollectionManager manager;
+ manager.read(file, dataBlockStart);
QDirIterator it(repoPath, QDirIterator::Subdirectories);
while (it.hasNext() && !it.next().isEmpty()) {
@@ -285,19 +285,17 @@ bool CreateLocalRepositoryOperation::performOperation()
}
// copy the 7z files that are inside the component index into the target
- QInstallerCreator::Component c = componentIndex.componentByName(fileName.toUtf8());
- if (c.archives().count()) {
- QVector<QSharedPointer<QInstallerCreator::Archive> > archives = c.archives();
- foreach (const QSharedPointer<QInstallerCreator::Archive> &a, archives) {
- if (!a->open(QIODevice::ReadOnly))
- continue;
-
- QFile target(absoluteTargetPath + QDir::separator() + QString::fromUtf8(a->name()));
- QInstaller::openForWrite(&target);
- a->copyData(&target);
- helper.m_files.prepend(target.fileName());
- emit outputTextChanged(helper.m_files.first());
- }
+ const ResourceCollection collection = manager.collectionByName(fileName.toUtf8());
+ foreach (const QSharedPointer<Resource> &resource, collection.resources()) {
+ if (!resource->open())
+ continue;
+
+ QFile target(absoluteTargetPath + QDir::separator()
+ + QString::fromUtf8(resource->name()));
+ QInstaller::openForWrite(&target);
+ resource->copyData(&target);
+ helper.m_files.prepend(target.fileName());
+ emit outputTextChanged(helper.m_files.first());
}
}
}
diff --git a/src/libs/installer/downloadarchivesjob.cpp b/src/libs/installer/downloadarchivesjob.cpp
index 332c62f2a..a1612b158 100644
--- a/src/libs/installer/downloadarchivesjob.cpp
+++ b/src/libs/installer/downloadarchivesjob.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Installer Framework.
@@ -240,7 +240,7 @@ void DownloadArchivesJob::registerFile()
}
const QPair<QString, QString> pair = m_archivesToDownload.takeFirst();
- QInstallerCreator::BinaryFormatEngineHandler::instance()->registerArchive(pair.first,
+ BinaryFormatEngineHandler::instance()->registerResource(pair.first,
m_downloader->downloadedFileName());
}
fetchNextArchiveHash();
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index 58f89ef17..0c1e94c34 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -393,8 +393,8 @@ bool PackageManagerCorePrivate::buildComponentTree(QHash<QString, Component*> &c
void PackageManagerCorePrivate::cleanUpComponentEnvironment()
{
// clean up already downloaded data, don't reset registered archives in offline installer case
- if (QInstallerCreator::BinaryFormatEngineHandler::instance() && !m_core->isInstaller())
- QInstallerCreator::BinaryFormatEngineHandler::instance()->resetRegisteredArchives();
+ if (BinaryFormatEngineHandler::instance() && !m_core->isInstaller())
+ BinaryFormatEngineHandler::instance()->reset();
// there could be still some references to already deleted components,
// so we need to remove the current component script engine
diff --git a/tools/binarycreator/binarycreator.cpp b/tools/binarycreator/binarycreator.cpp
index 9263d13d0..c82d48b73 100644
--- a/tools/binarycreator/binarycreator.cpp
+++ b/tools/binarycreator/binarycreator.cpp
@@ -61,18 +61,17 @@
#include <iostream>
using namespace QInstaller;
-using namespace QInstallerCreator;
struct Input {
QString outputPath;
QString installerExePath;
- ComponentIndex componentIndex;
+ ResourceCollectionManager collectionManager;
QString binaryResourcePath;
QStringList binaryResources;
Range<qint64> operationsPos;
QVector<Range<qint64> > resourcePos;
- Range<qint64> componentIndexSegment;
+ Range<qint64> resourceCollectionsSegment;
};
class BundleBackup
@@ -315,18 +314,13 @@ static int assemble(Input input, const QInstaller::Settings &settings)
input.operationsPos = Range<qint64>::fromStartAndEnd(operationsStart, out.pos())
.moved(-dataBlockStart);
- // write out every components data
- input.componentIndex.writeComponentData(&out, -dataBlockStart);
- const qint64 compIndexStart = out.pos() - dataBlockStart;
-
- // write out the component index
- input.componentIndex.writeIndex(&out, -dataBlockStart);
- input.componentIndexSegment = Range<qint64>::fromStartAndEnd(compIndexStart, out.pos()
- - dataBlockStart);
+ // write out every resource collections data and index
+ input.resourceCollectionsSegment = input.collectionManager.write(&out, -dataBlockStart)
+ .moved(-dataBlockStart);
- qDebug("Component index: [%llu:%llu]", input.componentIndexSegment.start(),
- input.componentIndexSegment.end());
- QInstaller::appendInt64Range(&out, input.componentIndexSegment);
+ qDebug("Resource collections segment index: [%llu:%llu]", input.resourceCollectionsSegment
+ .start(), input.resourceCollectionsSegment.end());
+ QInstaller::appendInt64Range(&out, input.resourceCollectionsSegment);
foreach (const Range<qint64> &range, input.resourcePos)
QInstaller::appendInt64Range(&out, range);
QInstaller::appendInt64Range(&out, input.operationsPos);
@@ -765,17 +759,17 @@ int main(int argc, char **argv)
// now put the packages into the components section of the binary
foreach (const QInstallerTools::PackageInfo &info, packages) {
- Component comp;
- comp.setName(info.name.toUtf8());
+ ResourceCollection collection;
+ collection.setName(info.name.toUtf8());
qDebug() << "Creating component info for" << info.name;
- foreach (const QString &archive, info.copiedFiles) {
- const QSharedPointer<Archive> arch(new Archive(archive));
- qDebug() << QString::fromLatin1("Appending %1 (%2)").arg(archive,
- humanReadableSize(arch->size()));
- comp.appendArchive(arch);
+ foreach (const QString &file, info.copiedFiles) {
+ const QSharedPointer<Resource> resource(new Resource(file));
+ qDebug() << QString::fromLatin1("Appending %1 (%2)").arg(file,
+ humanReadableSize(resource->size()));
+ collection.appendResource(resource);
}
- input.componentIndex.insertComponent(comp);
+ input.collectionManager.insertCollection(collection);
}
qDebug() << "Creating the binary";
diff --git a/tools/devtool/binarydump.cpp b/tools/devtool/binarydump.cpp
index 6b871fd47..8c73d7642 100644
--- a/tools/devtool/binarydump.cpp
+++ b/tools/devtool/binarydump.cpp
@@ -50,7 +50,7 @@
#include <iostream>
-int BinaryDump::dump(const QInstallerCreator::ComponentIndex &index, const QString &target)
+int BinaryDump::dump(const QInstaller::ResourceCollectionManager &manager, const QString &target)
{
QDir targetDir(QFileInfo(target).absoluteFilePath());
if (targetDir.exists()) {
@@ -121,20 +121,18 @@ int BinaryDump::dump(const QInstallerCreator::ComponentIndex &index, const QStri
continue;
const QString fileName = it.fileName();
- QInstallerCreator::Component c = index.componentByName(fileName.toUtf8());
- if (c.archives().count() <= 0)
+ const QInstaller::ResourceCollection c = manager.collectionByName(fileName.toUtf8());
+ if (c.resources().count() <= 0)
continue;
- typedef QSharedPointer<QInstallerCreator::Archive> Archive;
- QVector<Archive> archives = c.archives();
- foreach (const Archive &archive, archives) {
- if (!archive->open(QIODevice::ReadOnly))
+ foreach (const QSharedPointer<QInstaller::Resource> &resource, c.resources()) {
+ if (!resource->open())
continue; // TODO: should we throw here?
QFile target(targetDir.filePath(fileName) + QDir::separator()
- + QString::fromUtf8(archive->name()));
+ + QString::fromUtf8(resource->name()));
QInstaller::openForWrite(&target);
- archive->copyData(&target); // copy the 7z files into the target directory
+ resource->copyData(&target); // copy the 7z files into the target directory
}
}
result = EXIT_SUCCESS;
diff --git a/tools/devtool/binarydump.h b/tools/devtool/binarydump.h
index 6211944a5..4504e169c 100644
--- a/tools/devtool/binarydump.h
+++ b/tools/devtool/binarydump.h
@@ -50,7 +50,7 @@ class BinaryDump
public:
BinaryDump() {}
- int dump(const QInstallerCreator::ComponentIndex &index, const QString &target);
+ int dump(const QInstaller::ResourceCollectionManager &manager, const QString &target);
};
#endif // BINARYDUMP_H
diff --git a/tools/devtool/main.cpp b/tools/devtool/main.cpp
index b03bc4ff1..ca11414a4 100644
--- a/tools/devtool/main.cpp
+++ b/tools/devtool/main.cpp
@@ -60,8 +60,6 @@
#include <iostream>
-using namespace QInstallerCreator;
-
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
@@ -165,33 +163,38 @@ int main(int argc, char *argv[])
performedOperations.append(op.take());
}
- // seek to the position of the component index
+ // seek to the position of the resource collections segment info
const qint64 resourceOffsetAndLengtSize = 2 * sizeof(qint64);
const qint64 resourceSectionSize = resourceOffsetAndLengtSize * layout.resourceCount;
- const qint64 offset = layout.endOfData - layout.indexSize - resourceSectionSize
+ qint64 offset = layout.endOfData - layout.indexSize - resourceSectionSize
- resourceOffsetAndLengtSize;
- if (!file->seek(offset))
- throw QInstaller::Error(QLatin1String("Could not seek to read component index info."));
+ if (!file->seek(offset)) {
+ throw QInstaller::Error(QLatin1String("Could not seek to read the resource collection "
+ "segment info."));
+ }
- const qint64 compIndexStart = QInstaller::retrieveInt64(file) + dataBlockStart;
- if (!file->seek(compIndexStart))
- throw QInstaller::Error(QLatin1String("Could not seek to start of component index."));
+ offset = QInstaller::retrieveInt64(file) + dataBlockStart;
+ if (!file->seek(offset)) {
+ throw QInstaller::Error(QLatin1String("Could not seek to start position of resource "
+ "collection block."));
+ }
- // setup the component index
+ // setup the collection manager
QSharedPointer<QFile> data(file);
- ComponentIndex index = ComponentIndex::read(data, dataBlockStart);
+ QInstaller::ResourceCollectionManager manager;
+ manager.read(data, dataBlockStart);
if (parser.isSet(dump)) {
// To dump the content we do not need the binary format engine.
if (layout.magicMarker != QInstaller::BinaryContent::MagicInstallerMarker)
throw QInstaller::Error(QLatin1String("Source file is not an installer."));
BinaryDump bd;
- return bd.dump(index, parser.value(dump));
+ return bd.dump(manager, parser.value(dump));
}
// setup the binary format engine
- QScopedPointer<BinaryFormatEngineHandler> binaryFormatEngineHandler;
- binaryFormatEngineHandler.reset(new BinaryFormatEngineHandler(index));
+ QScopedPointer<QInstaller::BinaryFormatEngineHandler> binaryFormatEngineHandler;
+ binaryFormatEngineHandler.reset(new QInstaller::BinaryFormatEngineHandler(manager));
if (parser.isSet(run)) {
OperationRunner runner(layout.magicMarker, performedOperations);