1 // frmUpdate.cpp - Update form.
3 // (c) 2012-2015 Xestia Software Development.
5 // This file is part of Xestia Address Book.
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.
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.
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/>
20 #include <curl/curl.h>
22 #include "frmUpdate.h"
25 size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){
27 // Write back function for getting version information.
30 //wxString *PageInput;
31 Data = wxString::FromUTF8((char *)ptr);
39 frmUpdate::frmUpdate( wxWindow* parent )
41 frmUpdateADT( parent )
46 void frmUpdate::CloseWindow( wxCommandEvent& event )
55 void frmUpdate::FetchData()
58 // Connect to the update server and grab the
59 // build type information.
62 conn = curl_easy_init();
68 wxString UpdateAddress = wxT("http://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.
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.
97 lblRunningVer->SetLabel(RunningVer);
99 // Setup the build type.
101 wxString BuildType = wxT(XSDAB_SOURCE);
102 lblBuildType->SetLabel(BuildType);
104 if (conncode != CURLE_OK){
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)));
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);
131 lblAvailableVer->SetLabel(wxT("Unable to determine."));
133 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
141 if (BuildType == wxT("source")){
143 // Write message about getting the update
144 // from Xestia Gelforn.
146 if (CurrentVerDouble >= VersionCodeDouble){
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)."));
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)."));
158 btnVisitGelforn->Hide();
160 // Display message based on type returned.
162 if (CurrentVerDouble >= VersionCodeDouble){
164 wxString UpdateMessage = wxT("Xestia Address Book is up to date.\n\n");
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."));
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."));
176 lblUpdateMessage->SetLabel(UpdateMessage);
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)"));
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."));
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."));
200 void frmUpdate::VisitGelforn( wxCommandEvent &event ){
202 // Launch the Xestia Gelforn website.
204 wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
208 void frmUpdate::VisitPREMIUM( wxCommandEvent &event ){
210 // Launch the Xestia PREMIUM website.
212 wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));