From 77b1e168202e8781ddfe5c06fc1ceaea5934e855 Mon Sep 17 00:00:00 2001 From: kh1 Date: Fri, 29 Aug 2014 12:56:06 +0200 Subject: 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 --- src/sdk/updatechecker.cpp | 114 ++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 54 deletions(-) (limited to 'src/sdk/updatechecker.cpp') 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 +#include #include -#include #include #include #include @@ -55,57 +53,65 @@ #include -int UpdateChecker::check(int argc, char *argv[]) +UpdateChecker::UpdateChecker(int &argc, char *argv[]) + : SDKApp(argc, argv) { - try { - SDKApp 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 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 binary(new QFile(fileName)); + QInstaller::openForRead(binary.data()); + + qint64 magicMarker; + QInstaller::ResourceCollection resources; + QList 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 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; } -- cgit v1.2.3