MuldeR's Utilities for Qt
MUtilities
UpdateChecker.h
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
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 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
22 #pragma once
23 
24 //MUtils
25 #include <MUtils/Global.h>
26 
27 //Qt
28 #include <QThread>
29 #include <QDate>
30 
32 
33 namespace MUtils
34 {
35  class MUTILS_API UpdateCheckerInfo
36  {
37  friend class UpdateChecker;
38 
39  public:
40  UpdateCheckerInfo(void);
41  void resetInfo(void);
42  bool isComplete(void);
43 
44  const quint32 &getBuildNo(void) const { return m_buildNo; }
45  const QDate &getBuildDate(void) const { return m_buildDate; }
46  const QString &getDownloadSite(void) const { return m_downloadSite; }
47  const QString &getDownloadAddress(void) const { return m_downloadAddress; }
48  const QString &getDownloadFilename(void) const { return m_downloadFilename; }
49  const QString &getDownloadFilecode(void) const { return m_downloadFilecode; }
50  const QString &getDownloadChecksum(void) const { return m_downloadChecksum; }
51 
52  private:
53  quint32 m_buildNo;
54  QDate m_buildDate;
55  QString m_downloadSite;
56  QString m_downloadAddress;
57  QString m_downloadFilename;
58  QString m_downloadFilecode;
59  QString m_downloadChecksum;
60  };
61 
62  // ----------------------------------------------------------------
63 
64  class MUTILS_API UpdateChecker : public QThread
65  {
66  Q_OBJECT
67 
68  public:
69  enum
70  {
71  UpdateStatus_NotStartedYet = 0,
72  UpdateStatus_CheckingConnection = 1,
73  UpdateStatus_FetchingUpdates = 2,
74  UpdateStatus_CompletedUpdateAvailable = 3,
75  UpdateStatus_CompletedNoUpdates = 4,
76  UpdateStatus_CompletedNewVersionOlder = 5,
77  UpdateStatus_ErrorNoConnection = 6,
78  UpdateStatus_ErrorConnectionTestFailed = 7,
79  UpdateStatus_ErrorFetchUpdateInfo = 8
80  }
81  update_status_t;
82 
83  UpdateChecker(const QString &binWGet, const QString &binNC, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode = false);
84  ~UpdateChecker(void);
85 
86  const int getUpdateStatus(void) const { return m_status; }
87  const bool getSuccess(void) const { return m_success; };
88  const int getMaximumProgress(void) const { return m_maxProgress; };
89  const int getCurrentProgress(void) const { return m_progress; };
90  const UpdateCheckerInfo *getUpdateInfo(void) const { return m_updateInfo.data(); }
91 
92  protected:
93  void run(void);
94  void checkForUpdates(void);
95  void testKnownHosts(void);
96 
97  signals:
98  void statusChanged(const int status);
99  void progressChanged(const int progress);
100  void messageLogged(const QString &text);
101 
102  private:
103  const int m_maxProgress;
104  QScopedPointer<UpdateCheckerInfo> m_updateInfo;
105 
106  const bool m_betaUpdates;
107  const bool m_testMode;
108 
109  const QString m_applicationId;
110  const quint32 m_installedBuildNo;
111 
112  const QString m_binaryWGet;
113  const QString m_binaryNC;
114  const QString m_binaryGnuPG;
115  const QString m_binaryKeys;
116 
117  volatile bool m_success;
118 
119  int m_status;
120  int m_progress;
121 
122  inline void setStatus(const int status);
123  inline void setProgress(const int progress);
124  inline void log(const QString &str1, const QString &str2 = QString(), const QString &str3 = QString(), const QString &str4 = QString());
125 
126  bool getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign);
127  bool tryContactHost(const QString &hostname);
128  bool parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo);
129 
130  bool getFile(const QString &url, const QString &outFile, const unsigned int maxRedir = 5U, bool *httpOk = NULL);
131  bool getFile(const QString &url, const bool forceIp4, const QString &outFile, const unsigned int maxRedir = 5U, bool *httpOk = NULL);
132  bool checkSignature(const QString &file, const QString &signature);
133  bool tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url);
134  };
135 }
This file contains miscellaneous functions that are generally useful for Qt-based applications...
Definition: UpdateChecker.h:35
Global MUtils namespace.
Definition: CPUFeatures.h:37
Definition: UpdateChecker.h:64