summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/binaryformat.cpp
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-06-23 15:36:56 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-06-24 17:32:13 +0200
commitcead45552aad940d60974f8cebf71e8b4e321ca0 (patch)
tree93447cee025de5bb416d7986a7e4e10f0da562e9 /src/libs/installer/binaryformat.cpp
parent4272fc8a65e6d5ad6bfe1ea45039a2ac300defb6 (diff)
Fix possible case of uninstalling whole windows.
Task-number: QTIFW-511 In case we couldn't read the .dat file or the config file, target dir will return the path the application was started. Now we bail out early if one of the files is missing. Fixes also some outdated code mess when we switched from a single binary maintenance tool to the split binary version. Change-Id: I4c70ac4ca63142873ed1521df47d74331669b576 Reviewed-by: Kai Koehne <kai.koehne@digia.com> Reviewed-by: Niels Weber <niels.weber@digia.com>
Diffstat (limited to 'src/libs/installer/binaryformat.cpp')
-rw-r--r--src/libs/installer/binaryformat.cpp62
1 files changed, 25 insertions, 37 deletions
diff --git a/src/libs/installer/binaryformat.cpp b/src/libs/installer/binaryformat.cpp
index e31627a1c..517883b63 100644
--- a/src/libs/installer/binaryformat.cpp
+++ b/src/libs/installer/binaryformat.cpp
@@ -715,45 +715,33 @@ BinaryContent BinaryContent::readFromApplicationFile()
BinaryContent BinaryContent::readFromBinary(const QString &path)
{
BinaryContent c(path);
- if (!c.d->m_appBinary->open(QIODevice::ReadOnly)) {
- throw Error(QCoreApplication::translate("BinaryContent", "Could not open binary %1: %2")
- .arg(path, c.d->m_appBinary->errorString()));
+
+ // 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(), QInstaller::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)));
}
- // check for supported binary, will throw if we can't find a marker
- const BinaryLayout layout = readBinaryLayout(c.d->m_appBinary.data(),
- findMagicCookie(c.d->m_appBinary.data(), QInstaller::MagicCookie));
-
- bool retry = true;
- if (layout.magicMarker != MagicInstallerMarker) {
- QString binaryDataPath = path;
- QFileInfo fi(path + QLatin1String("/../../.."));
- if (QFileInfo(fi.absoluteFilePath()).isBundle())
- binaryDataPath = fi.absoluteFilePath();
- fi.setFile(binaryDataPath);
-
- c.d->m_binaryDataFile = QSharedPointer<QFile>(new QFile(fi.absolutePath() + QLatin1Char('/')
- + fi.baseName() + QLatin1String(".dat")));
- if (c.d->m_binaryDataFile->exists() && c.d->m_binaryDataFile->open(QIODevice::ReadOnly)) {
- // check for supported binary data file, will throw if we can't find a marker
- try {
- const qint64 cookiePos = findMagicCookie(c.d->m_binaryDataFile.data(),
- QInstaller::MagicCookieDat);
- const BinaryLayout binaryLayout = readBinaryLayout(c.d->m_binaryDataFile.data(), cookiePos);
- readBinaryData(c, c.d->m_binaryDataFile, binaryLayout);
- retry = false;
- } catch (const Error &error) {
- // this seems to be an unsupported dat file, try to read from original binary
- c.d->m_binaryDataFile.clear();
- qDebug() << error.message();
- }
- } else {
- c.d->m_binaryDataFile.clear();
- }
+ 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);
+ if (QFileInfo(fi.absoluteFilePath() + QLatin1String("/../../..")).isBundle())
+ fi.setFile(fi.absoluteFilePath()); // On OSX it's not inside the bundle, deserves TODO.
+
+ c.d->m_binaryDataFile.reset(new QFile(fi.absolutePath() + QLatin1Char('/') + fi.baseName()
+ + QLatin1String(".dat")));
+ QInstaller::openForRead(c.d->m_binaryDataFile.data());
+ cookiePos = findMagicCookie(c.d->m_binaryDataFile.data(), QInstaller::MagicCookieDat);
+ readBinaryData(c, c.d->m_binaryDataFile, readBinaryLayout(c.d->m_binaryDataFile.data(),
+ cookiePos));
+ } else {
+ // We are an installer, all data is appended to our binary itself.
+ readBinaryData(c, c.d->m_appBinary, readBinaryLayout(c.d->m_appBinary.data(), cookiePos));
}
-
- if (retry)
- readBinaryData(c, c.d->m_appBinary, layout);
-
return c;
}