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){
28 //wxString *PageInput;
29 Data = wxString::FromUTF8((char *)ptr);
37 frmUpdate::frmUpdate( wxWindow* parent )
39 frmUpdateADT( parent )
44 void frmUpdate::CloseWindow( wxCommandEvent& event )
51 void frmUpdate::FetchData()
54 // Connect to the update server and grab the
55 // build type information.
58 conn = curl_easy_init();
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.
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.
93 lblRunningVer->SetLabel(RunningVer);
95 // Setup the build type.
97 wxString BuildType = wxT(XSDAB_SOURCE);
98 lblBuildType->SetLabel(BuildType);
100 if (conncode != CURLE_OK){
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)));
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);
127 lblAvailableVer->SetLabel(wxT("Unable to determine."));
129 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
137 if (BuildType == wxT("source")){
139 // Write message about getting the update
140 // from Xestia Gelforn.
142 if (CurrentVerDouble >= VersionCodeDouble){
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)."));
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)."));
154 btnVisitGelforn->Hide();
156 // Display message based on type returned.
158 if (CurrentVerDouble >= VersionCodeDouble){
160 wxString UpdateMessage = wxT("Xestia Address Book is up to date.\n\n");
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."));
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."));
172 lblUpdateMessage->SetLabel(UpdateMessage);
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)"));
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."));
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."));
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/"));