autoupdater.h
1 //------------------------------------------------------------------------------
2 // autoupdater.h
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2012 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef DOOMSEEKER_UPDATER_AUTOUPDATER_H
24 #define DOOMSEEKER_UPDATER_AUTOUPDATER_H
25 
26 #include "dptr.h"
27 
28 #include <QDomDocument>
29 #include <QNetworkReply>
30 #include <QObject>
31 #include <QString>
32 #include <QUrl>
33 
34 class UpdateChannel;
35 class UpdatePackage;
36 
61 class AutoUpdater : public QObject
62 {
63  Q_OBJECT
64 
65 public:
66  enum ErrorCode
67  {
68  EC_Ok = 0,
120  };
121 
125  static const QString PLUGIN_PREFIX;
131  static const QString MAIN_PROGRAM_PACKAGE_NAME;
132  static const QString QT_PACKAGE_NAME;
133  static const QString WADSEEKER_PACKAGE_NAME;
138  static const QString UPDATER_INFO_URL_BASE;
139 
140  static QString errorCodeToString(ErrorCode code);
147  static QString updaterScriptPath();
148  static QString updateStorageDirPath();
149 
150 
151  AutoUpdater(QObject *pParent = nullptr);
152  ~AutoUpdater() override;
153 
154  void abort();
158  const UpdateChannel &channel() const;
175  const QStringList &downloadedPackagesFilenames() const;
176  ErrorCode errorCode() const;
177  QString errorString() const;
178 
179  bool isRunning() const;
180 
188  QNetworkReply::NetworkError lastNetworkError() const;
196  const QList<UpdatePackage> &newUpdatePackages() const;
200  void setChannel(const UpdateChannel &updateChannel);
211  void setIgnoreRevisions(const QMap<QString, QList<QString> > &packagesRevisions);
224  void start();
225 
226 public slots:
227  void confirmDownloadAndInstall();
228 
229 signals:
241  void finished();
242 
243  void overallProgress(int current, int total, const QString &msg);
244  void packageDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
245  void statusMessage(const QString &message);
246 
247 private:
249 
253  QDomDocument adjustUpdaterScriptXml(const QByteArray &xmlSource);
261  void dumpUpdatePackagesToLog(const QList<UpdatePackage> &packages);
262  void emitOverallProgress(const QString &message);
263  void emitStatusMessage(const QString &message);
264  void finishWithError(ErrorCode code);
265  QUrl mkVersionDataFileUrl();
266 
267  ErrorCode saveUpdaterScript();
268  void startPackageDownload(const UpdatePackage &pkg);
269  void startPackageScriptDownload(const UpdatePackage &pkg);
270  void startNextPackageDownload();
271 
272 private slots:
273  void onPackageDownloadFinish();
274  void onPackageDownloadReadyRead();
275  void onPackageScriptDownloadFinish();
276  void onUpdaterInfoDownloadFinish();
277 };
278 
279 #endif