summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-07-14 12:10:06 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-07-15 11:30:48 +0200
commit7e22555eaab60a575bf8185b860ba6f7d6639515 (patch)
treef62eea78c3de4663c38115c2d3fef4dbad255c48
parent7186834d5094083cff984bfc3002acaa5b8ec988 (diff)
Move updater class into sdk binary and rename to UpdateChecker.
Remove some now superfluous methods from binary format. Adjust initializing some objects as we need them not earlier. Unify implementation of accessing the right binary to read the content from. UpdateChecker does now have its own run checker, makes it possible to run the binary even if a e.g. maintenace tool is already running. Change-Id: I94f32f7f38b62b5aee433753abc2fe72e879ddc9 Reviewed-by: Niels Weber <niels.weber@digia.com> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
-rw-r--r--src/libs/installer/binaryformat.cpp30
-rw-r--r--src/libs/installer/binaryformat.h8
-rw-r--r--src/libs/installer/installer.pro2
-rw-r--r--src/libs/installer/updater.cpp108
-rw-r--r--src/sdk/installerbase.cpp31
-rw-r--r--src/sdk/sdk.pro6
-rw-r--r--src/sdk/sdkapp.h17
-rw-r--r--src/sdk/updatechecker.cpp111
-rw-r--r--src/sdk/updatechecker.h (renamed from src/libs/installer/updater.h)26
9 files changed, 150 insertions, 189 deletions
diff --git a/src/libs/installer/binaryformat.cpp b/src/libs/installer/binaryformat.cpp
index a734bc3fd..aaa1fcfc2 100644
--- a/src/libs/installer/binaryformat.cpp
+++ b/src/libs/installer/binaryformat.cpp
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Installer Framework.
@@ -530,18 +530,6 @@ BinaryContent::BinaryContent(const BinaryContent &rhs)
}
/*!
- Reads binary content stored in the current application binary. Maps the embedded resources into memory
- and instantiates performed operations if available.
-*/
-BinaryContent BinaryContent::readAndRegisterFromApplicationFile()
-{
- BinaryContent c = BinaryContent::readFromApplicationFile();
- c.registerEmbeddedQResources();
- c.registerPerformedOperations();
- return c;
-}
-
-/*!
Reads binary content stored in the passed application binary. Maps the embedded resources into memory
and instantiates performed operations if available.
*/
@@ -554,22 +542,6 @@ BinaryContent BinaryContent::readAndRegisterFromBinary(const QString &path)
}
/*!
- Reads binary content stored in the current application binary.
-*/
-BinaryContent BinaryContent::readFromApplicationFile()
-{
-#ifdef Q_OS_OSX
- // On Mac, data is always in a separate file so that the binary can be signed
- QDir dataPath(QCoreApplication::applicationDirPath());
- dataPath.cdUp();
- dataPath.cd(QLatin1String("Resources"));
- return BinaryContent::readFromBinary(dataPath.filePath(QLatin1String("installer.dat")));
-#else
- return BinaryContent::readFromBinary(QCoreApplication::applicationFilePath());
-#endif
-}
-
-/*!
* \class QInstaller::BinaryContent
*
* BinaryContent handles binary information embedded into executables.
diff --git a/src/libs/installer/binaryformat.h b/src/libs/installer/binaryformat.h
index 51c9f3948..904912de8 100644
--- a/src/libs/installer/binaryformat.h
+++ b/src/libs/installer/binaryformat.h
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Installer Framework.
@@ -188,12 +188,8 @@ public:
BinaryContent();
BinaryContent(const BinaryContent &rhs);
- static BinaryContent readAndRegisterFromApplicationFile();
- static BinaryContent readAndRegisterFromBinary(const QString &path);
-
- static BinaryContent readFromApplicationFile();
static BinaryContent readFromBinary(const QString &path);
-
+ static BinaryContent readAndRegisterFromBinary(const QString &path);
static BinaryLayout readBinaryLayout(QFile *const file, qint64 cookiePos);
int registerPerformedOperations();
diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro
index a2427458a..fb2c5d014 100644
--- a/src/libs/installer/installer.pro
+++ b/src/libs/installer/installer.pro
@@ -70,7 +70,6 @@ HEADERS += packagemanagercore.h \
settings.h \
downloadarchivesjob.h \
init.h \
- updater.h \
adminauthorization.h \
elevatedexecuteoperation.h \
fakestopprocessforupdateoperation.h \
@@ -151,7 +150,6 @@ SOURCES += packagemanagercore.cpp \
selfrestartoperation.cpp \
downloadarchivesjob.cpp \
init.cpp \
- updater.cpp \
elevatedexecuteoperation.cpp \
fakestopprocessforupdateoperation.cpp \
lazyplaintextedit.cpp \
diff --git a/src/libs/installer/updater.cpp b/src/libs/installer/updater.cpp
deleted file mode 100644
index ae6eaac29..000000000
--- a/src/libs/installer/updater.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/**************************************************************************
-**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the Qt Installer Framework.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia. For licensing terms and
-** conditions see http://qt.digia.com/licensing. For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights. These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-**************************************************************************/
-#include "updater.h"
-
-#include "productkeycheck.h"
-#include "binaryformat.h"
-#include "component.h"
-#include "init.h"
-#include "packagemanagercore.h"
-#include "utils.h"
-
-#include <QtCore/QDebug>
-
-#include <QtXml/QDomDocument>
-
-#include <iostream>
-
-using namespace QInstaller;
-using namespace QInstallerCreator;
-
-
-Updater::Updater()
-{
- QInstaller::init();
-}
-
-void Updater::setVerbose(bool verbose)
-{
- QInstaller::setVerbose(verbose);
-}
-
-bool Updater::checkForUpdates()
-{
- BinaryContent content = BinaryContent::readAndRegisterFromApplicationFile();
- if (content.magicMarker() == MagicInstallerMarker) {
- qDebug() << "Impossible to use an installer to check for updates!";
- return false;
- }
-
- PackageManagerCore core(content.magicMarker(), content.performedOperations());
- core.setUpdater();
- PackageManagerCore::setVirtualComponentsVisible(true);
- ProductKeyCheck::instance()->init(&core);
-
- if (!core.fetchRemotePackagesTree())
- return false;
-
- const QList<QInstaller::Component *> components = core.updaterComponents();
-
- if (components.isEmpty()) {
- qDebug() << "There are currently no updates available.";
- return false;
- }
-
- QDomDocument doc;
- QDomElement root = doc.createElement(QLatin1String("updates"));
- doc.appendChild(root);
-
- QList<QInstaller::Component *>::const_iterator it;
- for (it = components.begin(); it != components.end(); ++it) {
- QDomElement update = doc.createElement(QLatin1String("update"));
- update.setAttribute(QLatin1String("name"), (*it)->value(scDisplayName));
- update.setAttribute(QLatin1String("version"), (*it)->value(scRemoteVersion));
- update.setAttribute(QLatin1String("size"), (*it)->value(scUncompressedSize));
- root.appendChild(update);
- }
-
- std::cout << doc.toString(4) << std::endl;
- return true;
-}
diff --git a/src/sdk/installerbase.cpp b/src/sdk/installerbase.cpp
index 2e4c88dbb..6a9198d5e 100644
--- a/src/sdk/installerbase.cpp
+++ b/src/sdk/installerbase.cpp
@@ -43,6 +43,7 @@
#include "installerbasecommons.h"
#include "sdkapp.h"
#include "tabcontroller.h"
+#include "updatechecker.h"
#include <binaryformat.h>
#include <errors.h>
@@ -52,7 +53,6 @@
#include <remoteserver.h>
#include <settings.h>
#include <utils.h>
-#include <updater.h>
#include <kdselfrestarter.h>
#include <kdrunoncechecker.h>
@@ -95,8 +95,6 @@ int main(int argc, char *argv[])
#endif
qsrand(QDateTime::currentDateTime().toTime_t());
- const KDSelfRestarter restarter(argc, argv);
- KDRunOnceChecker runCheck(QLatin1String("lockmyApp1234865.lock"));
QCommandLineParser parser;
QCommandLineOption help = parser.addHelpOption();
@@ -257,18 +255,11 @@ int main(int argc, char *argv[])
#endif
}
- if (parser.isSet(checkUpdates)) {
- SDKApp<QCoreApplication> app(argc, argv);
- if (runCheck.isRunning(KDRunOnceChecker::ProcessList))
- throw Error(QLatin1String("An instance is already checking for updates."));
-
- Updater u;
- u.setVerbose(parser.isSet(verbose));
- return u.checkForUpdates() ? EXIT_SUCCESS : EXIT_FAILURE;
- }
+ if (parser.isSet(checkUpdates))
+ return UpdateChecker().check(argc, argv);
SDKApp<QApplication> app(argc, argv);
- QInstaller::init(); // register custom operations
+ KDRunOnceChecker runCheck(QLatin1String("lockmyApp1234865.lock"));
if (runCheck.isRunning(KDRunOnceChecker::ProcessList)
|| runCheck.isRunning(KDRunOnceChecker::Lockfile)) {
@@ -279,6 +270,9 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
+ const KDSelfRestarter restarter(argc, argv);
+ QInstaller::init(); // register custom operations
+
if (QInstaller::isVerbose()) {
qDebug() << VERSION;
qDebug() << "Arguments:" << app.arguments();
@@ -293,16 +287,7 @@ int main(int argc, char *argv[])
qDebug() << QString::fromLatin1(" %1").arg(it.next());
}
- QString binaryFile = QCoreApplication::applicationFilePath();
-#ifdef Q_OS_OSX
- // The installer binary on OSX does not contain the binary content, it's put
- // into the resources folder as separate file. Adjust the actual binary path.
- QDir resourcePath(QFileInfo(binaryFile).dir());
- resourcePath.cdUp();
- resourcePath.cd(QLatin1String("Resources"));
- binaryFile = resourcePath.filePath(QLatin1String("installer.dat"));
-#endif
- BinaryContent content = BinaryContent::readAndRegisterFromBinary(binaryFile);
+ BinaryContent content = BinaryContent::readAndRegisterFromBinary(app.binaryFile());
// instantiate the installer we are actually going to use
PackageManagerCore core(content.magicMarker(), content.performedOperations());
diff --git a/src/sdk/sdk.pro b/src/sdk/sdk.pro
index e30e8baa2..e33c53772 100644
--- a/src/sdk/sdk.pro
+++ b/src/sdk/sdk.pro
@@ -111,12 +111,14 @@ HEADERS += \
installerbasecommons.h \
settingsdialog.h \
console.h \
- sdkapp.h
+ sdkapp.h \
+ updatechecker.h
SOURCES = installerbase.cpp \
tabcontroller.cpp \
installerbasecommons.cpp \
- settingsdialog.cpp
+ settingsdialog.cpp \
+ updatechecker.cpp
win32 {
# Force to overwrite the default manifest file with our own extended version.
diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h
index f00dd6eb9..1c3d98505 100644
--- a/src/sdk/sdkapp.h
+++ b/src/sdk/sdkapp.h
@@ -63,9 +63,26 @@ public:
return T::notify(receiver, event);
} catch (std::exception &e) {
qFatal("Exception thrown: %s", e.what());
+ } catch (...) {
+ qFatal("Unknown exception caught.");
}
return false;
}
+
+ QString binaryFile() const
+ {
+ QString binaryFile = QCoreApplication::applicationFilePath();
+#ifdef Q_OS_OSX
+ // The installer binary on OSX does not contain the binary content, it's put into
+ // the resources folder as separate file. Adjust the actual binary path. No error
+ // checking here since we will fail later while reading the binary content.
+ QDir resourcePath(QFileInfo(binaryFile).dir());
+ resourcePath.cdUp();
+ resourcePath.cd(QLatin1String("Resources"));
+ binaryFile = resourcePath.filePath(QLatin1String("installer.dat"));
+#endif
+ return binaryFile;
+ }
};
#endif // SDKAPP_H
diff --git a/src/sdk/updatechecker.cpp b/src/sdk/updatechecker.cpp
new file mode 100644
index 000000000..29ef05fd1
--- /dev/null
+++ b/src/sdk/updatechecker.cpp
@@ -0,0 +1,111 @@
+/**************************************************************************
+**
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt Installer Framework.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+**************************************************************************/
+
+#include "updatechecker.h"
+#include "sdkapp.h"
+
+#include <binaryformat.h>
+#include <component.h>
+#include <constants.h>
+#include <errors.h>
+#include <init.h>
+#include <kdrunoncechecker.h>
+#include <packagemanagercore.h>
+#include <productkeycheck.h>
+
+#include <QDomDocument>
+
+#include <iostream>
+
+int UpdateChecker::check(int argc, char *argv[])
+{
+ try {
+ SDKApp<QCoreApplication> app(argc, argv);
+
+ KDRunOnceChecker runCheck((QLatin1String("lockmyApp15021976.lock")));
+ if (runCheck.isRunning(KDRunOnceChecker::Lockfile))
+ throw QInstaller::Error(QLatin1String("An instance is already checking for updates."));
+
+ QInstaller::init(); // register custom operations
+
+ const QInstaller::BinaryContent content =
+ QInstaller::BinaryContent::readAndRegisterFromBinary(app.binaryFile());
+ if (content.magicMarker() != QInstaller::MagicInstallerMarker)
+ throw QInstaller::Error(QLatin1String("Installers cannot check for updates."));
+
+ QInstaller::PackageManagerCore core(QInstaller::MagicUpdaterMarker, content
+ .performedOperations());
+ ProductKeyCheck::instance()->init(&core);
+ QInstaller::PackageManagerCore::setVirtualComponentsVisible(true);
+
+ if (!core.fetchRemotePackagesTree())
+ throw QInstaller::Error(core.error());
+
+ const QList<QInstaller::Component *> components = core.updaterComponents();
+ if (components.isEmpty())
+ throw QInstaller::Error(QLatin1String("There are currently no updates available."));
+
+ QDomDocument doc;
+ QDomElement root = doc.createElement(QLatin1String("updates"));
+ doc.appendChild(root);
+
+ foreach (QInstaller::Component *component, components) {
+ QDomElement update = doc.createElement(QLatin1String("update"));
+ update.setAttribute(QLatin1String("name"),
+ component->value(QInstaller::scDisplayName));
+ update.setAttribute(QLatin1String("version"),
+ component->value(QInstaller::scRemoteVersion));
+ update.setAttribute(QLatin1String("size"),
+ component->value(QInstaller::scUncompressedSize));
+ root.appendChild(update);
+ }
+
+ std::cout << qPrintable(doc.toString(4)) << std::endl;
+ return EXIT_SUCCESS;
+ } catch (const QInstaller::Error &e) {
+ std::cerr << qPrintable(e.message()) << std::endl;
+ } catch (const std::exception &e) {
+ std::cerr << e.what() << std::endl;
+ } catch (...) {
+ std::cerr << "Unknown exception caught." << std::endl;
+ }
+ return EXIT_FAILURE;
+}
diff --git a/src/libs/installer/updater.h b/src/sdk/updatechecker.h
index 1f5f39f53..504e97604 100644
--- a/src/libs/installer/updater.h
+++ b/src/sdk/updatechecker.h
@@ -1,6 +1,6 @@
/**************************************************************************
**
-** Copyright (C) 2012-2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2012-2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Installer Framework.
@@ -39,26 +39,14 @@
**
**************************************************************************/
-#ifndef UPDATER_H
-#define UPDATER_H
+#ifndef UPDATECHECKER_H
+#define UPDATECHECKER_H
-#include "installer_global.h"
-
-#include <QtCore/QObject>
-
-namespace QInstaller {
-
-class INSTALLER_EXPORT Updater : public QObject
+class UpdateChecker
{
- Q_OBJECT
-
public:
- explicit Updater();
-
- bool checkForUpdates();
- void setVerbose(bool verbose);
+ UpdateChecker() {}
+ int check(int argc, char *argv[]);
};
-} // namespace QInstaller
-
-#endif
+#endif // UPDATECHECKER_H