summaryrefslogtreecommitdiffstats
path: root/src/sdk
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-10-14 17:03:54 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-10-15 17:10:18 +0200
commit84875396b75f5615afa637f9633d19bbc79e08e0 (patch)
tree012fe931425ae267361a608c0c63e0d05e4ee03e /src/sdk
parentec92e19193eb9d69a3cf18979d6434cf04764902 (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/sdk')
-rw-r--r--src/sdk/installerbase.cpp16
-rw-r--r--src/sdk/sdkapp.h32
-rw-r--r--src/sdk/updatechecker.cpp11
3 files changed, 19 insertions, 40 deletions
diff --git a/src/sdk/installerbase.cpp b/src/sdk/installerbase.cpp
index 33f8d39e3..d5280a8bc 100644
--- a/src/sdk/installerbase.cpp
+++ b/src/sdk/installerbase.cpp
@@ -95,15 +95,14 @@ int InstallerBase::run()
cookie = QInstaller::BinaryContent::MagicCookie;
}
- QSharedPointer<QFile> binary(new QFile(fileName));
- QInstaller::openForRead(binary.data());
+ QFile binary(fileName);
+ QInstaller::openForRead(&binary);
qint64 magicMarker;
- QInstaller::ResourceCollection resources;
QInstaller::ResourceCollectionManager manager;
QList<QInstaller::OperationBlob> oldOperations;
- QInstaller::BinaryContent::readBinaryContent(binary, &resources, &oldOperations, &manager,
- &magicMarker, cookie);
+ QInstaller::BinaryContent::readBinaryContent(&binary, &oldOperations, &manager, &magicMarker,
+ cookie);
if (QInstaller::isVerbose()) {
qDebug() << "Language:" << QLocale().uiLanguages().value(0,
@@ -111,7 +110,7 @@ int InstallerBase::run()
qDebug() << "Arguments: " << arguments().join(QLatin1String(", ")).toUtf8().constData();
}
- registerMetaResources(resources); // the base class will unregister the resources
+ SDKApp::registerMetaResources(manager.collectionByName("QResources"));
QInstaller::BinaryFormatEngineHandler::instance()->registerResources(manager.collections());
if (QInstaller::isVerbose())
@@ -121,11 +120,6 @@ int InstallerBase::run()
m_core = new QInstaller::PackageManagerCore(magicMarker, oldOperations);
QInstaller::ProductKeyCheck::instance()->init(m_core);
- // We can close the binary file if we are an online installer or no installer at all, cause no
- // embedded archives exist inside the component index. Keeps the .dat file unlocked on Windows.
- if ((!m_core->isInstaller()) || (!m_core->isOfflineOnly()))
- binary->close();
-
CommandLineParser parser;
parser.parse(arguments());
diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h
index a00e2d0e8..d6f830b37 100644
--- a/src/sdk/sdkapp.h
+++ b/src/sdk/sdkapp.h
@@ -48,7 +48,6 @@
#include <fileutils.h>
#include <QApplication>
-#include <QBuffer>
#include <QDir>
#include <QFileInfo>
#include <QResource>
@@ -64,12 +63,8 @@ public:
virtual ~SDKApp()
{
- using namespace QInstaller;
- foreach (const QSharedPointer<Resource> &resource, resourceMappings.resources()) {
- resource->open(); // ignore error here, either we opened it or it is opened
- QResource::unregisterResource((const uchar *) resource->readAll().constData(),
- QLatin1String(":/metadata"));
- }
+ foreach (const QByteArray &ba, m_resourceMappings)
+ QResource::unregisterResource((const uchar*) ba.data(), QLatin1String(":/metadata"));
}
bool notify(QObject *receiver, QEvent *event)
@@ -132,14 +127,9 @@ public:
return QString();
}
- QInstaller::ResourceCollection registeredMetaResources()
- {
- return resourceMappings;
- }
-
- void registerMetaResources(const QInstaller::ResourceCollection &resources)
+ void registerMetaResources(const QInstaller::ResourceCollection &collection)
{
- foreach (const QSharedPointer<QInstaller::Resource> &resource, resources.resources()) {
+ foreach (const QSharedPointer<QInstaller::Resource> &resource, collection.resources()) {
const bool isOpen = resource->isOpen();
if ((!isOpen) && (!resource->open()))
continue;
@@ -151,20 +141,16 @@ public:
if (ba.isEmpty())
continue;
- if (QResource::registerResource((const uchar*) ba.data(), QLatin1String(":/metadata"))) {
- using namespace QInstaller;
- QSharedPointer<QBuffer> buffer(new QBuffer);
- buffer->setData(ba); // set the buffers internal data
- resourceMappings.appendResource(QSharedPointer<Resource>(new Resource(buffer)));
- }
+ if (QResource::registerResource((const uchar*) ba.data(), QLatin1String(":/metadata")))
+ m_resourceMappings.append(ba);
- 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.
+ 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.
}
}
private:
- QInstaller::ResourceCollection resourceMappings;
+ QList<QByteArray> m_resourceMappings;
};
#endif // SDKAPP_H
diff --git a/src/sdk/updatechecker.cpp b/src/sdk/updatechecker.cpp
index 115db45ea..69bfe1732 100644
--- a/src/sdk/updatechecker.cpp
+++ b/src/sdk/updatechecker.cpp
@@ -72,20 +72,19 @@ int UpdateChecker::check()
cookie = QInstaller::BinaryContent::MagicCookie;
}
- QSharedPointer<QFile> binary(new QFile(fileName));
- QInstaller::openForRead(binary.data());
+ QFile binary(fileName);
+ QInstaller::openForRead(&binary);
qint64 magicMarker;
- QInstaller::ResourceCollection resources;
QList<QInstaller::OperationBlob> operations;
QInstaller::ResourceCollectionManager manager;
- QInstaller::BinaryContent::readBinaryContent(binary, &resources, &operations, &manager,
- &magicMarker, cookie);
+ QInstaller::BinaryContent::readBinaryContent(&binary, &operations, &manager, &magicMarker,
+ cookie);
if (magicMarker != QInstaller::BinaryContent::MagicInstallerMarker)
throw QInstaller::Error(QLatin1String("Installers cannot check for updates."));
- registerMetaResources(resources); // the base class will unregister the resources
+ SDKApp::registerMetaResources(manager.collectionByName("QResources"));
// instantiate the installer we are actually going to use
QInstaller::PackageManagerCore core(QInstaller::BinaryContent::MagicUpdaterMarker, operations);