QtAutoUpdater  3.0.0
A Qt library to automatically check for updates and install them
processbackend.h
1 #ifndef QTAUTOUPDATER_PROCESSBACKEND_H
2 #define QTAUTOUPDATER_PROCESSBACKEND_H
3 
4 #include <QtCore/qglobal.h>
5 
6 #if QT_CONFIG(process)
7 
8 #include <optional>
9 
10 #include <QtCore/QProcess>
11 
12 #include "QtAutoUpdaterCore/qtautoupdatercore_global.h"
13 #include "QtAutoUpdaterCore/updaterbackend.h"
14 
15 namespace QtAutoUpdater {
16 
17 class ProcessBackendPrivate;
19 class Q_AUTOUPDATERCORE_EXPORT ProcessBackend : public UpdaterBackend
20 {
21  Q_OBJECT
22 
23 public:
24  void abort(bool force) override;
25  bool triggerUpdates(const QList<QtAutoUpdater::UpdateInfo> &infos, bool track) override;
26 
28  static QStringList readPathList(const QVariant &value);
30  static QStringList readArgumentList(const QVariant &value);
31 
32 protected:
34  struct Q_AUTOUPDATERCORE_EXPORT ProcessInfoBase {
37  std::optional<QString> workingDir = std::nullopt;
38  };
39 
41  struct Q_AUTOUPDATERCORE_EXPORT UpdateProcessInfo : public ProcessInfoBase {
42  bool useStdout = true;
43  bool useStderr = false;
44  std::optional<QByteArray> stdinData;
45  };
46 
48  struct Q_AUTOUPDATERCORE_EXPORT InstallProcessInfo : public ProcessInfoBase {
49  std::optional<bool> runAsAdmin = std::nullopt;
50  };
51 
53  explicit ProcessBackend(QString &&key, QObject *parent = nullptr);
55  explicit ProcessBackend(ProcessBackendPrivate &dd, QObject *parent = nullptr);
56 
58  void runUpdateTool(int id, UpdateProcessInfo toolInfo);
60  void cancelUpdateTool(int id, bool kill = false);
62  virtual void onToolDone(int id, int exitCode, QIODevice *processDevice) = 0;
64  virtual std::optional<InstallProcessInfo> installerInfo(const QList<QtAutoUpdater::UpdateInfo> &infos, bool track) = 0;
65 
66 private:
67  Q_DECLARE_PRIVATE(ProcessBackend)
68 
69  Q_PRIVATE_SLOT(d_func(), void _q_updaterStateChanged(int, QProcess::ProcessState state))
70  Q_PRIVATE_SLOT(d_func(), void _q_installerStateChanged(QProcess::ProcessState state))
71 };
72 
73 }
74 
75 #endif
76 
77 #endif // QTAUTOUPDATER_PROCESSBACKEND_H
QtAutoUpdater::ProcessBackend::ProcessInfoBase::program
QString program
The path or name of the executable.
Definition: processbackend.h:35
QIODevice
QtAutoUpdater::ProcessBackend::ProcessInfoBase::arguments
QStringList arguments
The arguments that should be passed to the process.
Definition: processbackend.h:36
QList< QtAutoUpdater::UpdateInfo >
QString
QtAutoUpdater::ProcessBackend::ProcessInfoBase
Structure that collects information about a process to be started.
Definition: processbackend.h:34
QtAutoUpdater::ProcessBackend
An extension of UpdaterBackend for easy implementation of QProcess based updater plugins.
Definition: processbackend.h:19
QtAutoUpdater::ProcessBackend::UpdateProcessInfo::stdinData
std::optional< QByteArray > stdinData
Data to be passed to the stdin of the process once it started. Set this to nullopt to disable input.
Definition: processbackend.h:44
QtAutoUpdater::ProcessBackend::InstallProcessInfo
Structure that collects information about an installation process to be started.
Definition: processbackend.h:48
QtAutoUpdater::ProcessBackend::UpdateProcessInfo
Structure that collects information about an update process to be started.
Definition: processbackend.h:41
QVariant
QObject
QtAutoUpdater
The QtAutoUpdater namespace holds all classes that are related with the updater.
Definition: adminauthoriser.h:9
QStringList
QtAutoUpdater::UpdaterBackend
An interface to be implemented by updater plugins to provide the updater functionalities.
Definition: updaterbackend.h:22