Mania++
 All Classes Functions Variables Pages
VersionChecker.h
1 #ifndef VERSIONCHECKER_H_
2 #define VERSIONCHECKER_H_
3 
4 #include <curl/curl.h>
5 #include "json.hpp"
6 
7 #include "Config/Version.h"
8 #include "../Utils/Logging.h"
9 
10 using json = nlohmann::json;
11 
12 //* GitVersion
16 struct GitVersion
17 {
18  std::string Repository;
19  std::string Tag;
20  std::string Name;
21  std::string Commit;
22  bool PreRelease;
23 };
24 
25 //* VersionCompare
30 {
31 public:
38  static bool NewerThanCurrent(const std::string& current, const std::string& other)
39  {
40  int parsedCurrent[3], parsedOther[3];
41  parseVersion(parsedCurrent, current);
42  parseVersion(parsedOther, other);
43  return std::lexicographical_compare(parsedCurrent, parsedCurrent + 3, parsedOther, parsedOther + 3);
44  }
45 
46 private:
53  static void parseVersion(int result[3], const std::string& input)
54  {
55  std::istringstream parser(input);
56  parser >> result[0];
57  for(int idx = 1; idx < 3; idx++)
58  {
59  parser.get();
60  parser >> result[idx];
61  }
62  }
63 };
64 
65 //* VersionChecker
70 {
71 public:
78  bool CheckForUpdates(std::string repository, std::string currentVersion);
79 
80 private:
89  static size_t receiveData(void* contents, size_t size, size_t nmemb, std::string* tags);
90 
97  void retrieveData(std::string url, std::string* data);
98 
104  std::vector<GitVersion> retrieveVersions(std::string repository);
105 
111  std::vector<GitVersion> decodeVersions(std::string response);
112 
118  void retrieveRelease(GitVersion* version);
119 
126  void decodeRelease(GitVersion* version, std::string response);
127 };
128 
129 #endif // VERSIONCHECKER_H_
Compares string versions.
Definition: VersionChecker.h:29
bool PreRelease
Is pre-release?.
Definition: VersionChecker.h:22
static void parseVersion(int result[3], const std::string &input)
Definition: VersionChecker.h:53
bool CheckForUpdates(std::string repository, std::string currentVersion)
Returns whether there are updates available.
Definition: VersionChecker.cpp:3
Checks Mania++ version (and possibly plugin versions).
Definition: VersionChecker.h:69
void retrieveData(std::string url, std::string *data)
Retrieves data via cURL.
Definition: VersionChecker.cpp:96
void decodeRelease(GitVersion *version, std::string response)
Decodes the JSON response with release and inputs info into version struct.
Definition: VersionChecker.cpp:157
std::string Tag
Tag version.
Definition: VersionChecker.h:19
std::vector< GitVersion > retrieveVersions(std::string repository)
Retrieves versions (tags) of repository.
Definition: VersionChecker.cpp:120
static bool NewerThanCurrent(const std::string &current, const std::string &other)
Definition: VersionChecker.h:38
static size_t receiveData(void *contents, size_t size, size_t nmemb, std::string *tags)
Receives data from cURL input.
Definition: VersionChecker.cpp:78
std::vector< GitVersion > decodeVersions(std::string response)
Decodes the JSON response with versions (tags) of repository.
Definition: VersionChecker.cpp:128
void retrieveRelease(GitVersion *version)
Retrieves release information.
Definition: VersionChecker.cpp:149
std::string Repository
Name of the GitHub repository.
Definition: VersionChecker.h:18
Contains information about a Git release (version).
Definition: VersionChecker.h:16
std::string Commit
SHA commit.
Definition: VersionChecker.h:21
std::string Name
Tag name (description).
Definition: VersionChecker.h:20