summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2019-10-21 12:31:04 +0300
committerKatja Marttila <katja.marttila@qt.io>2019-11-19 09:37:39 +0000
commit3bd4e7d632967b1bf77120918700c11f83318166 (patch)
treec6ad1d18b60ff27e0fb64c507852aca039cdbe97
parent9ce679325c244859c7e50ed3cca304c1e0f2b698 (diff)
Refactor code to functions which command line interface needs
These are needed in multiple places while implementing CLI so created common functions to avoid code repeat. Change-Id: I2b30bedf5de838211f48bd1669c59ff3a17f640e Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
-rw-r--r--src/libs/installer/globals.cpp9
-rw-r--r--src/libs/installer/globals.h2
-rw-r--r--src/libs/installer/packagemanagercore.cpp10
-rw-r--r--src/libs/installer/packagemanagercore_p.cpp28
-rw-r--r--src/libs/installer/packagemanagercore_p.h3
-rw-r--r--src/sdk/installerbase.cpp18
-rw-r--r--src/sdk/installerbase.h1
7 files changed, 55 insertions, 16 deletions
diff --git a/src/libs/installer/globals.cpp b/src/libs/installer/globals.cpp
index c059b6630..48195f0dd 100644
--- a/src/libs/installer/globals.cpp
+++ b/src/libs/installer/globals.cpp
@@ -25,6 +25,8 @@
** $QT_END_LICENSE$
**
**************************************************************************/
+#include <QTextDocument>
+
#include "globals.h"
const char IFW_COMPONENT_CHECKER[] = "ifw.componentChecker";
@@ -56,5 +58,12 @@ QRegExp commaRegExp()
return *staticCommaRegExp();
}
+QString htmlToString(const QString &html)
+{
+ QTextDocument doc;
+ doc.setHtml(html);
+ return doc.toPlainText();
+}
+
} // namespace QInstaller
diff --git a/src/libs/installer/globals.h b/src/libs/installer/globals.h
index a5bd47ac8..b92dfd1bb 100644
--- a/src/libs/installer/globals.h
+++ b/src/libs/installer/globals.h
@@ -44,6 +44,8 @@ QStringList INSTALLER_EXPORT loggingCategories();
QRegExp INSTALLER_EXPORT commaRegExp();
+QString htmlToString(const QString &html);
+
} // QInstaller
#endif // GLOBALS_H
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp
index 6c30208db..2be6eaeb0 100644
--- a/src/libs/installer/packagemanagercore.cpp
+++ b/src/libs/installer/packagemanagercore.cpp
@@ -1837,16 +1837,8 @@ void PackageManagerCore::listInstalledPackages()
void PackageManagerCore::updateComponentsSilently()
{
- //Check if there are processes running in the install
- QStringList excludeFiles;
- excludeFiles.append(maintenanceToolName());
-
- QStringList runningProcesses = d->runningInstallerProcesses(excludeFiles);
- if (!runningProcesses.isEmpty()) {
- qDebug() << "Unable to update components. Please stop these processes: "
- << runningProcesses << " and try again.";
+ if (d->runningProcessesFound())
return;
- }
autoAcceptMessageBoxes();
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp
index 308bfa097..f33d03bec 100644
--- a/src/libs/installer/packagemanagercore_p.cpp
+++ b/src/libs/installer/packagemanagercore_p.cpp
@@ -1981,6 +1981,20 @@ void PackageManagerCorePrivate::installComponent(Component *component, double pr
ProgressCoordinator::instance()->emitDetailTextChanged(tr("Done"));
}
+bool PackageManagerCorePrivate::runningProcessesFound()
+{
+ //Check if there are processes running in the install
+ QStringList excludeFiles;
+ excludeFiles.append(maintenanceToolName());
+ QStringList runningProcesses = runningInstallerProcesses(excludeFiles);
+ if (!runningProcesses.isEmpty()) {
+ qDebug() << "Unable to update components. Please stop these processes: "
+ << runningProcesses << " and try again.";
+ return true;
+ }
+ return false;
+}
+
// -- private
void PackageManagerCorePrivate::deleteMaintenanceTool()
@@ -2498,5 +2512,19 @@ QStringList PackageManagerCorePrivate::runningInstallerProcesses(const QStringLi
return checkRunningProcessesFromList(resultFiles);
}
+bool PackageManagerCorePrivate::calculateComponentsAndRun()
+{
+ QString htmlOutput;
+ bool componentsOk = m_core->calculateComponents(&htmlOutput);
+ qDebug().noquote() << htmlToString(htmlOutput);
+ if (componentsOk) {
+ if (m_core->run()) {
+ m_core->writeMaintenanceTool();
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace QInstaller
diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h
index 3e8f831a3..c7b657eb8 100644
--- a/src/libs/installer/packagemanagercore_p.h
+++ b/src/libs/installer/packagemanagercore_p.h
@@ -165,6 +165,8 @@ public:
void installComponent(Component *component, double progressOperationSize,
bool adminRightsGained = false);
+ bool runningProcessesFound();
+
signals:
void installationStarted();
void installationFinished();
@@ -239,6 +241,7 @@ private:
void processFilesForDelayedDeletion();
void findExecutablesRecursive(const QString &path, const QStringList &excludeFiles, QStringList *result);
QStringList runningInstallerProcesses(const QStringList &exludeFiles);
+ bool calculateComponentsAndRun();
private:
PackageManagerCore *m_core;
diff --git a/src/sdk/installerbase.cpp b/src/sdk/installerbase.cpp
index 5c8478036..918a846fc 100644
--- a/src/sdk/installerbase.cpp
+++ b/src/sdk/installerbase.cpp
@@ -296,19 +296,14 @@ int InstallerBase::run()
if (parser.isSet(QLatin1String(CommandLineOptions::SilentUpdate))) {
if (m_core->isInstaller())
throw QInstaller::Error(QLatin1String("Cannot start installer binary as updater."));
- const ProductKeyCheck *const productKeyCheck = ProductKeyCheck::instance();
- if (!productKeyCheck->hasValidLicense())
- throw QInstaller::Error(QLatin1String("Silent update not allowed."));
+ checkLicense();
m_core->setUpdater();
m_core->updateComponentsSilently();
} else if (parser.isSet(QLatin1String(CommandLineOptions::ListInstalledPackages))){
if (m_core->isInstaller())
throw QInstaller::Error(QLatin1String("Cannot start installer binary as package manager."));
+ checkLicense();
m_core->setPackageManager();
-
- const ProductKeyCheck *const productKeyCheck = ProductKeyCheck::instance();
- if (!productKeyCheck->hasValidLicense())
- throw QInstaller::Error(QLatin1String("No valid license found."));
m_core->listInstalledPackages();
} else {
//create the wizard GUI
@@ -384,3 +379,12 @@ QStringList InstallerBase::repositories(const QString &list) const
qDebug().noquote() << "Adding custom repository:" << item;
return items;
}
+
+void InstallerBase::checkLicense()
+{
+ const ProductKeyCheck *const productKeyCheck = ProductKeyCheck::instance();
+ if (!productKeyCheck->hasValidLicense()) {
+ qDebug() << "No valid license found.";
+ throw QInstaller::Error(QLatin1String("No valid license found."));
+ }
+}
diff --git a/src/sdk/installerbase.h b/src/sdk/installerbase.h
index 677f567ee..3f51331cd 100644
--- a/src/sdk/installerbase.h
+++ b/src/sdk/installerbase.h
@@ -49,6 +49,7 @@ public:
private:
void dumpResourceTree() const;
QStringList repositories(const QString &list) const;
+ void checkLicense();
private:
QInstaller::PackageManagerCore *m_core;