Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Move INSTALL, LICENSE, README, THANKS and TODO into root directory
[xestiaab/.git] / source / frmUpdate.cpp
1 // frmUpdate.cpp - Update form.
2 //
3 // (c) 2012-2015 Xestia Software Development.
4 //
5 // This file is part of Xestia Address Book.
6 //
7 // Xestia Address Book 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 Address Book 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 Address Book. If not, see <http://www.gnu.org/licenses/>
19 #include <wx/wx.h>
20 #include <curl/curl.h>
22 #include "frmUpdate.h"
23 #include "version.h"
25 size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){
26         
27         // Write back function for getting version information.
28         
29         wxString Data;
30         //wxString *PageInput;
31         Data = wxString::FromUTF8((char *)ptr);
32         
33         stream->Append(Data);
34         
35         return size * nmemb;
37 }
39 frmUpdate::frmUpdate( wxWindow* parent )
40 :
41 frmUpdateADT( parent )
42 {
44 }
46 void frmUpdate::CloseWindow( wxCommandEvent& event )
47 {
49         // Close this window.
50         
51         this->Close();
53 }
55 void frmUpdate::FetchData()
56 {
58         // Connect to the update server and grab the
59         // build type information.
61         CURL *conn;
62         conn = curl_easy_init();
63         CURLcode conncode;
65         wxString PageData;
66         wxString PageHeader;
68         wxString UpdateAddress = wxT("https://update.xestia.co.uk/");
69         UpdateAddress.Append(XSDAB_SOURCE);
71         curl_easy_setopt(conn, CURLOPT_URL, (const char*)UpdateAddress.mb_str(wxConvUTF8));
72         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
73         curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
74         curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3);
75         curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
76         curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
77         curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate);
78         curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
79         curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
80         curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
81         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1);
83         conncode = (curl_easy_perform(conn));
85         // Split the data received.
86         
87         PageData.Trim();
88         
89         wxString SupportCode = PageData.Left(1);
90         wxString VersionCode = PageData.Mid(1, wxString::npos);
91         wxString RunningVer = wxString::Format(wxT("%s"), XSDAB_VERSION);
92         double VersionCodeDouble;
93         double CurrentVerDouble;
95         // Setup the running version.
96         
97         lblRunningVer->SetLabel(RunningVer);
99         // Setup the build type.
101         wxString BuildType = wxT(XSDAB_SOURCE);
102         lblBuildType->SetLabel(BuildType);
103         
104         if (conncode != CURLE_OK){
105         
106                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
107                 curl_easy_cleanup(conn);
108                 curl_global_cleanup();
110                 lblUpdateMessage->SetLabel(wxT("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(conncode)));
112                 return;                 
113         
114         }
116         // Cleanup connections.
118         curl_easy_cleanup(conn);
119         curl_global_cleanup();
121         // Setup the avaiable version.
123         RunningVer.ToDouble(&CurrentVerDouble);
125         if (VersionCode.ToDouble(&VersionCodeDouble)){
127                 lblAvailableVer->SetLabel(VersionCode);
129         } else {
130         
131                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
133                 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
135                 return;
136         
137         }
138         
139         // Set a message.
140         
141         if (BuildType == wxT("source")){
142         
143                 // Write message about getting the update
144                 // from Xestia Gelforn.
145                 
146                 if (CurrentVerDouble >= VersionCodeDouble){
147                 
148                         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)."));
149                 
150                 } else {
151                 
152                         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)."));
153         
154                 }
155                 
156         } else {
157         
158                 btnVisitGelforn->Hide();
159         
160                 // Display message based on type returned.
161                 
162                 if (CurrentVerDouble >= VersionCodeDouble){
163                 
164                         wxString UpdateMessage = wxT("Xestia Address Book is up to date.\n\n");
165                 
166                         if (SupportCode == wxT("U")){
168                                 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."));
169                 
170                         } else if (SupportCode == wxT("X")){
172                                 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."));
173                 
174                         }
175                 
176                         lblUpdateMessage->SetLabel(UpdateMessage);
177                 
178                         
179                 
180                 }
181                 
182                 if (SupportCode == wxT("S")){
184                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Address Book for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
185                 
186                 } else if (SupportCode == wxT("U")){
188                         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."));
189                 
190                 } else if (SupportCode == wxT("X")){
192                         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."));
193                 
194                 }
195         
196         }
200 void frmUpdate::VisitGelforn( wxCommandEvent &event ){
202         // Launch the Xestia Gelforn website.
203         
204         wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
208 void frmUpdate::VisitPREMIUM( wxCommandEvent &event ){
210         // Launch the Xestia PREMIUM website.
211         
212         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