summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2013-10-16 15:04:28 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2013-10-16 15:51:30 +0200
commit0f4ceb1950c18d7de27265504e104a65f2be7628 (patch)
treea4e1f245ff59cd5848410a61d5e11770cbb80ec5 /src
parent27a63dd497c25f9cc1c97b4decfacd618114521c (diff)
Implement a way to replace the default resource.
Change-Id: I2e362d255bf2526f216cbb872bbb64d37383d229 Reviewed-by: Tim Jenssen <tim.jenssen@digia.com> Reviewed-by: Michal Klocek <michal.klocek@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/libs/installer/binaryformat.cpp23
-rw-r--r--src/libs/installer/binaryformat.h1
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp49
-rw-r--r--src/sdk/installerbase.cpp5
4 files changed, 60 insertions, 18 deletions
diff --git a/src/libs/installer/binaryformat.cpp b/src/libs/installer/binaryformat.cpp
index fe1c61ced..081555a59 100644
--- a/src/libs/installer/binaryformat.cpp
+++ b/src/libs/installer/binaryformat.cpp
@@ -796,7 +796,7 @@ BinaryContentPrivate::BinaryContentPrivate(const BinaryContentPrivate &other)
BinaryContentPrivate::~BinaryContentPrivate()
{
foreach (const QByteArray &rccData, m_resourceMappings)
- QResource::unregisterResource((const uchar*)rccData.constData());
+ QResource::unregisterResource((const uchar*)rccData.constData(), QLatin1String(":/metadata"));
m_resourceMappings.clear();
}
@@ -1138,6 +1138,27 @@ int BinaryContent::registerEmbeddedQResources()
}
/*!
+ 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.takeFirst().constData(),
+ QLatin1String(":/metadata"));
+ }
+
+ 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);
+ }
+}
+
+/*!
Returns the binary component index as read from the file.
*/
QInstallerCreator::ComponentIndex BinaryContent::componentIndex() const
diff --git a/src/libs/installer/binaryformat.h b/src/libs/installer/binaryformat.h
index d255ea8a9..0abe78030 100644
--- a/src/libs/installer/binaryformat.h
+++ b/src/libs/installer/binaryformat.h
@@ -242,6 +242,7 @@ public:
qint64 magicMarker() const;
int registerEmbeddedQResources();
+ void registerAsDefaultQResource(const QString &path);
QInstallerCreator::ComponentIndex componentIndex() const;
private:
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index a8978bb52..7cd2c292c 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -1094,7 +1094,25 @@ void PackageManagerCorePrivate::writeUninstallerBinaryData(QIODevice *output, QF
const qint64 dataBlockStart = output->pos();
QVector<Range<qint64> >resourceSegments;
- foreach (const Range<qint64> &segment, layout.metadataResourceSegments) {
+ QVector<Range<qint64> >existingResourceSegments = layout.metadataResourceSegments;
+
+ const QString newDefaultResource = m_core->value(QString::fromLatin1("DefaultResourceReplacement"));
+ if (!newDefaultResource.isEmpty()) {
+ QFile file(newDefaultResource);
+ if (file.open(QIODevice::ReadOnly)) {
+ resourceSegments.append(Range<qint64>::fromStartAndLength(output->pos(), file.size()));
+ appendData(output, &file, file.size());
+ existingResourceSegments.remove(0);
+
+ file.remove(); // clear all possible leftovers
+ m_core->setValue(QString::fromLatin1("DefaultResourceReplacement"), QString());
+ } else {
+ qWarning() << QString::fromLatin1("Could not replace default resource with '%1'.")
+ .arg(newDefaultResource);
+ }
+ }
+
+ foreach (const Range<qint64> &segment, existingResourceSegments) {
input->seek(segment.start());
resourceSegments.append(Range<qint64>::fromStartAndLength(output->pos(), segment.length()));
appendData(output, input, segment.length());
@@ -1156,8 +1174,6 @@ void PackageManagerCorePrivate::writeUninstaller(OperationList performedOperatio
performedOperations.append(takeOwnedOperation(op));
}
- writeMaintenanceConfigFiles();
-
#ifdef Q_OS_MAC
// if it is a bundle, we need some stuff in it...
const QString sourceAppDirPath = QCoreApplication::applicationDirPath();
@@ -1264,12 +1280,8 @@ void PackageManagerCorePrivate::writeUninstaller(OperationList performedOperatio
bool newBinaryWritten = false;
bool replacementExists = false;
- const QString installerBaseBinary = m_core->replaceVariables(m_installerBaseBinaryUnreplaced);
- if (!installerBaseBinary.isEmpty() && !QFileInfo(installerBaseBinary).exists()) {
- qWarning() << "The current installer base binary could not updated with a not existing '%1'. "
- "Please fix the 'installer.setInstallerBaseBinary(<temp_installer_base_binary_path>)' call "
- "in your scripts.";
- } else if (!installerBaseBinary.isEmpty()) {
+ const QString installerBaseBinary = replaceVariables(m_installerBaseBinaryUnreplaced);
+ if (!installerBaseBinary.isEmpty() && QFileInfo(installerBaseBinary).exists()) {
qDebug() << "Got a replacement installer base binary:" << installerBaseBinary;
QFile replacementBinary(installerBaseBinary);
@@ -1285,16 +1297,20 @@ void PackageManagerCorePrivate::writeUninstaller(OperationList performedOperatio
qDebug() << error.message();
}
- if (replacementBinary.remove()) {
- qDebug() << QString::fromLatin1("Removed temporary installer base replacement binary file: %1").arg(
- installerBaseBinary);
- } else {
+ if (!replacementBinary.remove()) {
// Is there anything more sensible we can do with this error? I think not. It's not serious
// enough for throwing / aborting the process.
- qDebug() << QString::fromLatin1("Could not remove installer base binary (%1) after updating "
+ qDebug() << QString::fromLatin1("Could not remove installer base binary '%1' after updating "
"the uninstaller: %2").arg(installerBaseBinary, replacementBinary.errorString());
+ } else {
+ qDebug() << QString::fromLatin1("Removed installer base binary '%1' after updating the "
+ "uninstaller/ maintenance tool.").arg(installerBaseBinary);
}
m_installerBaseBinaryUnreplaced.clear();
+ } else if (!installerBaseBinary.isEmpty() && !QFileInfo(installerBaseBinary).exists()) {
+ qWarning() << QString::fromLatin1("The current uninstaller/ maintenance tool could not be "
+ "updated. '%1' does not exist. Please fix the 'setInstallerBaseBinary(<temp_installer_base_"
+ "binary_path>)' call in your script.").arg(installerBaseBinary);
}
QFile input;
@@ -1338,9 +1354,7 @@ void PackageManagerCorePrivate::writeUninstaller(OperationList performedOperatio
#endif
}
- performedOperations = sortOperationsBasedOnComponentDependencies(
- performedOperations);
-
+ performedOperations = sortOperationsBasedOnComponentDependencies(performedOperations);
m_core->setValue(QLatin1String("installedOperationAreSorted"), QLatin1String("true"));
try {
@@ -1371,6 +1385,7 @@ void PackageManagerCorePrivate::writeUninstaller(OperationList performedOperatio
appendInt64(&file, MagicCookie);
}
input.close();
+ writeMaintenanceConfigFiles();
deferredRename(dataFile + QLatin1String(".new"), dataFile, false);
if (newBinaryWritten) {
diff --git a/src/sdk/installerbase.cpp b/src/sdk/installerbase.cpp
index e188107f9..8d7518fcf 100644
--- a/src/sdk/installerbase.cpp
+++ b/src/sdk/installerbase.cpp
@@ -360,6 +360,11 @@ int main(int argc, char *argv[])
}
}
+ // this needs to happen after we parse the arguments, but before we use the actual resources
+ const QString newDefaultResource = core.value(QString::fromLatin1("DefaultResourceReplacement"));
+ if (!newDefaultResource.isEmpty())
+ content.registerAsDefaultQResource(newDefaultResource);
+
if (QInstaller::isVerbose()) {
qDebug() << "Resource tree after loading the in-binary resource:";
QDirIterator it(QLatin1String(":/"), QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden,