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 QT_PACKAGE_NAME;
137  static const QString WADSEEKER_PACKAGE_NAME;
142  static const QString UPDATER_INFO_URL_BASE;
143 
144  static QString errorCodeToString(ErrorCode code);
151  static QString updaterScriptPath();
152  static QString updateStorageDirPath();
153 
154 
155  AutoUpdater(QObject* pParent = NULL);
156  ~AutoUpdater();
157 
158  void abort();
162  const UpdateChannel& channel() const;
179  const QStringList& downloadedPackagesFilenames() const;
180  ErrorCode errorCode() const;
181  QString errorString() const;
182 
183  bool isRunning() const;
184 
192  QNetworkReply::NetworkError lastNetworkError() const;
200  const QList<UpdatePackage>& newUpdatePackages() const;
204  void setChannel(const UpdateChannel& updateChannel);
215  void setIgnoreRevisions(const QMap<QString, QList<QString> >& packagesRevisions);
228  void start();
229 
230  public slots:
231  void confirmDownloadAndInstall();
232 
233  signals:
245  void finished();
246 
247  void overallProgress(int current, int total, const QString& msg);
248  void packageDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
249  void statusMessage(const QString &message);
250 
251  private:
253 
257  QDomDocument adjustUpdaterScriptXml(const QByteArray& xmlSource);
265  void dumpUpdatePackagesToLog(const QList<UpdatePackage>& packages);
266  void emitOverallProgress(const QString& message);
267  void emitStatusMessage(const QString &message);
268  void finishWithError(ErrorCode code);
269  QUrl mkVersionDataFileUrl();
270 
271  ErrorCode saveUpdaterScript();
272  void startPackageDownload(const UpdatePackage& pkg);
273  void startPackageScriptDownload(const UpdatePackage& pkg);
274  void startNextPackageDownload();
275 
276  private slots:
277  void onPackageDownloadFinish();
278  void onPackageDownloadReadyRead();
279  void onPackageScriptDownloadFinish();
280  void onUpdaterInfoDownloadFinish();
281 };
282 
283 #endif
static const QString UPDATER_INFO_URL_BASE
Base URL to the directory where "update-info*" JSON files are contained.
Definition: autoupdater.h:142
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.
static const QString FALLBACK_MAIN_PROGRAM_PACKAGE_NAME
Support for downgrading to monolithic Doomseeker package.
Definition: autoupdater.h:135
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.