diff options
author | kh1 <karsten.heimrich@digia.com> | 2013-10-16 15:04:28 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@digia.com> | 2013-10-16 15:51:30 +0200 |
commit | 0f4ceb1950c18d7de27265504e104a65f2be7628 (patch) | |
tree | a4e1f245ff59cd5848410a61d5e11770cbb80ec5 /src/libs/installer/packagemanagercore_p.cpp | |
parent | 27a63dd497c25f9cc1c97b4decfacd618114521c (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/libs/installer/packagemanagercore_p.cpp')
-rw-r--r-- | src/libs/installer/packagemanagercore_p.cpp | 49 |
1 files changed, 32 insertions, 17 deletions
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) { |