Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Added copyright and license header to the C++ files and headers in the top source...
[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         wxString Data;
28         //wxString *PageInput;
29         Data = wxString::FromUTF8((char *)ptr);
30         
31         stream->Append(Data);
32         
33         return size * nmemb;
35 }
37 frmUpdate::frmUpdate( wxWindow* parent )
38 :
39 frmUpdateADT( parent )
40 {
42 }
44 void frmUpdate::CloseWindow( wxCommandEvent& event )
45 {
47         this->Close();
49 }
51 void frmUpdate::FetchData()
52 {
54         // Connect to the update server and grab the
55         // build type information.
57         CURL *conn;
58         conn = curl_easy_init();
59         CURLcode conncode;
61         wxString PageData;
62         wxString PageHeader;
64         wxString UpdateAddress = wxT("http://update.xestia.co.uk/");
65         UpdateAddress.Append(XSDAB_SOURCE);
67         curl_easy_setopt(conn, CURLOPT_URL, (const char*)UpdateAddress.mb_str(wxConvUTF8));
68         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0);
69         curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
70         curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3);
71         curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE);
72         curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDAB_USERAGENT);
73         curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate);
74         curl_easy_setopt(conn, CURLOPT_WRITEDATA, &PageData);
75         curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &PageHeader);
76         curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1);
77         curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1);
79         conncode = (curl_easy_perform(conn));
81         // Split the data received.
82         
83         PageData.Trim();
84         
85         wxString SupportCode = PageData.Left(1);
86         wxString VersionCode = PageData.Mid(1, wxString::npos);
87         wxString RunningVer = wxString::Format(wxT("%s"), XSDAB_VERSION);
88         double VersionCodeDouble;
89         double CurrentVerDouble;
91         // Setup the running version.
92         
93         lblRunningVer->SetLabel(RunningVer);
95         // Setup the build type.
97         wxString BuildType = wxT(XSDAB_SOURCE);
98         lblBuildType->SetLabel(BuildType);
99         
100         if (conncode != CURLE_OK){
101         
102                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
103                 curl_easy_cleanup(conn);
104                 curl_global_cleanup();
106                 lblUpdateMessage->SetLabel(wxT("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(conncode)));
108                 return;                 
109         
110         }
112         // Cleanup connections.
114         curl_easy_cleanup(conn);
115         curl_global_cleanup();
117         // Setup the avaiable version.
119         RunningVer.ToDouble(&CurrentVerDouble);
121         if (VersionCode.ToDouble(&VersionCodeDouble)){
123                 lblAvailableVer->SetLabel(VersionCode);
125         } else {
126         
127                 lblAvailableVer->SetLabel(wxT("Unable to determine."));
129                 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
131                 return;
132         
133         }
134         
135         // Set a message.
136         
137         if (BuildType == wxT("source")){
138         
139                 // Write message about getting the update
140                 // from Xestia Gelforn.
141                 
142                 if (CurrentVerDouble >= VersionCodeDouble){
143                 
144                         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)."));
145                 
146                 } else {
147                 
148                         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)."));
149         
150                 }
151                 
152         } else {
153         
154                 btnVisitGelforn->Hide();
155         
156                 // Display message based on type returned.
157                 
158                 if (CurrentVerDouble >= VersionCodeDouble){
159                 
160                         wxString UpdateMessage = wxT("Xestia Address Book is up to date.\n\n");
161                 
162                         if (SupportCode == wxT("U")){
164                                 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."));
165                 
166                         } else if (SupportCode == wxT("X")){
168                                 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."));
169                 
170                         }
171                 
172                         lblUpdateMessage->SetLabel(UpdateMessage);
173                 
174                         
175                 
176                 }
177                 
178                 if (SupportCode == wxT("S")){
180                         lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Address Book for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
181                 
182                 } else if (SupportCode == wxT("U")){
184                         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."));
185                 
186                 } else if (SupportCode == wxT("X")){
188                         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."));
189                 
190                 }
191         
192         }
196 void frmUpdate::VisitGelforn( wxCommandEvent &event ){
198         wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
202 void frmUpdate::VisitPREMIUM( wxCommandEvent &event ){
204         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