summaryrefslogtreecommitdiffstats
path: root/src/sdk/sdkapp.h
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-08-29 12:56:06 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-09-04 10:41:53 +0200
commit77b1e168202e8781ddfe5c06fc1ceaea5934e855 (patch)
treeffcd3040a42ffd5086b34a034d042b0d65143aa3 /src/sdk/sdkapp.h
parente9e26f11d78def8ad8cb8f1864c61d88e3a1f0be (diff)
Split and implement new installer base, update checker.
Based on the former patches, split the installer base into its own class. Use the new binary content read functions. Adjust uses to match the new classes. Adjust installer base /update checker signature and inheritance. Remove all now superfluous functions from binary content. Core engine instantiates the operations now, makes reading and writing more generic. Move product key check into QInstaller namespace. Make use of the new command line parser. Change-Id: I00aff79085b69ce627906881b43f374681ea7e91 Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src/sdk/sdkapp.h')
-rw-r--r--src/sdk/sdkapp.h87
1 files changed, 82 insertions, 5 deletions
diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h
index f0095e3bf..a00e2d0e8 100644
--- a/src/sdk/sdkapp.h
+++ b/src/sdk/sdkapp.h
@@ -42,12 +42,16 @@
#ifndef SDKAPP_H
#define SDKAPP_H
-#include <QApplication>
+#include <binarycontent.h>
+#include <binaryformat.h>
+#include <fileio.h>
+#include <fileutils.h>
-#ifdef Q_OS_OSX
+#include <QApplication>
+#include <QBuffer>
#include <QDir>
#include <QFileInfo>
-#endif
+#include <QResource>
template<class T>
class SDKApp : public T
@@ -58,8 +62,14 @@ public:
{
}
- ~SDKApp()
+ 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"));
+ }
}
bool notify(QObject *receiver, QEvent *event)
@@ -74,6 +84,15 @@ public:
return false;
}
+ /*!
+ Returns the installer/ maintenance tool binary. In case of an installer this will be the
+ installer binary itself, which contains the binary layout and the binary content. In case
+ of an maintenance tool, it will return a binary that has just a binary layout append.
+
+ Note on OSX: For compatibility reason this function will return the a .dat file located
+ inside the resource folder in the application bundle, as on OSX the binary layout can not
+ be appended to the actual installer/ maintenance tool binary itself because of signing.
+ */
QString binaryFile() const
{
QString binaryFile = QCoreApplication::applicationFilePath();
@@ -84,10 +103,68 @@ public:
QDir resourcePath(QFileInfo(binaryFile).dir());
resourcePath.cdUp();
resourcePath.cd(QLatin1String("Resources"));
- binaryFile = resourcePath.filePath(QLatin1String("installer.dat"));
+ return resourcePath.filePath(QLatin1String("installer.dat"));
#endif
return binaryFile;
}
+
+ /*!
+ Returns the corresponding .dat file for a given installer/ maintenance tool binary or an
+ empty string if it fails to find one.
+ */
+ QString datFile(const QString &binaryFile) const
+ {
+ QFile file(binaryFile);
+ QInstaller::openForRead(&file);
+ const quint64 cookiePos = QInstaller::BinaryContent::findMagicCookie(&file,
+ QInstaller::BinaryContent::MagicCookie);
+ if (!file.seek(cookiePos - sizeof(qint64))) // seek to read the marker
+ return QString(); // ignore error, we will fail later
+
+ const qint64 magicMarker = QInstaller::retrieveInt64(&file);
+ if (magicMarker == QInstaller::BinaryContent::MagicUninstallerMarker) {
+ QFileInfo fi(binaryFile);
+ QString bundlePath;
+ if (QInstaller::isInBundle(fi.absoluteFilePath(), &bundlePath))
+ fi.setFile(bundlePath);
+ return fi.absoluteDir().filePath(fi.baseName() + QLatin1String(".dat"));
+ }
+ return QString();
+ }
+
+ QInstaller::ResourceCollection registeredMetaResources()
+ {
+ return resourceMappings;
+ }
+
+ void registerMetaResources(const QInstaller::ResourceCollection &resources)
+ {
+ foreach (const QSharedPointer<QInstaller::Resource> &resource, resources.resources()) {
+ const bool isOpen = resource->isOpen();
+ if ((!isOpen) && (!resource->open()))
+ continue;
+
+ if (!resource->seek(0))
+ continue;
+
+ const QByteArray ba = resource->readAll();
+ 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 (!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;
};
#endif // SDKAPP_H