summaryrefslogtreecommitdiffstats
path: root/src/sdk/sdkapp.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/sdk/sdkapp.h')
-rw-r--r--src/sdk/sdkapp.h133
1 files changed, 97 insertions, 36 deletions
diff --git a/src/sdk/sdkapp.h b/src/sdk/sdkapp.h
index 7573241cf..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;
@@ -143,28 +147,25 @@ public:
if (m_parser.isSet(CommandLineOptions::scLoggingRulesLong)) {
loggingRules = QLatin1String("ifw.* = false\n");
loggingRules += m_parser.value(CommandLineOptions::scLoggingRulesLong)
- .split(QLatin1Char(','), QString::SkipEmptyParts)
+ .split(QLatin1Char(','), Qt::SkipEmptyParts)
.join(QLatin1Char('\n')); // take rules from command line
} else if (isCommandLineInterface) {
loggingRules = QLatin1String("ifw.* = false\n"
"ifw.installer.* = true\n"
"ifw.server = true\n"
- "ifw.progress.indicator = true\n"
- "ifw.package.* = true\n");
+ "ifw.progress.indicator = true\n");
} else {
// enable all except detailed package information and developer specific logging
loggingRules = QLatin1String("ifw.* = true\n"
- "ifw.developer.build = false\n"
- "ifw.package.* = true\n");
+ "ifw.developer.build = false\n");
}
if (QInstaller::LoggingHandler::instance().verboseLevel() == QInstaller::LoggingHandler::Detailed) {
- loggingRules += QLatin1String("\nifw.developer.build = true\n"
- "ifw.package.* = true\n");
+ loggingRules += QLatin1String("\nifw.developer.build = true\n");
}
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)
@@ -184,18 +185,19 @@ public:
const QHash<QString, QString> userArgs = userArguments();
if (m_parser.isSet(CommandLineOptions::scStartClientLong)) {
const QStringList arguments = m_parser.value(CommandLineOptions::scStartClientLong)
- .split(QLatin1Char(','), QString::SkipEmptyParts);
+ .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);
}
+ QLocale lang = QLocale::English;
#ifndef IFW_DISABLE_TRANSLATIONS
if (!isCommandLineInterface) {
const QString directory = QLatin1String(":/translations");
@@ -205,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)
@@ -215,27 +218,36 @@ 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());
+ if (ifwLoaded) {
+ QCoreApplication::instance()->installTranslator(ifwTranslator.release());
+ } else {
+ qCWarning(QInstaller::lcDeveloperBuild) << "Could not load IFW translation for language"
+ << QLocale::languageToString(locale.language());
+ }
// To stop loading other translations it's sufficient that
// qt was loaded successfully or we hit English as system language
- emit m_core->defaultTranslationsLoadedForLanguage(locale.language());
+ lang = locale;
break;
+ } else {
+ qCWarning(QInstaller::lcDeveloperBuild) << "Could not load Qt translation for language"
+ << QLocale::languageToString(locale.language());
}
}
} 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;
}
}
#endif
@@ -262,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);
@@ -344,6 +366,16 @@ public:
.isSet(CommandLineOptions::scCreateLocalRepositoryLong)
|| m_core->settings().createLocalRepository());
+ if (m_parser.isSet(CommandLineOptions::scMaxConcurrentOperationsLong)) {
+ bool isValid;
+ const int count = m_parser.value(CommandLineOptions::scMaxConcurrentOperationsLong).toInt(&isValid);
+ if (!isValid) {
+ errorMessage = QObject::tr("Invalid value for 'max-concurrent-operations'.");
+ return false;
+ }
+ QInstaller::PackageManagerCore::setMaxConcurrentOperations(count);
+ }
+
if (m_parser.isSet(CommandLineOptions::scAcceptLicensesLong))
m_core->setAutoAcceptLicenses();
@@ -363,7 +395,7 @@ public:
if (m_parser.isSet(CommandLineOptions::scMessageAutomaticAnswerLong)) {
const QString positionalArguments = m_parser.value(CommandLineOptions::scMessageAutomaticAnswerLong);
- const QStringList items = positionalArguments.split(QLatin1Char(','), QString::SkipEmptyParts);
+ const QStringList items = positionalArguments.split(QLatin1Char(','), Qt::SkipEmptyParts);
if (items.count() > 0) {
errorMessage = setMessageBoxAutomaticAnswers(items);
if (!errorMessage.isEmpty())
@@ -376,7 +408,7 @@ public:
}
if (m_parser.isSet(CommandLineOptions::scFileDialogAutomaticAnswer)) {
const QString positionalArguments = m_parser.value(CommandLineOptions::scFileDialogAutomaticAnswer);
- const QStringList items = positionalArguments.split(QLatin1Char(','), QString::SkipEmptyParts);
+ const QStringList items = positionalArguments.split(QLatin1Char(','), Qt::SkipEmptyParts);
foreach (const QString &item, items) {
if (item.contains(QLatin1Char('='))) {
@@ -394,6 +426,9 @@ public:
errorMessage = e.message();
return false;
}
+
+ m_core->setValue(QInstaller::scUILanguage, lang.name());
+ emit m_core->defaultTranslationsLoadedForLanguage(lang);
ProductKeyCheck::instance()->addPackagesFromXml(QLatin1String(":/metadata/Updates.xml"));
return true;
@@ -447,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();
}
@@ -482,7 +543,7 @@ public:
QStringList repositories(const QString &list) const
{
- const QStringList items = list.split(QLatin1Char(','), QString::SkipEmptyParts);
+ const QStringList items = list.split(QLatin1Char(','), Qt::SkipEmptyParts);
foreach (const QString &item, items)
qCDebug(QInstaller::lcInstallerInstallLog) << "Adding custom repository:" << item;
return items;
@@ -495,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);
}
}
@@ -544,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()) {