diff options
36 files changed, 185 insertions, 187 deletions
@@ -1,3 +1,5 @@ +2.1.0 + 2.0.0 - Require Qt 5.4 as a minimal version, Qt 4 code removed. - Only support Qt 5 on documentation side as well. diff --git a/dist/config/config.xml b/dist/config/config.xml index ecf184a11..39ee262bc 100644 --- a/dist/config/config.xml +++ b/dist/config/config.xml @@ -1,7 +1,7 @@ <?xml version="1.0"?> <Installer> <Name>Qt Installer Framework</Name> - <Title>Qt Installer Framework 2.0.0</Title> + <Title>Qt Installer Framework 2.0.81</Title> <Version>1.0.0</Version> <Publisher>Qt Project</Publisher> <ProductUrl>http://qt-project.org</ProductUrl> @@ -9,5 +9,5 @@ <MaintenanceToolName>Uninstaller</MaintenanceToolName> <!-- Tweaked for windows in installscript.qs --> - <TargetDir>@HomeDir@/Qt/QtIFW2.0.0</TargetDir> + <TargetDir>@HomeDir@/Qt/QtIFW-2.0.81</TargetDir> </Installer> diff --git a/dist/packages/org.qtproject.ifw.binaries/meta/package.xml b/dist/packages/org.qtproject.ifw.binaries/meta/package.xml index b953b8a2c..f820372fc 100644 --- a/dist/packages/org.qtproject.ifw.binaries/meta/package.xml +++ b/dist/packages/org.qtproject.ifw.binaries/meta/package.xml @@ -2,7 +2,7 @@ <Package> <DisplayName>Qt Installer Framework Binaries</DisplayName> <Description>Installs the binaries, examples and help files.</Description> - <Version>2.0.0</Version> + <Version>2.0.81</Version> <ReleaseDate>2013-12-12</ReleaseDate> <Default>True</Default> </Package> diff --git a/dist/packages/org.qtproject.ifw/meta/package.xml b/dist/packages/org.qtproject.ifw/meta/package.xml index 18172602e..08eaedc3e 100644 --- a/dist/packages/org.qtproject.ifw/meta/package.xml +++ b/dist/packages/org.qtproject.ifw/meta/package.xml @@ -2,7 +2,7 @@ <Package> <DisplayName>Qt Installer Framework</DisplayName> <Description>Installs the Qt Installer Framework.</Description> - <Version>2.0.0</Version> + <Version>2.0.81</Version> <ReleaseDate>2013-12-12</ReleaseDate> <Licenses> <License name="LGPL 2.1" file="LICENSE.LGPLv21" /> diff --git a/installerfw.pri b/installerfw.pri index 5ba038337..bed0451a9 100644 --- a/installerfw.pri +++ b/installerfw.pri @@ -3,8 +3,8 @@ } IFW_PRI_INCLUDED = 1 -IFW_VERSION_STR = 2.0.0 -IFW_VERSION = 0x020000 +IFW_VERSION_STR = 2.0.81 +IFW_VERSION = 0x020081 IFW_REPOSITORY_FORMAT_VERSION = 1.0.0 IFW_NEWLINE = $$escape_expand(\\n\\t) diff --git a/src/libs/installer/consumeoutputoperation.cpp b/src/libs/installer/consumeoutputoperation.cpp index 00b396ad6..bf9e6c143 100644 --- a/src/libs/installer/consumeoutputoperation.cpp +++ b/src/libs/installer/consumeoutputoperation.cpp @@ -59,13 +59,10 @@ bool ConsumeOutputOperation::performOperation() // 2. executable path // 3. argument for the executable // 4. more arguments possible ... - if (arguments().count() < 3) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.").arg(name()).arg( - arguments().count()).arg(tr("at least 2"), QLatin1String("(<to be saved installer key name>, " - "<executable>, [argument1], [argument2], ...)"))); + + if (!checkArgumentCount(2, INT_MAX, tr("<to be saved installer key name> " + "<executable> [argument1] [argument2] [...]"))) return false; - } PackageManagerCore *const core = value(QLatin1String("installer")).value<PackageManagerCore*>(); if (!core) { diff --git a/src/libs/installer/copydirectoryoperation.cpp b/src/libs/installer/copydirectoryoperation.cpp index cd2b1b341..172cdddba 100644 --- a/src/libs/installer/copydirectoryoperation.cpp +++ b/src/libs/installer/copydirectoryoperation.cpp @@ -63,13 +63,10 @@ void CopyDirectoryOperation::backup() bool CopyDirectoryOperation::performOperation() { - const QStringList args = arguments(); - if (args.count() < 2 || args.count() > 3) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("2 or 3"), tr(" (<source> <target> [forceOverwrite])"))); + if (!checkArgumentCount(2, 3, tr("<source> <target> [\"forceOverwrite\"]"))) return false; - } + + const QStringList args = arguments(); const QString sourcePath = args.at(0); const QString targetPath = args.at(1); bool overwrite = false; diff --git a/src/libs/installer/createdesktopentryoperation.cpp b/src/libs/installer/createdesktopentryoperation.cpp index 11e977d08..8d71c2c07 100644 --- a/src/libs/installer/createdesktopentryoperation.cpp +++ b/src/libs/installer/createdesktopentryoperation.cpp @@ -127,16 +127,11 @@ void CreateDesktopEntryOperation::backup() bool CreateDesktopEntryOperation::performOperation() { - const QStringList args = arguments(); - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 2"), QLatin1String(""))); + if (!checkArgumentCount(2)) return false; - } const QString filename = absoluteFileName(); - const QString &values = args[1]; + const QString &values = arguments().at(1); QFile file(filename); if (file.exists() && !file.remove()) { diff --git a/src/libs/installer/createlinkoperation.cpp b/src/libs/installer/createlinkoperation.cpp index 6117ef602..fc0950870 100644 --- a/src/libs/installer/createlinkoperation.cpp +++ b/src/libs/installer/createlinkoperation.cpp @@ -50,15 +50,10 @@ void CreateLinkOperation::backup() bool CreateLinkOperation::performOperation() { - QStringList args = arguments(); - - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 2"), QLatin1String(""))); + if (!checkArgumentCount(2)) return false; - } + const QStringList args = arguments(); const QString& linkPath = args.at(0); const QString& targetPath = args.at(1); Link link = Link::create(linkPath, targetPath); diff --git a/src/libs/installer/createlocalrepositoryoperation.cpp b/src/libs/installer/createlocalrepositoryoperation.cpp index 55453a916..0904ab8dd 100644 --- a/src/libs/installer/createlocalrepositoryoperation.cpp +++ b/src/libs/installer/createlocalrepositoryoperation.cpp @@ -152,16 +152,12 @@ bool CreateLocalRepositoryOperation::performOperation() AutoHelper helper(this); emit progressChanged(0.0); - const QStringList args = arguments(); - - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 2"), QLatin1String(""))); + if (!checkArgumentCount(2)) return false; - } try { + const QStringList args = arguments(); + const QString binaryPath = QFileInfo(args.at(0)).absoluteFilePath(); // Note the "/" at the end, important to make copy directory operation behave well const QString repoPath = QFileInfo(args.at(1)).absoluteFilePath() + QLatin1Char('/'); diff --git a/src/libs/installer/createshortcutoperation.cpp b/src/libs/installer/createshortcutoperation.cpp index 060672bd8..110698413 100644 --- a/src/libs/installer/createshortcutoperation.cpp +++ b/src/libs/installer/createshortcutoperation.cpp @@ -159,12 +159,15 @@ static bool createLink(const QString &fileName, const QString &linkName, QString // -- CreateShortcutOperation CreateShortcutOperation::CreateShortcutOperation() + : m_optionalArgumentsRead(false) { setName(QLatin1String("CreateShortcut")); } void CreateShortcutOperation::backup() { + ensureOptionalArgumentsRead(); + QDir linkPath(QFileInfo(arguments().at(1)).absolutePath()); QStringList directoriesToCreate; @@ -177,25 +180,36 @@ void CreateShortcutOperation::backup() setValue(QLatin1String("createddirs"), directoriesToCreate); } -bool CreateShortcutOperation::performOperation() +void CreateShortcutOperation::ensureOptionalArgumentsRead() { + if (m_optionalArgumentsRead) + return; + + m_optionalArgumentsRead = true; + QStringList args = arguments(); - const QString iconId = takeArgument(QString::fromLatin1("iconId="), &args); - const QString iconPath = takeArgument(QString::fromLatin1("iconPath="), &args); - const QString workingDir = takeArgument(QString::fromLatin1("workingDirectory="), &args); + m_iconId = takeArgument(QString::fromLatin1("iconId="), &args); + m_iconPath = takeArgument(QString::fromLatin1("iconPath="), &args); + m_workingDir = takeArgument(QString::fromLatin1("workingDirectory="), &args); + + setArguments(args); +} + +bool CreateShortcutOperation::performOperation() +{ + ensureOptionalArgumentsRead(); - if (args.count() != 2 && args.count() != 3) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("2 or 3"), - tr(" (optional: 'workingDirectory=...', 'iconPath=...', 'iconId=...')"))); + if (!checkArgumentCount(2, 3, tr("<target> <link location> [target arguments] " + "[\"workingDirectory=...\"] [\"iconPath=...\"] [\"iconId=...\"]"))) { return false; } + QStringList args = arguments(); + const QString linkTarget = args.at(0); const QString linkLocation = args.at(1); - const QString targetArguments = args.value(2); //used value because it could be not existing + const QString targetArguments = args.value(2); // value() used since it's optional const QString linkPath = QFileInfo(linkLocation).absolutePath().trimmed(); const bool created = QDir(linkPath).exists() || QDir::root().mkpath(linkPath); @@ -224,7 +238,7 @@ bool CreateShortcutOperation::performOperation() return false; } - const bool linked = createLink(linkTarget, linkLocation, workingDir, targetArguments, iconPath, iconId); + const bool linked = createLink(linkTarget, linkLocation, m_workingDir, targetArguments, m_iconPath, m_iconId); if (!linked) { setError(UserDefinedError); setErrorString(tr("Could not create link %1: %2").arg(QDir::toNativeSeparators(linkLocation), @@ -236,6 +250,8 @@ bool CreateShortcutOperation::performOperation() bool CreateShortcutOperation::undoOperation() { + ensureOptionalArgumentsRead(); + const QString &linkLocation = arguments().at(1); if (!deleteFileNowOrLater(linkLocation) ) qDebug() << "Cannot delete:" << linkLocation; diff --git a/src/libs/installer/createshortcutoperation.h b/src/libs/installer/createshortcutoperation.h index 29c9e2574..62ed53a82 100644 --- a/src/libs/installer/createshortcutoperation.h +++ b/src/libs/installer/createshortcutoperation.h @@ -49,6 +49,13 @@ public: bool undoOperation(); bool testOperation(); Operation *clone() const; +private: + void ensureOptionalArgumentsRead(); + + bool m_optionalArgumentsRead; + QString m_iconId; + QString m_iconPath; + QString m_workingDir; }; } diff --git a/src/libs/installer/elevatedexecuteoperation.cpp b/src/libs/installer/elevatedexecuteoperation.cpp index 38aab5d8b..1f439067c 100644 --- a/src/libs/installer/elevatedexecuteoperation.cpp +++ b/src/libs/installer/elevatedexecuteoperation.cpp @@ -80,12 +80,9 @@ bool ElevatedExecuteOperation::performOperation() { // This operation receives only one argument. It is the complete // command line of the external program to execute. - if (arguments().isEmpty()) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("at least 1"), QLatin1String(""))); + if (!checkArgumentCount(1, INT_MAX)) return false; - } + QStringList args; foreach (const QString &argument, arguments()) { if (argument!=QLatin1String("UNDOEXECUTE")) @@ -213,14 +210,14 @@ bool ElevatedExecuteOperation::Private::run(const QStringList &arguments) if (process->exitStatus() == QProcessWrapper::CrashExit) { q->setError(UserDefinedError); - q->setErrorString(tr("Execution failed(Crash): \"%1\"").arg(callstr)); + q->setErrorString(tr("Execution failed (Crash): \"%1\"").arg(callstr)); returnValue = false; } if (!allowedExitCodes.contains(process->exitCode())) { q->setError(UserDefinedError); if (customErrorMessage.isEmpty()) { - q->setErrorString(tr("Execution failed(Unexpected exit code: %1): \"%2\"") + q->setErrorString(tr("Execution failed (Unexpected exit code: %1): \"%2\"") .arg(QString::number(process->exitCode()), callstr)); } else { q->setErrorString(customErrorMessage); diff --git a/src/libs/installer/environmentvariablesoperation.cpp b/src/libs/installer/environmentvariablesoperation.cpp index f41b90893..55332f540 100644 --- a/src/libs/installer/environmentvariablesoperation.cpp +++ b/src/libs/installer/environmentvariablesoperation.cpp @@ -121,21 +121,16 @@ UpdateOperation::Error undoSetting(const QString ®Path, bool EnvironmentVariableOperation::performOperation() { - QStringList args = arguments(); - if (args.count() < 2 || args.count() > 4) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("2 to 4"), QLatin1String(""))); + if (!checkArgumentCount(2, 4)) return false; - } - const QString name = arguments().at(0); - const QString value = arguments().at(1); - bool isPersistent = false; + const QStringList args = arguments(); + const QString name = args.at(0); + const QString value = args.at(1); #ifdef Q_OS_WIN - isPersistent = arguments().count() >= 3 ? arguments().at(2) == QLatin1String("true") : true; - const bool isSystemWide = arguments().count() >= 4 ? arguments().at(3) == QLatin1String("true") : false; + const bool isPersistent = arguments().count() > 2 ? arguments().at(2) == QLatin1String("true") : true; + const bool isSystemWide = arguments().count() > 3 ? arguments().at(3) == QLatin1String("true") : false; QString oldvalue; if (isPersistent) { const QString regPath = isSystemWide ? QLatin1String("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet" @@ -158,9 +153,8 @@ bool EnvironmentVariableOperation::performOperation() setValue(QLatin1String("oldvalue"), oldvalue); return true; } -#endif Q_ASSERT(!isPersistent); - Q_UNUSED(isPersistent) +#endif setValue(QLatin1String("oldvalue"), Environment::instance().value(name)); Environment::instance().setTemporaryValue(name, value); diff --git a/src/libs/installer/extractarchiveoperation.cpp b/src/libs/installer/extractarchiveoperation.cpp index dba695593..d75913d7e 100644 --- a/src/libs/installer/extractarchiveoperation.cpp +++ b/src/libs/installer/extractarchiveoperation.cpp @@ -54,15 +54,11 @@ void ExtractArchiveOperation::backup() bool ExtractArchiveOperation::performOperation() { - const QStringList args = arguments(); - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 2"), QLatin1String(""))); + if (!checkArgumentCount(2)) return false; - } - const QString archivePath = args.first(); + const QStringList args = arguments(); + const QString archivePath = args.at(0); const QString targetDir = args.at(1); Receiver receiver; diff --git a/src/libs/installer/fakestopprocessforupdateoperation.cpp b/src/libs/installer/fakestopprocessforupdateoperation.cpp index d30aa370e..562816bfc 100644 --- a/src/libs/installer/fakestopprocessforupdateoperation.cpp +++ b/src/libs/installer/fakestopprocessforupdateoperation.cpp @@ -57,11 +57,8 @@ bool FakeStopProcessForUpdateOperation::performOperation() bool FakeStopProcessForUpdateOperation::undoOperation() { setError(KDUpdater::UpdateOperation::NoError); - if (arguments().size() != 1) { - setError(KDUpdater::UpdateOperation::InvalidArguments, tr("Number of arguments does not " - "match: one is required")); + if (!checkArgumentCount(1)) return false; - } PackageManagerCore *const core = value(QLatin1String("installer")).value<PackageManagerCore*>(); if (!core) { diff --git a/src/libs/installer/globalsettingsoperation.cpp b/src/libs/installer/globalsettingsoperation.cpp index 3623487a3..f8d5ee439 100644 --- a/src/libs/installer/globalsettingsoperation.cpp +++ b/src/libs/installer/globalsettingsoperation.cpp @@ -105,17 +105,13 @@ Operation *GlobalSettingsOperation::clone() const QSettingsWrapper *GlobalSettingsOperation::setup(QString *key, QString *value, const QStringList &arguments) { - if (arguments.count() != 3 && arguments.count() != 4 && arguments.count() != 5) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments.count()).arg(tr("3, 4 or 5"), QLatin1String(""))); + if (!checkArgumentCount(3, 5)) return 0; - } if (arguments.count() == 5) { QSettingsWrapper::Scope scope = QSettingsWrapper::UserScope; if (arguments.at(0) == QLatin1String("SystemScope")) - scope = QSettingsWrapper::SystemScope; + scope = QSettingsWrapper::SystemScope; const QString &company = arguments.at(1); const QString &application = arguments.at(2); *key = arguments.at(3); diff --git a/src/libs/installer/installiconsoperation.cpp b/src/libs/installer/installiconsoperation.cpp index f957623bb..f9a9096f5 100644 --- a/src/libs/installer/installiconsoperation.cpp +++ b/src/libs/installer/installiconsoperation.cpp @@ -109,16 +109,12 @@ void InstallIconsOperation::backup() bool InstallIconsOperation::performOperation() { - const QStringList args = arguments(); - if ((args.count() != 1) && (args.count() != 2)) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("1 or 2"), tr(" (Sourcepath, [Vendorprefix])"))); + if (!checkArgumentCount(1, 2, tr("<source path> [vendor prefix]"))) return false; - } + const QStringList args = arguments(); const QString source = args.at(0); - const QString vendor = args.value(1); + const QString vendor = args.value(1); // value() used since it's optional if (source.isEmpty()) { setError(InvalidArguments); diff --git a/src/libs/installer/lib7z_facade.cpp b/src/libs/installer/lib7z_facade.cpp index a2811c19e..900b09e65 100644 --- a/src/libs/installer/lib7z_facade.cpp +++ b/src/libs/installer/lib7z_facade.cpp @@ -842,7 +842,7 @@ public: // do not follow symlinks, so we need to remove an existing one if (fi.isSymLink() && (!QFile::remove(fi.absoluteFilePath()))) { Lib7z::setLastError(QCoreApplication::translate("ExtractCallbackImpl", - "Could not remove already existing symlink. %1").arg(fi.absoluteFilePath())); + "Could not remove already existing symlink %1.").arg(fi.absoluteFilePath())); return E_FAIL; } #endif @@ -850,7 +850,7 @@ public: new QFile(fi.absoluteFilePath()), QIODeviceSequentialOutStream::CloseAndDeleteDevice); if (!qOutStream->errorString().isEmpty()) { Lib7z::setLastError(QCoreApplication::translate("ExtractCallbackImpl", - "Could not open file: %1 (%2)").arg(fi.absoluteFilePath(), + "Could not open file %1: %2.").arg(fi.absoluteFilePath(), qOutStream->errorString())); return E_FAIL; } @@ -882,7 +882,7 @@ public: UString s; if (arc->GetItemPath(currentIndex, s) != S_OK) { Lib7z::setLastError(QCoreApplication::translate("ExtractCallbackImpl", - "Could not retrieve path of archive item %1").arg(currentIndex)); + "Could not retrieve path of archive item %1.").arg(currentIndex)); return E_FAIL; } const QString path = UString2QString(s).replace(QLatin1Char('\\'), QLatin1Char('/')); @@ -922,7 +922,7 @@ public: QFile targetFile(QString::fromLatin1(symlinkTarget)); if (!targetFile.link(absFilePath)) { Lib7z::setLastError(QCoreApplication::translate("ExtractCallbackImpl", - "Could not create symlink at %1. %2").arg(absFilePath, + "Could not create symlink at %1: %2.").arg(absFilePath, targetFile.errorString())); return E_FAIL; } diff --git a/src/libs/installer/linereplaceoperation.cpp b/src/libs/installer/linereplaceoperation.cpp index 9063f8848..c84d1922c 100644 --- a/src/libs/installer/linereplaceoperation.cpp +++ b/src/libs/installer/linereplaceoperation.cpp @@ -51,18 +51,14 @@ void LineReplaceOperation::backup() bool LineReplaceOperation::performOperation() { - const QStringList args = arguments(); - // Arguments: // 1. filename // 2. startsWith Search-String // 3. Replace-Line-String - if (args.count() != 3) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 3"), QLatin1String(""))); + if (!checkArgumentCount(3)) return false; - } + + const QStringList args = arguments(); const QString fileName = args.at(0); const QString searchString = args.at(1); const QString replaceString = args.at(2); diff --git a/src/libs/installer/metadatajob.cpp b/src/libs/installer/metadatajob.cpp index ec0784758..41c0265bc 100644 --- a/src/libs/installer/metadatajob.cpp +++ b/src/libs/installer/metadatajob.cpp @@ -78,7 +78,7 @@ void MetadataJob::doStart() emit infoMessage(this, tr("Preparing meta information download...")); const bool onlineInstaller = m_core->isInstaller() && !m_core->isOfflineOnly(); - if (onlineInstaller || (m_core->isUpdater() || m_core->isPackageManager())) { + if (onlineInstaller || m_core->isMaintainer()) { QList<FileTaskItem> items; const ProductKeyCheck *const productKeyCheck = ProductKeyCheck::instance(); foreach (const Repository &repo, m_core->settings().repositories()) { @@ -158,7 +158,7 @@ void MetadataJob::xmlTaskFinished() if (s.updateDefaultRepositories(update) == Settings::UpdatesApplied || s.updateUserRepositories(update) == Settings::UpdatesApplied) { - if (m_core->isUpdater() || m_core->isPackageManager()) + if (m_core->isMaintainer()) m_core->writeMaintenanceConfigFiles(); } } @@ -438,7 +438,7 @@ MetadataJob::Status MetadataJob::parseUpdatesXml(const QList<FileTaskResult> &re return XmlDownloadRetry; } } else if (s.updateDefaultRepositories(repositoryUpdates) == Settings::UpdatesApplied) { - if (m_core->isUpdater() || m_core->isPackageManager()) + if (m_core->isMaintainer()) m_core->writeMaintenanceConfigFiles(); QFile::remove(result.target()); return XmlDownloadRetry; diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 58af91b9a..45bb9baf8 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -897,7 +897,7 @@ void PackageManagerCore::networkSettingsChanged() d->m_repoFetched = false; d->m_updateSourcesAdded = false; - if (d->isUpdater() || d->isPackageManager()) + if (isMaintainer()) d->writeMaintenanceConfigFiles(); KDUpdater::FileDownloaderFactory::instance().setProxyFactory(proxyFactory()); @@ -2078,6 +2078,14 @@ bool PackageManagerCore::isPackageManager() const } /*! + Returns \c true if it is a package manager or an updater. +*/ +bool PackageManagerCore::isMaintainer() const +{ + return isPackageManager() || isUpdater(); +} + +/*! \qmlmethod boolean installer::runInstaller() Runs the installer. Returns \c true on success, \c false otherwise. @@ -2128,7 +2136,7 @@ bool PackageManagerCore::run() return d->runInstaller(); else if (isUninstaller()) return d->runUninstaller(); - else if (isPackageManager() || isUpdater()) + else if (isMaintainer()) return d->runPackageUpdater(); return false; } diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h index 5b2cbdfa7..04bee2f71 100644 --- a/src/libs/installer/packagemanagercore.h +++ b/src/libs/installer/packagemanagercore.h @@ -230,6 +230,8 @@ public: Q_INVOKABLE void setPackageManager(); Q_INVOKABLE bool isPackageManager() const; + bool isMaintainer() const; + bool isVerbose() const; void setVerbose(bool on); diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index ebaf4d92c..c4210644c 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -412,7 +412,7 @@ bool PackageManagerCorePrivate::buildComponentTree(QHash<QString, Component*> &c void PackageManagerCorePrivate::cleanUpComponentEnvironment() { // clean up registered (downloaded) data - if (m_core->isUpdater() || m_core->isPackageManager()) + if (m_core->isMaintainer()) BinaryFormatEngineHandler::instance()->clear(); // there could be still some references to already deleted components, diff --git a/src/libs/installer/packagemanagergui.cpp b/src/libs/installer/packagemanagergui.cpp index 8e1712617..c19bd3936 100644 --- a/src/libs/installer/packagemanagergui.cpp +++ b/src/libs/installer/packagemanagergui.cpp @@ -734,7 +734,7 @@ void PackageManagerGui::cancelButtonClicked() question = tr("Do you want to quit the installer application?"); if (m_core->isUninstaller()) question = tr("Do you want to quit the uninstaller application?"); - if (m_core->isUpdater() || m_core->isPackageManager()) + if (m_core->isMaintainer()) question = tr("Do you want to quit the maintenance application?"); } @@ -1142,7 +1142,7 @@ int PackageManagerPage::nextId() const core->calculateComponentsToInstall(); foreach (Component* component, core->orderedComponentsToInstall()) { - if ((core->isPackageManager() || core->isUpdater()) && component->isInstalled()) + if (core->isMaintainer() && component->isInstalled()) continue; // package manager or updater, hide as long as the component is installed // The component is about to be installed and provides a license, so the page needs to @@ -1265,7 +1265,7 @@ int IntroductionPage::nextId() const if (packageManagerCore()->isUninstaller()) return PackageManagerCore::ReadyForInstallation; - if (packageManagerCore()->isUpdater() || packageManagerCore()->isPackageManager()) + if (packageManagerCore()->isMaintainer()) return PackageManagerCore::ComponentSelection; return PackageManagerPage::nextId(); @@ -1290,8 +1290,7 @@ bool IntroductionPage::validatePage() } gui()->setSettingsButtonEnabled(false); - const bool maintenance = core->isUpdater() || core->isPackageManager(); - if (maintenance) { + if (core->isMaintainer()) { showAll(); setMaintenanceToolsEnabled(false); } else { @@ -1350,7 +1349,7 @@ bool IntroductionPage::validatePage() setComplete(true); } - if (maintenance) { + if (core->isMaintainer()) { showMaintenanceTools(); setMaintenanceToolsEnabled(true); } else { @@ -1529,7 +1528,7 @@ void IntroductionPage::entering() m_progressBar->setValue(0); m_progressBar->setRange(0, 0); PackageManagerCore *core = packageManagerCore(); - if (core->isUninstaller() || core->isUpdater() || core->isPackageManager()) { + if (core->isUninstaller() || core->isMaintainer()) { showMaintenanceTools(); setMaintenanceToolsEnabled(true); } @@ -2552,7 +2551,7 @@ void ReadyForInstallationPage::entering() .absolutePath()))); setComplete(true); return; - } else if (packageManagerCore()->isPackageManager() || packageManagerCore()->isUpdater()) { + } else if (packageManagerCore()->isMaintainer()) { setButtonText(QWizard::CommitButton, tr("U&pdate")); setColoredTitle(tr("Ready to Update Packages")); m_msgLabel->setText(tr("Setup is now ready to begin updating your installation.")); @@ -2807,7 +2806,7 @@ void PerformInstallationPage::entering() setColoredTitle(tr("Uninstalling %1").arg(productName())); QTimer::singleShot(30, packageManagerCore(), SLOT(runUninstaller())); - } else if (packageManagerCore()->isPackageManager() || packageManagerCore()->isUpdater()) { + } else if (packageManagerCore()->isMaintainer()) { setButtonText(QWizard::CommitButton, tr("&Update")); setColoredTitle(tr("Updating components of %1").arg(productName())); @@ -2937,7 +2936,7 @@ void FinishedPage::entering() m_commitButton = 0; } - if (packageManagerCore()->isUpdater() || packageManagerCore()->isPackageManager()) { + if (packageManagerCore()->isMaintainer()) { #ifdef Q_OS_OSX gui()->setOption(QWizard::NoCancelButton, false); #endif diff --git a/src/libs/installer/replaceoperation.cpp b/src/libs/installer/replaceoperation.cpp index c2aec65a8..98a0e7bc9 100644 --- a/src/libs/installer/replaceoperation.cpp +++ b/src/libs/installer/replaceoperation.cpp @@ -51,18 +51,14 @@ void ReplaceOperation::backup() bool ReplaceOperation::performOperation() { - const QStringList args = arguments(); - // Arguments: // 1. filename // 2. Source-String // 3. Replace-String - if (args.count() != 3) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 3"), QLatin1String(""))); + if (!checkArgumentCount(3)) return false; - } + + const QStringList args = arguments(); const QString fileName = args.at(0); const QString before = args.at(1); const QString after = args.at(2); diff --git a/src/libs/installer/selfrestartoperation.cpp b/src/libs/installer/selfrestartoperation.cpp index 491503e92..8b1f6b0e8 100644 --- a/src/libs/installer/selfrestartoperation.cpp +++ b/src/libs/installer/selfrestartoperation.cpp @@ -58,7 +58,7 @@ bool SelfRestartOperation::performOperation() return false; } - if (!core->isUpdater() && !core->isPackageManager()) { + if (!core->isMaintainer()) { setError(UserDefinedError); setErrorString(tr("Self Restart: Only valid within updater or packagemanager mode.")); return false; diff --git a/src/libs/installer/simplemovefileoperation.cpp b/src/libs/installer/simplemovefileoperation.cpp index 5edb392e1..54a5583ee 100644 --- a/src/libs/installer/simplemovefileoperation.cpp +++ b/src/libs/installer/simplemovefileoperation.cpp @@ -49,14 +49,10 @@ void SimpleMoveFileOperation::backup() bool SimpleMoveFileOperation::performOperation() { - const QStringList args = arguments(); - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 2"), QLatin1String(""))); + if (!checkArgumentCount(2)) return false; - } + const QStringList args = arguments(); const QString source = args.at(0); const QString target = args.at(1); diff --git a/src/libs/kdtools/kdupdaterupdateoperation.cpp b/src/libs/kdtools/kdupdaterupdateoperation.cpp index 8b6cbec64..05c0995ac 100644 --- a/src/libs/kdtools/kdupdaterupdateoperation.cpp +++ b/src/libs/kdtools/kdupdaterupdateoperation.cpp @@ -180,6 +180,42 @@ QStringList UpdateOperation::arguments() const return m_arguments; } +bool UpdateOperation::checkArgumentCount(int minArgCount, int maxArgCount, + const QString &argDescription) +{ + const int argCount = arguments().count(); + if (argCount < minArgCount || argCount > maxArgCount) { + setError(InvalidArguments); + QString countRange; + if (minArgCount == maxArgCount) + countRange = tr("exactly %1").arg(minArgCount); + else if (maxArgCount == INT_MAX) + countRange = tr("at least %1").arg(minArgCount); + else if (minArgCount == 0) + countRange = tr("not more than %1").arg(maxArgCount); + else if (minArgCount == maxArgCount - 1) + countRange = tr("%1 or %2").arg(minArgCount).arg(maxArgCount); + else + countRange = tr("%1 to %2").arg(minArgCount).arg(maxArgCount); + + if (argDescription.isEmpty()) + setErrorString(tr("Invalid arguments in %1: %n arguments given, " + "%2 arguments expected.", 0, argCount) + .arg(name(), countRange)); + else + setErrorString(tr("Invalid arguments in %1: %n arguments given, " + "%2 arguments expected in the form: %3.", 0, argCount) + .arg(name(), countRange, argDescription)); + return false; + } + return true; +} + +bool UpdateOperation::checkArgumentCount(int argCount) +{ + return checkArgumentCount(argCount, argCount); +} + struct StartsWith { StartsWith(const QString &searchTerm) diff --git a/src/libs/kdtools/kdupdaterupdateoperation.h b/src/libs/kdtools/kdupdaterupdateoperation.h index d841fb564..7707a2d62 100644 --- a/src/libs/kdtools/kdupdaterupdateoperation.h +++ b/src/libs/kdtools/kdupdaterupdateoperation.h @@ -90,6 +90,8 @@ protected: void setError(int error, const QString &errorString = QString()); void registerForDelayedDeletion(const QStringList &files); bool deleteFileNowOrLater(const QString &file, QString *errorString = 0); + bool checkArgumentCount(int minArgCount, int maxArgCount, const QString &argDescription = QString()); + bool checkArgumentCount(int argCount); private: QString m_name; diff --git a/src/libs/kdtools/kdupdaterupdateoperations.cpp b/src/libs/kdtools/kdupdaterupdateoperations.cpp index 31d9d1f44..90dbc7d60 100644 --- a/src/libs/kdtools/kdupdaterupdateoperations.cpp +++ b/src/libs/kdtools/kdupdaterupdateoperations.cpp @@ -146,11 +146,8 @@ bool CopyOperation::performOperation() { // We need two args to complete the copy operation. First arg provides the complete file name of source // Second arg provides the complete file name of dest - if (arguments().count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(arguments().count())); + if (!checkArgumentCount(2)) return false; - } QString source = sourcePath(); QString destination = destinationPath(); @@ -273,14 +270,11 @@ bool MoveOperation::performOperation() { // We need two args to complete the copy operation. // First arg provides the complete file name of // source, second arg provides the complete file name of dest - const QStringList args = this->arguments(); - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count())); + if (!checkArgumentCount(2)) return false; - } - const QString dest = args.last(); + const QStringList args = arguments(); + const QString dest = args.at(1); // If destination file exists, then we cannot use QFile::copy() because it does not overwrite an existing // file. So we remove the destination file. if (QFile::exists(dest)) { @@ -293,7 +287,7 @@ bool MoveOperation::performOperation() } // Copy source to destination. - QFile file(args.first()); + QFile file(args.at(0)); if (!file.copy(dest)) { setError(UserDefinedError); setErrorString(tr("Could not copy %1 to %2: %3").arg(file.fileName(), dest, file.errorString())); @@ -372,13 +366,10 @@ void DeleteOperation::backup() bool DeleteOperation::performOperation() { // Requires only one parameter. That is the name of the file to remove. - const QStringList args = this->arguments(); - if (args.count() != 1) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count())); + if (!checkArgumentCount(1)) return false; - } - return deleteFileNowOrLater(args.first()); + + return deleteFileNowOrLater(arguments().at(0)); } bool DeleteOperation::undoOperation() @@ -459,14 +450,10 @@ void MkdirOperation::backup() bool MkdirOperation::performOperation() { // Requires only one parameter. That is the path which should be created - QStringList args = this->arguments(); - if (args.count() != 1) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count())); + if (!checkArgumentCount(1)) return false; - } - const QString dirName = args.first(); + const QString dirName = arguments().at(0); const bool created = QDir::root().mkpath(dirName); if (!created) { setError(UserDefinedError); @@ -538,26 +525,23 @@ void RmdirOperation::backup() bool RmdirOperation::performOperation() { // Requires only one parameter. That is the name of the file to remove. - const QStringList args = this->arguments(); - if (args.count() != 1) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count())); + if (!checkArgumentCount(1)) return false; - } - QDir dir(args.first()); + const QString firstArg = arguments().at(0); + QDir dir(firstArg); if (!dir.exists()) { setError(UserDefinedError); - setErrorString(tr("Could not remove folder %1: The folder does not exist.").arg(args.first())); + setErrorString(tr("Could not remove folder %1: The folder does not exist.").arg(firstArg)); return false; } errno = 0; - const bool removed = dir.rmdir(args.first()); + const bool removed = dir.rmdir(firstArg); setValue(QLatin1String("removed"), removed); if (!removed) { setError(UserDefinedError); - setErrorString(tr("Could not remove folder %1: %2").arg(args.first(), errnoToQString(errno))); + setErrorString(tr("Could not remove folder %1: %2").arg(firstArg, errnoToQString(errno))); } return removed; } @@ -616,15 +600,11 @@ bool AppendFileOperation::performOperation() { // This operation takes two arguments. First argument is the name of the file into which a text has to be // appended. Second argument is the text to append. - const QStringList args = this->arguments(); - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments in %0: %1 arguments given, %2 expected%3.") - .arg(name()).arg(arguments().count()).arg(tr("exactly 2"), QLatin1String(""))); + if (!checkArgumentCount(2)) return false; - } - const QString fName = args.first(); + const QStringList args = this->arguments(); + const QString fName = args.at(0); QFile file(fName); if (!file.open(QFile::Append)) { // first we rename the file, then we copy it to the real target and open the copy - the renamed original is then marked for deletion @@ -653,7 +633,7 @@ bool AppendFileOperation::performOperation() } QTextStream ts(&file); - ts << args.last(); + ts << args.at(1); file.close(); return true; @@ -727,14 +707,11 @@ bool PrependFileOperation::performOperation() // This operation takes two arguments. First argument is the name // of the file into which a text has to be appended. Second argument // is the text to append. - const QStringList args = this->arguments(); - if (args.count() != 2) { - setError(InvalidArguments); - setErrorString(tr("Invalid arguments: %1 arguments given, 2 expected.").arg(args.count())); + if (!checkArgumentCount(2)) return false; - } - const QString fName = args.first(); + const QStringList args = this->arguments(); + const QString fName = args.at(0); // Load the file first. QFile file(fName); if (!file.open(QFile::ReadOnly)) { @@ -748,7 +725,7 @@ bool PrependFileOperation::performOperation() file.close(); // Prepend text to the file text - fContents = args.last() + fContents; + fContents = args.at(1) + fContents; // Now re-open the file in write only mode. if (!file.open(QFile::WriteOnly)) { diff --git a/tests/auto/installer/consumeoutputoperationtest/tst_consumeoutputoperationtest.cpp b/tests/auto/installer/consumeoutputoperationtest/tst_consumeoutputoperationtest.cpp index f2e05979d..868865b5d 100644 --- a/tests/auto/installer/consumeoutputoperationtest/tst_consumeoutputoperationtest.cpp +++ b/tests/auto/installer/consumeoutputoperationtest/tst_consumeoutputoperationtest.cpp @@ -79,7 +79,8 @@ private slots: QCOMPARE(UpdateOperation::Error(operation.error()), UpdateOperation::InvalidArguments); //qDebug() << operation.errorString(); QString compareString("Invalid arguments in ConsumeOutput: 0 arguments given, at least 2 " - "expected(<to be saved installer key name>, <executable>, [argument1], [argument2], ...)."); + "arguments expected in the form: <to be saved installer key name> " + "<executable> [argument1] [argument2] [...]."); //qDebug() << compareString; QCOMPARE(operation.errorString(), compareString); } diff --git a/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp b/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp index f528b5f39..da26daf2c 100644 --- a/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp +++ b/tests/auto/installer/copyoperationtest/tst_copyoperationtest.cpp @@ -69,7 +69,8 @@ private slots: QVERIFY(!op.performOperation()); QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments); - QCOMPARE(op.errorString(), QString("Invalid arguments: 0 arguments given, 2 expected.")); + QCOMPARE(op.errorString(), QString("Invalid arguments in Copy: " + "0 arguments given, exactly 2 arguments expected.")); } diff --git a/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp index e101b96e5..b87cea791 100644 --- a/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp +++ b/tests/auto/installer/extractarchiveoperationtest/tst_extractarchiveoperationtest.cpp @@ -61,7 +61,8 @@ private slots: //QVERIFY(!op.undoOperation()); Can't test for failure as we run into Q_ASSERT QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments); - QCOMPARE(op.errorString(), QString("Invalid arguments in Extract: 0 arguments given, exactly 2 expected.")); + QCOMPARE(op.errorString(), QString("Invalid arguments in Extract: " + "0 arguments given, exactly 2 arguments expected.")); } diff --git a/tests/auto/installer/fakestopprocessforupdateoperation/tst_fakestopprocessforupdateoperation.cpp b/tests/auto/installer/fakestopprocessforupdateoperation/tst_fakestopprocessforupdateoperation.cpp index c8b314657..58624d24b 100644 --- a/tests/auto/installer/fakestopprocessforupdateoperation/tst_fakestopprocessforupdateoperation.cpp +++ b/tests/auto/installer/fakestopprocessforupdateoperation/tst_fakestopprocessforupdateoperation.cpp @@ -23,7 +23,8 @@ private slots: QVERIFY(!op.undoOperation()); QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments); - QCOMPARE(op.errorString(), QString("Number of arguments does not match: one is required")); + QCOMPARE(op.errorString(), QString("Invalid arguments in FakeStopProcessForUpdate: " + "0 arguments given, exactly 1 arguments expected.")); } void testMissingPackageManagerCore() diff --git a/tests/auto/installer/mkdiroperationtest/tst_mkdiroperationtest.cpp b/tests/auto/installer/mkdiroperationtest/tst_mkdiroperationtest.cpp index 8267c9de0..f7922e62d 100644 --- a/tests/auto/installer/mkdiroperationtest/tst_mkdiroperationtest.cpp +++ b/tests/auto/installer/mkdiroperationtest/tst_mkdiroperationtest.cpp @@ -66,7 +66,8 @@ private slots: QVERIFY(!op.performOperation()); QCOMPARE(UpdateOperation::Error(op.error()), UpdateOperation::InvalidArguments); - QCOMPARE(op.errorString(), QString("Invalid arguments: 0 arguments given, 1 expected.")); + QCOMPARE(op.errorString(), QString("Invalid arguments in Mkdir: " + "0 arguments given, exactly 1 arguments expected.")); } |