autoupdater.h
1 //------------------------------------------------------------------------------
2 // autoupdater.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; 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;
136  static const QString UPDATER_INFO_URL_BASE;
137 
138  static QString errorCodeToString(ErrorCode code);
145  static QString updaterScriptPath();
146  static QString updateStorageDirPath();
147 
148 
149  AutoUpdater(QObject* pParent = NULL);
150  ~AutoUpdater();
151 
152  void abort();
156  const UpdateChannel& channel() const;
173  const QStringList& downloadedPackagesFilenames() const;
174  ErrorCode errorCode() const;
175  QString errorString() const;
176 
177  bool isRunning() const;
178 
186  QNetworkReply::NetworkError lastNetworkError() const;
194  const QList<UpdatePackage>& newUpdatePackages() const;
198  void setChannel(const UpdateChannel& updateChannel);
209  void setIgnoreRevisions(const QMap<QString, QList<unsigned long long> >& packagesRevisions);
222  void start();
223 
224  public slots:
225  void confirmDownloadAndInstall();
226 
227  signals:
239  void finished();
240 
241  void overallProgress(int current, int total, const QString& msg);
242  void packageDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
243  void statusMessage(const QString &message);
244 
245  private:
247 
251  QDomDocument adjustUpdaterScriptXml(const QByteArray& xmlSource);
259  void dumpUpdatePackagesToLog(const QList<UpdatePackage>& packages);
260  void emitOverallProgress(const QString& message);
261  void emitStatusMessage(const QString &message);
262  void finishWithError(ErrorCode code);
263  QUrl mkVersionDataFileUrl();
264 
265  ErrorCode saveUpdaterScript();
266  void startPackageDownload(const UpdatePackage& pkg);
267  void startPackageScriptDownload(const UpdatePackage& pkg);
268  void startNextPackageDownload();
269 
270  private slots:
271  void onPackageDownloadFinish();
272  void onPackageDownloadReadyRead();
273  void onPackageScriptDownloadFinish();
274  void onUpdaterInfoDownloadFinish();
275 };
276 
277 #endif
static const QString UPDATER_INFO_URL_BASE
Base URL to the directory where "update-info*" JSON files are contained.
Definition: autoupdater.h:136
void setIgnoreRevisions(const QMap< QString, QList< unsigned long long > > &packagesRevisions)
Revisions set in this map will not be treated as updates even if they differ from the currently insta...
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'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
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't be parsed.
Definition: autoupdater.h:84
Update was aborted by the user or by the program.
Definition: autoupdater.h:72
Package file can'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.