WE Core
Loading...
Searching...
No Matches
UpdateChecker.h
Go to the documentation of this file.
1/*
2 * File: UpdateChecker.h
3 *
4 * Created: 05/05/2017
5 *
6 * This file is part of WECore.
7 *
8 * WECore is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * WECore is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef UpdateChecker_h
23#define UpdateChecker_h
24
25#include <string>
26#include <curl/curl.h>
27
29public:
30 UpdateChecker() = default;
31
32 bool checkIsLatestVersion(const char* productName,
33 const char* productVersion) {
34
35 // cURL setup
36 CURL *curl;
37 CURLcode result;
38 curl = curl_easy_init();
39
40 // build the URL we'll be sending
41 std::string requestURL {TARGET_URL};
42 requestURL.append("?product=");
43 requestURL.append(productName);
44
45 std::string response;
46
47 // setup the request
48 curl_easy_setopt(curl, CURLOPT_URL, requestURL.c_str());
49 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, _writeToString);
50 curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
51
52 // send the request and clean up
53 result = curl_easy_perform(curl);
54 curl_easy_cleanup(curl);
55
56 return (productVersion == response);
57 }
58
59private:
60 const std::string TARGET_URL {"https://whiteelephantaudio.com/versionChecker.php"};
61
62 static size_t _writeToString(char* ptr, size_t size, size_t nmemb, std::string* stream) {
63 *stream = std::string(ptr);
64
65 return size * nmemb;
66 }
67};
68
69#endif /* UpdateChecker_h */
static size_t _writeToString(char *ptr, size_t size, size_t nmemb, std::string *stream)
bool checkIsLatestVersion(const char *productName, const char *productVersion)
UpdateChecker()=default
const std::string TARGET_URL