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 /tools | |
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 'tools')
-rw-r--r-- | tools/binarycreator/binarycreator.cpp | 49 | ||||
-rw-r--r-- | tools/devtool/binarydump.cpp | 6 | ||||
-rw-r--r-- | tools/devtool/main.cpp | 17 |
3 files changed, 42 insertions, 30 deletions
diff --git a/tools/binarycreator/binarycreator.cpp b/tools/binarycreator/binarycreator.cpp index 1a14c4bf0..6b40f44d3 100644 --- a/tools/binarycreator/binarycreator.cpp +++ b/tools/binarycreator/binarycreator.cpp @@ -52,10 +52,12 @@ #include <settings.h> #include <utils.h> -#include <QtCore/QDirIterator> -#include <QtCore/QProcess> -#include <QtCore/QSettings> -#include <QtCore/QTemporaryFile> +#include <QDateTime> +#include <QDirIterator> +#include <QDomDocument> +#include <QProcess> +#include <QSettings> +#include <QTemporaryFile> #include <QTemporaryDir> #include <iostream> @@ -66,7 +68,7 @@ struct Input { QString outputPath; QString installerExePath; QInstallerTools::PackageInfoVector packages; - QInstaller::ResourceCollection metaCollection; + QInstaller::ResourceCollectionManager manager; }; class BundleBackup @@ -250,7 +252,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) } #endif - QSharedPointer<QTemporaryFile> out(new QTemporaryFile); + QTemporaryFile out; QString targetName = input.outputPath; #ifdef Q_OS_OSX QDir resourcePath(QFileInfo(input.outputPath).dir()); @@ -270,7 +272,7 @@ static int assemble(Input input, const QInstaller::Settings &settings) } try { - QInstaller::openForWrite(out.data()); + QInstaller::openForWrite(&out); QFile exe(input.installerExePath); #ifdef Q_OS_OSX @@ -280,10 +282,9 @@ static int assemble(Input input, const QInstaller::Settings &settings) } #else QInstaller::openForRead(&exe); - QInstaller::appendData(out.data(), &exe, exe.size()); + QInstaller::appendData(&out, &exe, exe.size()); #endif - QInstaller::ResourceCollectionManager manager; foreach (const QInstallerTools::PackageInfo &info, input.packages) { QInstaller::ResourceCollection collection; collection.setName(info.name.toUtf8()); @@ -295,11 +296,11 @@ static int assemble(Input input, const QInstaller::Settings &settings) humanReadableSize(resource->size())); collection.appendResource(resource); } - manager.insertCollection(collection); + input.manager.insertCollection(collection); } const QList<QInstaller::OperationBlob> operations; - BinaryContent::writeBinaryContent(out, input.metaCollection, operations, manager, + BinaryContent::writeBinaryContent(&out, operations, input.manager, BinaryContent::MagicInstallerMarker, BinaryContent::MagicCookie); } catch (const Error &e) { qCritical("Error occurred while assembling the installer: %s", qPrintable(e.message())); @@ -307,16 +308,16 @@ static int assemble(Input input, const QInstaller::Settings &settings) return EXIT_FAILURE; } - if (!out->rename(targetName)) { + if (!out.rename(targetName)) { qCritical("Could not write installer to %s: %s", targetName.toUtf8().constData(), - out->errorString().toUtf8().constData()); + out.errorString().toUtf8().constData()); QFile::remove(tempFile); return EXIT_FAILURE; } - out->setAutoRemove(false); + out.setAutoRemove(false); #ifndef Q_OS_WIN - chmod755(out->fileName()); + chmod755(out.fileName()); #endif QFile::remove(tempFile); @@ -402,8 +403,8 @@ static QSharedPointer<QInstaller::Resource> createDefaultResourceFile(const QStr throw Error(QString::fromLatin1("Could not compile rcc project file.")); } - return QSharedPointer<QInstaller::Resource>(new QInstaller::Resource(binaryName.toUtf8(), - binaryName)); + return QSharedPointer<QInstaller::Resource>(new QInstaller::Resource(binaryName, binaryName + .toUtf8())); } static @@ -420,8 +421,8 @@ QList<QSharedPointer<QInstaller::Resource> > createBinaryResourceFiles(const QSt if (status != EXIT_SUCCESS) continue; - result.append(QSharedPointer<QInstaller::Resource> (new QInstaller::Resource(binaryName - .toUtf8(), binaryName))); + result.append(QSharedPointer<QInstaller::Resource> (new QInstaller::Resource(binaryName, + binaryName.toUtf8()))); } } return result; @@ -731,9 +732,12 @@ int main(int argc, char **argv) input.packages = packages; input.outputPath = target; input.installerExePath = templateBinary; - input.metaCollection.appendResource(createDefaultResourceFile(tmpMetaDir, + + QInstaller::ResourceCollection metaCollection("QResources"); + metaCollection.appendResource(createDefaultResourceFile(tmpMetaDir, generateTemporaryFileName())); - input.metaCollection.appendResources(createBinaryResourceFiles(resources)); + metaCollection.appendResources(createBinaryResourceFiles(resources)); + input.manager.insertCollection(metaCollection); qDebug() << "Creating the binary"; exitCode = assemble(input, settings); @@ -750,7 +754,8 @@ int main(int argc, char **argv) } qDebug() << "Cleaning up..."; - foreach (const QSharedPointer<QInstaller::Resource> &resource, input.metaCollection.resources()) + const QInstaller::ResourceCollection collection = input.manager.collectionByName("QResources"); + foreach (const QSharedPointer<QInstaller::Resource> &resource, collection.resources()) QFile::remove(QString::fromUtf8(resource->name())); QInstaller::removeDirectory(tmpMetaDir, true); 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<QInstaller::Resource> &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<QFile> file(new QFile(path)); - QInstaller::openForRead(file.data()); + QFile file(path); + QInstaller::openForRead(&file); qint64 magicMarker; - QInstaller::ResourceCollection meta; QList<QInstaller::OperationBlob> 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<QInstaller::Resource> &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(); } |