Fabcoin Core  0.16.2
P2P Digital Currency
fabcoinversionchecker.cpp
Go to the documentation of this file.
2 #include <../clientversion.h>
3 
4 #include <QNetworkAccessManager>
5 #include <QNetworkRequest>
6 #include <QNetworkReply>
7 #include <QEventLoop>
8 #include <QRegularExpression>
9 #include <QRegularExpressionMatchIterator>
10 
11 #define paternVersion "fabcoin-([0-9]+\\.)?([0-9]+\\.)?([0-9]+)-"
12 
13 FabcoinVersionChecker::FabcoinVersionChecker(QObject *parent) : QObject(parent)
14 {
16 }
17 
19 {
20 
21 }
22 
24 {
25  Version maxReleaseVersion = getMaxReleaseVersion();
26  return maxReleaseVersion > currentVersion;
27 }
28 
30 {
31  QNetworkAccessManager manager;
32  QNetworkReply *response = manager.get(QNetworkRequest(QUrl(FABCOIN_RELEASES)));
33  QEventLoop event;
34  connect(response, SIGNAL(finished()), &event, SLOT(quit()));
35  event.exec();
36  QString html = response->readAll();
37 
38  QRegularExpression regEx(paternVersion);
39  QRegularExpressionMatchIterator regExIt = regEx.globalMatch(html);
40 
41  QList<Version> versions;
42 
43  while (regExIt.hasNext()) {
44  QRegularExpressionMatch match = regExIt.next();
45  QString versionString = match.captured().mid(5, match.captured().length() - 6); // get version string in format XX.XX.XX
46  Version version(versionString);
47  if(!versions.contains(version))
48  {
49  versions.append(version);
50  }
51  }
52  return versions;
53 }
54 
56 {
57  QList<Version> versions = getVersions();
58  Version maxVersion;
59 
60  if(!versions.isEmpty())
61  {
62  maxVersion = *std::max_element(versions.begin(), versions.end());
63  }
64  return maxVersion;
65 }
#define CLIENT_VERSION_MINOR
void version()
Definition: main.cpp:53
FabcoinVersionChecker(QObject *parent=0)
#define CLIENT_VERSION_REVISION
#define CLIENT_VERSION_MAJOR
QList< Version > getVersions()
char const * Version
Definition: Common.cpp:36
#define FABCOIN_RELEASES
#define paternVersion