summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/binarycontent.cpp
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/libs/installer/binarycontent.cpp
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/libs/installer/binarycontent.cpp')
-rw-r--r--src/libs/installer/binarycontent.cpp311
1 files changed, 0 insertions, 311 deletions
diff --git a/src/libs/installer/binarycontent.cpp b/src/libs/installer/binarycontent.cpp
index 6280134d9..25032177b 100644
--- a/src/libs/installer/binarycontent.cpp
+++ b/src/libs/installer/binarycontent.cpp
@@ -41,16 +41,9 @@
#include "binarycontent.h"
-#include "binaryformat.h"
-#include "binaryformatenginehandler.h"
#include "errors.h"
#include "fileio.h"
#include "fileutils.h"
-#include "kdupdaterupdateoperationfactory.h"
-#include "utils.h"
-
-#include <QFile>
-#include <QResource>
namespace QInstaller {
@@ -101,124 +94,6 @@ qint64 BinaryContent::findMagicCookie(QFile *in, quint64 magicCookie)
}
/*!
- \internal
- Registers the resource found at \a segment within \a file into the Qt resource system.
-*/
-static QByteArray addResourceFromBinary(QFile* file, const Range<qint64> &segment)
-{
- if (segment.length() <= 0)
- return 0;
-
- if (!file->seek(segment.start())) {
- throw Error(QCoreApplication::translate("BinaryContent",
- "Could not seek to in-binary resource. (offset: %1, length: %2)")
- .arg(QString::number(segment.start()), QString::number(segment.length())));
- }
-
- QByteArray ba = QInstaller::retrieveData(file, segment.length());
- if (!QResource::registerResource((const uchar*) ba.constData(), QLatin1String(":/metadata"))) {
- throw Error(QCoreApplication::translate("BinaryContent",
- "Could not register in-binary resource."));
- }
- return ba;
-}
-
-
-// -- Private
-
-class BinaryContent::Private : public QSharedData
-{
-public:
- Private();
- explicit Private(const QString &path);
- Private(const Private &other);
- ~Private();
-
- qint64 m_magicMarker;
- qint64 m_dataBlockStart;
-
- QSharedPointer<QFile> m_appBinary;
- QSharedPointer<QFile> m_binaryDataFile;
-
- QList<Operation *> m_performedOperations;
- QList<QPair<QString, QString> > m_performedOperationsData;
-
- QVector<QByteArray> m_resourceMappings;
- QVector<Range<qint64> > m_metadataResourceSegments;
-};
-
-
-BinaryContent::Private::Private()
- : m_magicMarker(Q_INT64_C(0))
- , m_dataBlockStart(Q_INT64_C(0))
- , m_appBinary(0)
- , m_binaryDataFile(0)
-{}
-
-BinaryContent::Private::Private(const QString &path)
- : m_magicMarker(Q_INT64_C(0))
- , m_dataBlockStart(Q_INT64_C(0))
- , m_appBinary(new QFile(path))
- , m_binaryDataFile(0)
-{}
-
-BinaryContent::Private::Private(const Private &other)
- : QSharedData(other)
- , m_magicMarker(other.m_magicMarker)
- , m_dataBlockStart(other.m_dataBlockStart)
- , m_appBinary(other.m_appBinary)
- , m_binaryDataFile(other.m_binaryDataFile)
- , m_performedOperations(other.m_performedOperations)
- , m_performedOperationsData(other.m_performedOperationsData)
- , m_resourceMappings(other.m_resourceMappings)
- , m_metadataResourceSegments(other.m_metadataResourceSegments)
-{}
-
-BinaryContent::Private::~Private()
-{
- foreach (const QByteArray &rccData, m_resourceMappings)
- QResource::unregisterResource((const uchar*) rccData.constData(), QLatin1String(":/metadata"));
- m_resourceMappings.clear();
-}
-
-
-// -- BinaryContent
-
-BinaryContent::BinaryContent()
- : d(new Private)
-{}
-
-BinaryContent::~BinaryContent()
-{}
-
-BinaryContent::BinaryContent(const QString &path)
- : d(new Private(path))
-{}
-
-BinaryContent::BinaryContent(const BinaryContent &rhs)
- : d(rhs.d)
-{}
-
-BinaryContent &BinaryContent::operator=(const BinaryContent &rhs)
-{
- if (this != &rhs)
- d = rhs.d;
- return *this;
-}
-
-/*!
- Reads binary content stored in the passed application binary. Maps the embedded resources into
- memory and instantiates performed operations if available.
-*/
-BinaryContent BinaryContent::readAndRegisterFromBinary(const QString &path)
-{
- BinaryContent c = BinaryContent::readFromBinary(path);
- c.registerEmbeddedQResources();
- c.registerPerformedOperations();
- return c;
-}
-
-/*!
* \class QInstaller::BinaryContent
*
* BinaryContent handles binary information embedded into executables.
@@ -288,41 +163,6 @@ BinaryContent BinaryContent::readAndRegisterFromBinary(const QString &path)
* \endverbatim
*/
-BinaryContent BinaryContent::readFromBinary(const QString &path)
-{
- BinaryContent c(path);
-
- // Try to read the binary layout of the calling application. We need to figure out
- // if we are in installer or an unistaller (maintenance, package manager, updater) binary.
- QInstaller::openForRead(c.d->m_appBinary.data());
- quint64 cookiePos = findMagicCookie(c.d->m_appBinary.data(), BinaryContent::MagicCookie);
- if (!c.d->m_appBinary->seek(cookiePos - sizeof(qint64))) { // seek to read the marker
- throw Error(QCoreApplication::translate("BinaryContent",
- "Could not seek to %1 to read the magic marker.").arg(cookiePos - sizeof(qint64)));
- }
- const qint64 magicMarker = QInstaller::retrieveInt64(c.d->m_appBinary.data());
-
- if (magicMarker != MagicInstallerMarker) {
- // We are not an installer, so we need to read the data from the .dat file.
-
- QFileInfo fi(path);
- QString bundlePath; // On OSX it's not inside the bundle, deserves TODO.
- if (QInstaller::isInBundle(fi.absoluteFilePath(), &bundlePath))
- fi.setFile(bundlePath);
-
- c.d->m_binaryDataFile.reset(new QFile(fi.absolutePath() + QLatin1Char('/') + fi.baseName()
- + QLatin1String(".dat")));
- QInstaller::openForRead(c.d->m_binaryDataFile.data());
- readBinaryData(c, c.d->m_binaryDataFile, binaryLayout(c.d->m_binaryDataFile.data(),
- BinaryContent::MagicCookieDat));
- } else {
- // We are an installer, all data is appended to our binary itself.
- readBinaryData(c, c.d->m_appBinary, binaryLayout(c.d->m_appBinary.data(),
- BinaryContent::MagicCookie));
- }
- return c;
-}
-
/* static */
BinaryLayout BinaryContent::binaryLayout(QFile *file, quint64 magicCookie)
{
@@ -370,157 +210,6 @@ BinaryLayout BinaryContent::binaryLayout(QFile *file, quint64 magicCookie)
return layout;
}
-/* static */
-void BinaryContent::readBinaryData(BinaryContent &content, const QSharedPointer<QFile> &file,
- const BinaryLayout &layout)
-{
- content.d->m_magicMarker = layout.magicMarker;
- content.d->m_metadataResourceSegments = layout.metadataResourceSegments;
-
- const qint64 dataBlockStart = layout.endOfData - layout.dataBlockSize;
- const qint64 operationsStart = layout.operationsStart + dataBlockStart;
- if (!file->seek(operationsStart))
- throw Error(QCoreApplication::translate("BinaryContent", "Could not seek to operation list."));
-
- const qint64 operationsCount = QInstaller::retrieveInt64(file.data());
- qDebug() << "Number of operations:" << operationsCount;
-
- for (int i = 0; i < operationsCount; ++i) {
- const QString name = QInstaller::retrieveString(file.data());
- const QString data = QInstaller::retrieveString(file.data());
- content.d->m_performedOperationsData.append(qMakePair(name, data));
- }
-
- // seek to the position of the resource collections segment info
- const qint64 resourceOffsetAndLengtSize = 2 * sizeof(qint64);
- const qint64 resourceSectionSize = resourceOffsetAndLengtSize * layout.resourceCount;
- qint64 offset = layout.endOfData - layout.indexSize - resourceSectionSize
- - resourceOffsetAndLengtSize;
- if (!file->seek(offset)) {
- throw Error(QCoreApplication::translate("BinaryContent",
- "Could not seek to read the resource collection segment info."));
- }
-
- offset = QInstaller::retrieveInt64(file.data()) + dataBlockStart;
- if (!file->seek(offset)) {
- throw Error(QCoreApplication::translate("BinaryContent", "Could not seek to start "
- "position of resource collection block."));
- }
-
- ResourceCollectionManager collectionManager;
- collectionManager.read(file, dataBlockStart);
- BinaryFormatEngineHandler::instance()->registerResources(collectionManager.collections());
-
- if (!QInstaller::isVerbose())
- return;
-
- const QList<ResourceCollection> collections = collectionManager.collections();
- qDebug() << "Number of resource collections loaded:" << collections.count();
- foreach (const ResourceCollection &collection, collections) {
- const QList<QSharedPointer<Resource> > resources = collection.resources();
- qDebug() << collection.name().data() << "loaded...";
- QStringList resourcesWithSize;
- foreach (const QSharedPointer<Resource> &resource, resources) {
- resourcesWithSize.append(QString::fromLatin1("%1 - %2")
- .arg(QString::fromUtf8(resource->name()), humanReadableSize(resource->size())));
- }
- if (!resourcesWithSize.isEmpty()) {
- qDebug() << " - " << resources.count() << "resources: "
- << qPrintable(resourcesWithSize.join(QLatin1String("; ")));
- }
- }
-}
-
-/*!
- Registers already performed operations.
-*/
-int BinaryContent::registerPerformedOperations()
-{
- if (d->m_performedOperations.count() > 0)
- return d->m_performedOperations.count();
-
- for (int i = 0; i < d->m_performedOperationsData.count(); ++i) {
- const QPair<QString, QString> opPair = d->m_performedOperationsData.at(i);
- QScopedPointer<Operation> op(KDUpdater::UpdateOperationFactory::instance().create(opPair.first));
- if (op.isNull()) {
- qWarning() << QString::fromLatin1("Failed to load unknown operation %1").arg(opPair.first);
- continue;
- }
-
- if (!op->fromXml(opPair.second)) {
- qWarning() << "Failed to load XML for operation:" << opPair.first;
- continue;
- }
- d->m_performedOperations.append(op.take());
- }
- return d->m_performedOperations.count();
-}
-
-/*!
- Returns the operations performed during installation. Returns an empty list if no operations
- are instantiated, performed or the binary is the installer application.
-*/
-OperationList BinaryContent::performedOperations() const
-{
- return d->m_performedOperations;
-}
-
-/*!
- Returns the magic marker found in the binary. Returns 0 if no marker has been found.
-*/
-qint64 BinaryContent::magicMarker() const
-{
- return d->m_magicMarker;
-}
-
-/*!
- Registers the Qt resources embedded in this binary.
-*/
-int BinaryContent::registerEmbeddedQResources()
-{
- if (d->m_resourceMappings.count() > 0)
- return d->m_resourceMappings.count();
-
- const bool hasBinaryDataFile = !d->m_binaryDataFile.isNull();
- QFile *const data = hasBinaryDataFile ? d->m_binaryDataFile.data() : d->m_appBinary.data();
- if (data != 0 && !data->isOpen() && !data->open(QIODevice::ReadOnly)) {
- throw Error(QCoreApplication::translate("BinaryContent", "Could not open binary %1: %2")
- .arg(data->fileName(), data->errorString()));
- }
-
- foreach (const Range<qint64> &i, d->m_metadataResourceSegments)
- d->m_resourceMappings.append(addResourceFromBinary(data, i));
-
- d->m_appBinary.clear();
- if (hasBinaryDataFile)
- d->m_binaryDataFile.clear();
-
- return d->m_resourceMappings.count();
-}
-
-/*!
- Registers the passed file as default resource content. If the embedded resources are already
- mapped into memory, it will replace the first with the new content.
-*/
-void BinaryContent::registerAsDefaultQResource(const QString &path)
-{
- QFile resource(path);
- bool success = resource.open(QIODevice::ReadOnly);
- if (success && (d->m_resourceMappings.count() > 0)) {
- success = QResource::unregisterResource((const uchar*) d->m_resourceMappings.first()
- .constData(), QLatin1String(":/metadata"));
- if (success)
- d->m_resourceMappings.remove(0);
- }
-
- if (success) {
- d->m_resourceMappings.prepend(addResourceFromBinary(&resource,
- Range<qint64>::fromStartAndEnd(0, resource.size())));
- } else {
- qWarning() << QString::fromLatin1("Could not register '%1' as default resource.").arg(path);
- }
-}
-
void BinaryContent::readBinaryContent(const QSharedPointer<QFile> &in,
ResourceCollection *metaResources, QList<OperationBlob> *operations,
ResourceCollectionManager *manager, qint64 *magicMarker, quint64 magicCookie)