summaryrefslogtreecommitdiffstats
path: root/src/sdk/updatechecker.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/sdk/updatechecker.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/sdk/updatechecker.cpp')
-rw-r--r--src/sdk/updatechecker.cpp114
1 files changed, 60 insertions, 54 deletions
diff --git a/src/sdk/updatechecker.cpp b/src/sdk/updatechecker.cpp
index 60587942e..2ebe39b92 100644
--- a/src/sdk/updatechecker.cpp
+++ b/src/sdk/updatechecker.cpp
@@ -40,11 +40,9 @@
**************************************************************************/
#include "updatechecker.h"
-#include "sdkapp.h"
-#include <binarycontent.h>
+#include <binaryformatenginehandler.h>
#include <component.h>
-#include <constants.h>
#include <errors.h>
#include <init.h>
#include <kdrunoncechecker.h>
@@ -55,57 +53,65 @@
#include <iostream>
-int UpdateChecker::check(int argc, char *argv[])
+UpdateChecker::UpdateChecker(int &argc, char *argv[])
+ : SDKApp<QCoreApplication>(argc, 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::BinaryContent::MagicInstallerMarker)
- throw QInstaller::Error(QLatin1String("Installers cannot check for updates."));
-
- QInstaller::PackageManagerCore core(QInstaller::BinaryContent::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;
+ QInstaller::init(); // register custom operations
+}
+
+int UpdateChecker::check()
+{
+ KDRunOnceChecker runCheck((QLatin1String("lockmyApp15021976.lock")));
+ if (runCheck.isRunning(KDRunOnceChecker::Lockfile))
+ throw QInstaller::Error(QLatin1String("An instance is already checking for updates."));
+
+ QString fileName = datFile(binaryFile());
+ quint64 cookie = QInstaller::BinaryContent::MagicCookieDat;
+ if (fileName.isEmpty()) {
+ fileName = binaryFile();
+ cookie = QInstaller::BinaryContent::MagicCookie;
}
- return EXIT_FAILURE;
+
+ QSharedPointer<QFile> binary(new QFile(fileName));
+ QInstaller::openForRead(binary.data());
+
+ qint64 magicMarker;
+ QInstaller::ResourceCollection resources;
+ QList<QInstaller::OperationBlob> operations;
+ QInstaller::ResourceCollectionManager manager;
+ QInstaller::BinaryContent::readBinaryContent(binary, &resources, &operations, &manager,
+ &magicMarker, cookie);
+
+ if (magicMarker != QInstaller::BinaryContent::MagicInstallerMarker)
+ throw QInstaller::Error(QLatin1String("Installers cannot check for updates."));
+
+ registerMetaResources(resources); // the base class will unregister the resources
+
+ // instantiate the installer we are actually going to use
+ QInstaller::PackageManagerCore core(QInstaller::BinaryContent::MagicUpdaterMarker, operations);
+ QInstaller::BinaryFormatEngineHandler::instance()->registerResources(manager.collections());
+ QInstaller::PackageManagerCore::setVirtualComponentsVisible(true);
+ QInstaller::ProductKeyCheck::instance()->init(&core);
+
+ 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;
}