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);
141  static QString updaterLogPath();
148  static QString updaterScriptPath();
149  static QString updateStorageDirPath();
150 
151 
152  AutoUpdater(QObject *pParent = nullptr);
153  ~AutoUpdater() override;
154 
155  void abort();
159  const UpdateChannel &channel() const;
176  const QStringList &downloadedPackagesFilenames() const;
177  ErrorCode errorCode() const;
178  QString errorString() const;
179 
180  bool isRunning() const;
181 
189  QNetworkReply::NetworkError lastNetworkError() const;
197  const QList<UpdatePackage> &newUpdatePackages() const;
201  void setChannel(const UpdateChannel &updateChannel);
212  void setIgnoreRevisions(const QMap<QString, QList<QString> > &packagesRevisions);
225  void start();
226 
227 public slots:
228  void confirmDownloadAndInstall();
229 
230 signals:
242  void finished();
243 
244  void overallProgress(int current, int total, const QString &msg);
245  void packageDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
246  void statusMessage(const QString &message);
247 
248 private:
250 
254  QDomDocument adjustUpdaterScriptXml(const QByteArray &xmlSource);
262  void dumpUpdatePackagesToLog(const QList<UpdatePackage> &packages);
263  void emitOverallProgress(const QString &message);
264  void emitStatusMessage(const QString &message);
265  void finishWithError(ErrorCode code);
266  QUrl mkVersionDataFileUrl();
267 
268  ErrorCode saveUpdaterScript();
269  void startPackageDownload(const UpdatePackage &pkg);
270  void startPackageScriptDownload(const UpdatePackage &pkg);
271  void startNextPackageDownload();
272 
273 private slots:
274  void onPackageDownloadFinish();
275  void onPackageDownloadReadyRead();
276  void onPackageScriptDownloadFinish();
277  void onUpdaterInfoDownloadFinish();
278 };
279 
280 #endif