diff options
Diffstat (limited to 'src/sdk/sdkapp.h')
-rw-r--r-- | src/sdk/sdkapp.h | 87 |
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 |