From 84875396b75f5615afa637f9633d19bbc79e08e0 Mon Sep 17 00:00:00 2001 From: kh1 Date: Tue, 14 Oct 2014 17:03:54 +0200 Subject: 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 Reviewed-by: Kai Koehne --- tools/devtool/binarydump.cpp | 6 +++++- tools/devtool/main.cpp | 17 ++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) (limited to 'tools/devtool') diff --git a/tools/devtool/binarydump.cpp b/tools/devtool/binarydump.cpp index 8c73d7642..7efa13960 100644 --- a/tools/devtool/binarydump.cpp +++ b/tools/devtool/binarydump.cpp @@ -126,13 +126,17 @@ int BinaryDump::dump(const QInstaller::ResourceCollectionManager &manager, const continue; foreach (const QSharedPointer &resource, c.resources()) { - if (!resource->open()) + const bool isOpen = resource->isOpen(); + if ((!isOpen) && (!resource->open())) continue; // TODO: should we throw here? QFile target(targetDir.filePath(fileName) + QDir::separator() + QString::fromUtf8(resource->name())); QInstaller::openForWrite(&target); resource->copyData(&target); // copy the 7z files into the target directory + + if (!isOpen) // If we reach that point, either the resource was opened already... + resource->close(); // or we did open it and have to close it again. } } result = EXIT_SUCCESS; diff --git a/tools/devtool/main.cpp b/tools/devtool/main.cpp index 9ef611ce2..61be6c9f7 100644 --- a/tools/devtool/main.cpp +++ b/tools/devtool/main.cpp @@ -136,24 +136,27 @@ int main(int argc, char *argv[]) } } - QSharedPointer file(new QFile(path)); - QInstaller::openForRead(file.data()); + QFile file(path); + QInstaller::openForRead(&file); qint64 magicMarker; - QInstaller::ResourceCollection meta; QList operations; QInstaller::ResourceCollectionManager manager; - QInstaller::BinaryContent::readBinaryContent(file, &meta, &operations, &manager, - &magicMarker, cookie); + QInstaller::BinaryContent::readBinaryContent(&file, &operations, &manager, &magicMarker, + cookie); // map the inbuilt resources + const QInstaller::ResourceCollection meta = manager.collectionByName("QResources"); foreach (const QSharedPointer &resource, meta.resources()) { - const bool opened = resource->open(); + const bool isOpen = resource->isOpen(); + if ((!isOpen) && (!resource->open())) + continue; // TODO: should we throw here? + const QByteArray ba = resource->readAll(); if (!QResource::registerResource((const uchar*) ba.data(), QLatin1String(":/metadata"))) throw QInstaller::Error(QLatin1String("Could not register in-binary resource.")); resourceMappings.append(ba); - if (opened) + if (!isOpen) resource->close(); } -- cgit v1.2.3