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 = NULL);
152  ~AutoUpdater();
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
static const QString UPDATER_INFO_URL_BASE
Base URL to the directory where "update-info*" JSON files are contained.
Definition: autoupdater.h:138
One of packages has no revision info.
Definition: autoupdater.h:93
QNetworkReply::NetworkError lastNetworkError() const
The network error that caused the updater to fail.
Failed to create directory for updates storage.
Definition: autoupdater.h:110
static QString updaterScriptPath()
Path to updater script XML file.
No valid UpdateChannel was specified.
Definition: autoupdater.h:76
const UpdateChannel & channel() const
setChannel() .
Failed to download update package.
Definition: autoupdater.h:106
QUrl.isValid() for package download URL returned false or QUrl.isRelative() returned true...
Definition: autoupdater.h:102
Update script can&#39;t be merged and stored on the local filesystem.
Definition: autoupdater.h:119
const QList< UpdatePackage > & newUpdatePackages() const
List of new update packages to install.
One of packages has no download URL.
Definition: autoupdater.h:97
void setChannel(const UpdateChannel &updateChannel)
Update channel name.
static const QString PLUGIN_PREFIX
Prefix for all plugins packages names.
Definition: autoupdater.h:125
void setIgnoreRevisions(const QMap< QString, QList< QString > > &packagesRevisions)
Revisions set in this map will not be treated as updates even if they differ from the currently insta...
File was parseable but there was no main program information inside.
Definition: autoupdater.h:89
Deals with program updates/upgrades.
Definition: autoupdater.h:61
const QStringList & downloadedPackagesFilenames() const
Filenames for packages which are ready to install.
void setRequireDownloadAndInstallConfirmation(bool b)
Controls if the download&installation process is automated.
Network error when downloading updater info file.
Definition: autoupdater.h:80
Updater info file can&#39;t be parsed.
Definition: autoupdater.h:84
Update was aborted by the user or by the program.
Definition: autoupdater.h:72
Package file can&#39;t be stored on the local filesystem.
Definition: autoupdater.h:114
static const QString MAIN_PROGRAM_PACKAGE_NAME
Package name for the main program.
Definition: autoupdater.h:131
void downloadAndInstallConfirmationRequested()
Information on update packages has been received and install confirmation is requested.
void finished()
AutoUpdater has finished its job.