Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Updated build system.
[xestiaab/.git] / source / frmUpdate.cpp
1 #include <wx/wx.h>
2 #include <curl/curl.h>
4 #include "frmUpdate.h"
5 #include "version.h"
7 size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){
8         
9         wxString Data;
10         //wxString *PageInput;
11         Data = wxString::FromUTF8((char *)ptr);
12         
13         stream->Append(Data);
14         
15         return size * nmemb;
17 }
19 frmUpdate::frmUpdate( wxWindow* parent )
20 :
21 frmUpdateADT( parent )
22 {
24 }
26 void frmUpdate::CloseWindow( wxCommandEvent& event )
27 {
29         this->Close();
31 }
33 void frmUpdate::FetchData()
34 {
36         // Connect to the update server and grab the
37         // build type information.
39         CURL *conn;
40         conn = curl_easy_init();
41         CURLcode conncode;
43         wxString PageData;
44         wxString PageHeader;
46         wxString UpdateAddress = wxT("http://update.xestia.co.uk/");
47         UpdateAddress.Append(XSDAB_SOURCE);
49         curl_easy_setopt(conn, CURLOPT_URL, (const char*)UpdateAddress.mb_str(wxConvUTF8));
50         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
51         curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
52         curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3);
53         curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
54         curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
55         curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate);
56         curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
57         curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
58         curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
59         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1);
61         conncode = (curl_easy_perform(conn));
63         // Split the data received.
64         
65         PageData.Trim();
66         
67         wxString SupportCode = PageData.Left(1);
68         wxString VersionCode = PageData.Mid(1, wxString::npos);
69         wxString RunningVer = wxString::Format(wxT("%s"), XSDAB_VERSION);
70         double VersionCodeDouble;
71         double CurrentVerDouble;
73         // Setup the running version.
74         
75         lblRunningVer->SetLabel(RunningVer);
77         // Setup the build type.
79         wxString BuildType = wxT(XSDAB_SOURCE);
80         lblBuildType->SetLabel(BuildType);
81         
82         if (conncode != CURLE_OK){
83         
84                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
85                 curl_easy_cleanup(conn);
86                 curl_global_cleanup();
88                 lblUpdateMessage->SetLabel(wxT("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(conncode)));
90                 return;                 
91         
92         }
94         // Cleanup connections.
96         curl_easy_cleanup(conn);
97         curl_global_cleanup();
99         // Setup the avaiable version.
101         RunningVer.ToDouble(&CurrentVerDouble);
103         if (VersionCode.ToDouble(&VersionCodeDouble)){
105                 lblAvailableVer->SetLabel(VersionCode);
107         } else {
108         
109                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
111                 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
113                 return;
114         
115         }
116         
117         // Set a message.
118         
119         if (BuildType == wxT("source")){
120         
121                 // Write message about getting the update
122                 // from Xestia Gelforn.
123                 
124                 if (CurrentVerDouble >= VersionCodeDouble){
125                 
126                         lblUpdateMessage->SetLabel(wxT("Xestia Address Book is up to date.\n\nFor a small yearly cost, prebuilt packages and support is available from Xestia PREMIUM (https://premium.xestia.co.uk)."));
127                 
128                 } else {
129                 
130                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Address Book is available from Xestia Gelforn (https://gelforn.xestia.co.uk/).\n\nFor a small yearly cost, prebuilt packages and support is available from Xestia PREMIUM (https://premium.xestia.co.uk)."));
131         
132                 }
133                 
134         } else {
135         
136                 btnVisitGelforn->Hide();
137         
138                 // Display message based on type returned.
139                 
140                 if (CurrentVerDouble >= VersionCodeDouble){
141                 
142                         wxString UpdateMessage = wxT("Xestia Address Book is up to date.\n\n");
143                 
144                         if (SupportCode == wxT("U")){
146                                 UpdateMessage.Append(wxT("An updated version of Xestia Address Book is available from Xestia PREMIUM (https://premium.xestia.co.uk) but will require your operating system to be updated."));
147                 
148                         } else if (SupportCode == wxT("X")){
150                                 UpdateMessage.Append(wxT("Xestia Address Book is no longer supported on the operating system you are using. Please visit the Xestia PREMIUM website (https://premium.xestia.co.uk) for a list of supported operating systems."));
151                 
152                         }
153                 
154                         lblUpdateMessage->SetLabel(UpdateMessage);
155                 
156                         
157                 
158                 }
159                 
160                 if (SupportCode == wxT("S")){
162                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Address Book for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
163                 
164                 } else if (SupportCode == wxT("U")){
166                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Address Book is available from Xestia PREMIUM (https://premium.xestia.co.uk) but will require your operating system to be updated."));
167                 
168                 } else if (SupportCode == wxT("X")){
170                         lblUpdateMessage->SetLabel(wxT("Xestia Address Book is no longer supported on the operating system you are using. Please visit the Xestia PREMIUM website (https://premium.xestia.co.uk) for a list of supported operating systems."));
171                 
172                 }
173         
174         }
178 void frmUpdate::VisitGelforn( wxCommandEvent &event ){
180         wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
184 void frmUpdate::VisitPREMIUM( wxCommandEvent &event ){
186         wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy