Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
213ac3327800c8ac3777fa312b2e51d0cbd1eaf6
[xestiacalendar/.git] / source / forms / update / frmUpdate.cpp
1 // frmUpdate.cpp - frmUpdate form functions
2 //
3 // (c) 2016-2017 Xestia Software Development.
4 //
5 // This file is part of Xestia Calendar.
6 //
7 // Xestia Calendar is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by the
9 // Free Software Foundation, version 3 of the license.
10 //
11 // Xestia Calendar is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with Xestia Calendar. If not, see <http://www.gnu.org/licenses/>
19 #include "frmUpdate.h"
21 size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){
22         
23         // Write back function for getting version information.
24         
25         wxString Data;
26         //wxString *PageInput;
27         Data = wxString::FromUTF8((char *)ptr);
28         
29         stream->Append(Data);
30         
31         return size * nmemb;
33 }
35 frmUpdate::frmUpdate( wxWindow* parent )
36 :
37 frmUpdateADT( parent )
38 {
40 }
42 void frmUpdate::FetchData()
43 {
45         // Connect to the update server and grab the
46         // build type information.
48         CURL *conn;
49         conn = curl_easy_init();
50         CURLcode conncode;
52         wxString PageData;
53         wxString PageHeader;
55         wxString UpdateAddress = wxT("http://update.xestia.co.uk/xestiacalendar/");
56         UpdateAddress.Append(XSDCAL_SOURCE);
58         curl_easy_setopt(conn, CURLOPT_URL, (const char*)UpdateAddress.mb_str(wxConvUTF8));
59         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
60         curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
61         curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3);
62         curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
63         curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDCAL_USERAGENT);
64         curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate);
65         curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
66         curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
67         curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
68         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1);
70         conncode = (curl_easy_perform(conn));
72         // Split the data received.
73         
74         PageData.Trim();
75         
76         wxString SupportCode = PageData.Left(1);
77         wxString VersionCode = PageData.Mid(1, wxString::npos);
78         wxString RunningVer = wxString::Format(wxT("%s"), XSDCAL_VERSION);
79         double VersionCodeDouble;
80         double CurrentVerDouble;
82         // Setup the running version.
83         
84         lblRunningVer->SetLabel(RunningVer);
86         // Setup the build type.
88         wxString BuildType = wxT(XSDCAL_SOURCE);
89         lblBuildType->SetLabel(BuildType);
90         
91         if (conncode != CURLE_OK){
92         
93                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
94                 curl_easy_cleanup(conn);
95                 curl_global_cleanup();
97                 lblUpdateMessage->SetLabel(wxT("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(conncode)));
99                 return;                 
100         
101         }
103         // Cleanup connections.
105         curl_easy_cleanup(conn);
107         // Setup the avaiable version.
109         RunningVer.ToDouble(&CurrentVerDouble);
111         if (VersionCode.ToDouble(&VersionCodeDouble)){
113                 lblAvailableVer->SetLabel(VersionCode);
115         } else {
116         
117                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
119                 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
121                 return;
122         
123         }
124         
125         // Set a message.
126         
127         if (BuildType == wxT("source")){
128         
129                 // Write message about getting the update
130                 // from Xestia Gelforn.
131                 
132                 if (CurrentVerDouble >= VersionCodeDouble){
133                 
134                         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)."));
135                 
136                 } else {
137                 
138                         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)."));
139         
140                 }
141                 
142         } else {
143         
144                 btnVisitGelforn->Hide();
145         
146                 // Display message based on type returned.
147                 
148                 if (CurrentVerDouble >= VersionCodeDouble){
149                 
150                         wxString UpdateMessage = wxT("Xestia Calendar is up to date.\n\n");
151                 
152                         if (SupportCode == wxT("U")){
154                                 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."));
155                 
156                         } else if (SupportCode == wxT("X")){
158                                 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."));
159                 
160                         }
161                 
162                         lblUpdateMessage->SetLabel(UpdateMessage);
163                 
164                         
165                 
166                 }
167                 
168                 if (SupportCode == wxT("S")){
170                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Calendar for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
171                 
172                 } else if (SupportCode == wxT("U")){
174                         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."));
175                 
176                 } else if (SupportCode == wxT("X")){
178                         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."));
179                 
180                 }
181         
182         }
186 void frmUpdate::VisitGelforn( wxCommandEvent& event )
188         
189         // Launch the Xestia Gelforn website.
190         
191         wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
192         
195 void frmUpdate::VisitPREMIUM( wxCommandEvent& event )
198         // Launch the Xestia PREMIUM website.
199         
200         wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));
201         
204 void frmUpdate::CloseWindow( wxCommandEvent& event )
206         
207         // Close this window.
208         
209         this->Close();
210         
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