Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
frmUpdate: Implemented code from Xestia Address Book
[xestiacalendar/.git] / source / forms / update / frmUpdate.cpp
1 #include "frmUpdate.h"
3 size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){
4         
5         // Write back function for getting version information.
6         
7         wxString Data;
8         //wxString *PageInput;
9         Data = wxString::FromUTF8((char *)ptr);
10         
11         stream->Append(Data);
12         
13         return size * nmemb;
15 }
17 frmUpdate::frmUpdate( wxWindow* parent )
18 :
19 frmUpdateADT( parent )
20 {
22 }
24 void frmUpdate::FetchData()
25 {
27         // Connect to the update server and grab the
28         // build type information.
30         CURL *conn;
31         conn = curl_easy_init();
32         CURLcode conncode;
34         wxString PageData;
35         wxString PageHeader;
37         wxString UpdateAddress = wxT("http://update.xestia.co.uk/xestiacalendar/");
38         UpdateAddress.Append(XSDCAL_SOURCE);
40         curl_easy_setopt(conn, CURLOPT_URL, (const char*)UpdateAddress.mb_str(wxConvUTF8));
41         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
42         curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
43         curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3);
44         curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
45         curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDCAL_USERAGENT);
46         curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate);
47         curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
48         curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
49         curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
50         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1);
52         conncode = (curl_easy_perform(conn));
54         // Split the data received.
55         
56         PageData.Trim();
57         
58         wxString SupportCode = PageData.Left(1);
59         wxString VersionCode = PageData.Mid(1, wxString::npos);
60         wxString RunningVer = wxString::Format(wxT("%s"), XSDCAL_VERSION);
61         double VersionCodeDouble;
62         double CurrentVerDouble;
64         // Setup the running version.
65         
66         lblRunningVer->SetLabel(RunningVer);
68         // Setup the build type.
70         wxString BuildType = wxT(XSDCAL_SOURCE);
71         lblBuildType->SetLabel(BuildType);
72         
73         if (conncode != CURLE_OK){
74         
75                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
76                 curl_easy_cleanup(conn);
77                 curl_global_cleanup();
79                 lblUpdateMessage->SetLabel(wxT("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(conncode)));
81                 return;                 
82         
83         }
85         // Cleanup connections.
87         curl_easy_cleanup(conn);
89         // Setup the avaiable version.
91         RunningVer.ToDouble(&CurrentVerDouble);
93         if (VersionCode.ToDouble(&VersionCodeDouble)){
95                 lblAvailableVer->SetLabel(VersionCode);
97         } else {
98         
99                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
101                 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
103                 return;
104         
105         }
106         
107         // Set a message.
108         
109         if (BuildType == wxT("source")){
110         
111                 // Write message about getting the update
112                 // from Xestia Gelforn.
113                 
114                 if (CurrentVerDouble >= VersionCodeDouble){
115                 
116                         lblUpdateMessage->SetLabel(wxT("Xestia Calendar is up to date.\n\nFor a small yearly cost, prebuilt packages and support is available from Xestia PREMIUM (https://premium.xestia.co.uk)."));
117                 
118                 } else {
119                 
120                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Calendar 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)."));
121         
122                 }
123                 
124         } else {
125         
126                 btnVisitGelforn->Hide();
127         
128                 // Display message based on type returned.
129                 
130                 if (CurrentVerDouble >= VersionCodeDouble){
131                 
132                         wxString UpdateMessage = wxT("Xestia Calendar is up to date.\n\n");
133                 
134                         if (SupportCode == wxT("U")){
136                                 UpdateMessage.Append(wxT("An updated version of Xestia Calendar is available from Xestia PREMIUM (https://premium.xestia.co.uk) but will require your operating system to be updated."));
137                 
138                         } else if (SupportCode == wxT("X")){
140                                 UpdateMessage.Append(wxT("Xestia Calendar 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."));
141                 
142                         }
143                 
144                         lblUpdateMessage->SetLabel(UpdateMessage);
145                 
146                         
147                 
148                 }
149                 
150                 if (SupportCode == wxT("S")){
152                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Calendar for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
153                 
154                 } else if (SupportCode == wxT("U")){
156                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Calendar is available from Xestia PREMIUM (https://premium.xestia.co.uk) but will require your operating system to be updated."));
157                 
158                 } else if (SupportCode == wxT("X")){
160                         lblUpdateMessage->SetLabel(wxT("Xestia Calendar 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."));
161                 
162                 }
163         
164         }
168 void frmUpdate::VisitGelforn( wxCommandEvent& event )
170         
171         // Launch the Xestia Gelforn website.
172         
173         wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
174         
177 void frmUpdate::VisitPREMIUM( wxCommandEvent& event )
180         // Launch the Xestia PREMIUM website.
181         
182         wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));
183         
186 void frmUpdate::CloseWindow( wxCommandEvent& event )
188         
189         // Close this window.
190         
191         this->Close();
192         
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