diff options
Diffstat (limited to 'src/sdk/sdkapp.h')
-rw-r--r-- | src/sdk/sdkapp.h | 89 |
1 files changed, 65 insertions, 24 deletions
diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h index cbd410b80..eef0110ec 100644 --- a/src/sdk/sdkapp.h +++ b/src/sdk/sdkapp.h @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2024 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -60,6 +60,10 @@ #include <QMetaEnum> #include <QTranslator> +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +#include <QNetworkInformation> +#endif + template<class T> class SDKApp : public T { @@ -71,6 +75,9 @@ public: , m_core(nullptr) { m_parser.parse(QCoreApplication::arguments()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + QNetworkInformation::loadDefaultBackend(); +#endif } virtual ~SDKApp() @@ -83,6 +90,8 @@ public: { try { return T::notify(receiver, event); + } catch (QInstaller::Error &e) { + qFatal("Exception thrown: %s", qPrintable(e.message())); } catch (std::exception &e) { qFatal("Exception thrown: %s", e.what()); } catch (...) { @@ -107,14 +116,9 @@ public: } binary.close(); #endif - QString fileName = datFile(binaryFile()); - quint64 cookie = QInstaller::BinaryContent::MagicCookieDat; - if (fileName.isEmpty()) { - fileName = binaryFile(); - cookie = QInstaller::BinaryContent::MagicCookie; - } - - binary.setFileName(fileName); + QString datFileName = datFile(binaryFile()); + quint64 cookie = datFileName.isEmpty() ? QInstaller::BinaryContent::MagicCookie : QInstaller::BinaryContent::MagicCookieDat; + binary.setFileName(!datFileName.isEmpty() ? datFileName : binaryFile()); QInstaller::openForRead(&binary); qint64 magicMarker; @@ -161,7 +165,7 @@ public: } QLoggingCategory::setFilterRules(loggingRules); qCDebug(QInstaller::lcInstallerInstallLog).noquote() << "Arguments:" << - QCoreApplication::arguments().join(QLatin1String(", ")); + m_parser.arguments().join(QLatin1String(", ")); for (auto &optionName : m_parser.optionNames()) { if (isCommandLineInterface) @@ -183,12 +187,12 @@ public: const QStringList arguments = m_parser.value(CommandLineOptions::scStartClientLong) .split(QLatin1Char(','), Qt::SkipEmptyParts); m_core = new QInstaller::PackageManagerCore( - magicMarker, oldOperations, + magicMarker, oldOperations, datFileName, arguments.value(0, QLatin1String(QInstaller::Protocol::DefaultSocket)), arguments.value(1, QLatin1String(QInstaller::Protocol::DefaultAuthorizationKey)), QInstaller::Protocol::Mode::Debug, userArgs, isCommandLineInterface); } else { - m_core = new QInstaller::PackageManagerCore(magicMarker, oldOperations, + m_core = new QInstaller::PackageManagerCore(magicMarker, oldOperations, datFileName, QUuid::createUuid().toString(), QUuid::createUuid().toString(), QInstaller::Protocol::Mode::Production, userArgs, isCommandLineInterface); } @@ -203,8 +207,9 @@ public: const QStringList translations = m_core->settings().translations(); if (translations.isEmpty()) { - foreach (const QLocale locale, QLocale().uiLanguages()) { - QScopedPointer<QTranslator> qtTranslator(new QTranslator(QCoreApplication::instance())); + for (const QString &language : QLocale().uiLanguages()) { + const QLocale locale(language); + std::unique_ptr<QTranslator> qtTranslator(new QTranslator(QCoreApplication::instance())); bool qtLoaded = qtTranslator->load(locale, QLatin1String("qt"), QLatin1String("_"), newDirectory); if (!qtLoaded) @@ -213,14 +218,14 @@ public: if (qtLoaded || locale.language() == QLocale::English) { if (qtLoaded) - QCoreApplication::instance()->installTranslator(qtTranslator.take()); + QCoreApplication::instance()->installTranslator(qtTranslator.release()); - QScopedPointer<QTranslator> ifwTranslator(new QTranslator(QCoreApplication::instance())); + std::unique_ptr <QTranslator> ifwTranslator(new QTranslator(QCoreApplication::instance())); bool ifwLoaded = ifwTranslator->load(locale, QLatin1String("ifw"), QLatin1String("_"), newDirectory); if (!ifwLoaded) ifwLoaded = ifwTranslator->load(locale, QLatin1String("ifw"), QLatin1String("_"), directory); if (ifwLoaded) { - QCoreApplication::instance()->installTranslator(ifwTranslator.take()); + QCoreApplication::instance()->installTranslator(ifwTranslator.release()); } else { qCWarning(QInstaller::lcDeveloperBuild) << "Could not load IFW translation for language" << QLocale::languageToString(locale.language()); @@ -237,9 +242,9 @@ public: } } else { foreach (const QString &translation, translations) { - QScopedPointer<QTranslator> translator(new QTranslator(QCoreApplication::instance())); + std::unique_ptr<QTranslator> translator(new QTranslator(QCoreApplication::instance())); if (translator->load(translation, QLatin1String(":/translations"))) - QCoreApplication::instance()->installTranslator(translator.take()); + QCoreApplication::instance()->installTranslator(translator.release()); } QLocale currentLocale(translations.at(0).section(QLatin1Char('_'), 1)); lang = currentLocale; @@ -269,6 +274,16 @@ public: KDUpdater::FileDownloaderFactory::instance().setProxyFactory(m_core->proxyFactory()); } + if (m_parser.isSet(CommandLineOptions::scLocalCachePathLong)) { + const QString cachePath = m_parser.value(CommandLineOptions::scLocalCachePathLong); + if (cachePath.isEmpty()) { + errorMessage = QObject::tr("Empty value for option 'cache-path'."); + return false; + } + m_core->settings().setLocalCachePath(cachePath); + } + m_core->resetLocalCache(true); + if (m_parser.isSet(CommandLineOptions::scShowVirtualComponentsLong)) QInstaller::PackageManagerCore::setVirtualComponentsVisible(true); @@ -413,7 +428,7 @@ public: } m_core->setValue(QInstaller::scUILanguage, lang.name()); - emit m_core->defaultTranslationsLoadedForLanguage(lang.language()); + emit m_core->defaultTranslationsLoadedForLanguage(lang); ProductKeyCheck::instance()->addPackagesFromXml(QLatin1String(":/metadata/Updates.xml")); return true; @@ -467,13 +482,39 @@ public: if (magicMarker == QInstaller::BinaryContent::MagicUninstallerMarker) { QFileInfo fi(binaryFile); QString bundlePath; + QString datFileName; if (QInstaller::isInBundle(fi.absoluteFilePath(), &bundlePath)) fi.setFile(bundlePath); #ifdef Q_OS_MACOS - return fi.absoluteDir().filePath(fi.baseName() + QLatin1String(".dat")); + datFileName = fi.absoluteDir().filePath(fi.baseName() + QLatin1String(".dat")); #else - return fi.absoluteDir().filePath(qApp->applicationName() + QLatin1String(".dat")); + datFileName = fi.absoluteDir().filePath(qApp->applicationName() + QLatin1String(".dat")); #endif + // When running maintenance tool, datFile name should be the same as the application name. + // In case we have updated maintenance tool in previous maintenance tool run, the datFile + // name may not match if the maintenance tool name has changed. In that case try to + // look for the dat file from the root folder of the install. + if (!QFileInfo::exists(datFileName)) { + QFileInfo fi(datFileName); + QDirIterator it(fi.absolutePath(), + QStringList() << QLatin1String("*.dat"), + QDir::Files | QDir::NoSymLinks | QDir::NoDotAndDotDot); + while (it.hasNext()) { + try { + QFile f(it.next()); + f.open(QIODevice::ReadOnly); + if (f.fileName().endsWith(QLatin1String("installer.dat"))) + continue; + QInstaller::BinaryContent::findMagicCookie(&f, magicMarker); + datFileName = f.fileName(); + break; + } catch (const QInstaller::Error &error) { + Q_UNUSED(error) + continue; + } + } + } + return datFileName; } return QString(); } @@ -515,7 +556,7 @@ public: foreach (const QString &argument, positionalArguments) { if (argument.contains(QLatin1Char('='))) { const QString name = argument.section(QLatin1Char('='), 0, 0); - const QString value = argument.section(QLatin1Char('='), 1, 1); + const QString value = argument.section(QLatin1Char('='), 1); params.insert(name, value); } } @@ -564,7 +605,7 @@ public: QString controlScript = QString(); if (m_parser.isSet(CommandLineOptions::scScriptLong)) { controlScript = m_parser.value(CommandLineOptions::scScriptLong); - if (!QFileInfo(controlScript).exists()) + if (!QFileInfo::exists(controlScript)) qCDebug(QInstaller::lcInstallerInstallLog) << "Script file does not exist."; } else if (!m_core->settings().controlScript().isEmpty()) { |