1 // frmUpdate.cpp - frmUpdate form functions
3 // (c) 2016-2017 Xestia Software Development.
5 // This file is part of Xestia Calendar.
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.
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.
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){
23 // Write back function for getting version information.
26 //wxString *PageInput;
27 Data = wxString::FromUTF8((char *)ptr);
35 frmUpdate::frmUpdate( wxWindow* parent )
37 frmUpdateADT( parent )
42 void frmUpdate::FetchData()
45 // Connect to the update server and grab the
46 // build type information.
49 conn = curl_easy_init();
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.
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.
84 lblRunningVer->SetLabel(RunningVer);
86 // Setup the build type.
88 wxString BuildType = wxT(XSDCAL_SOURCE);
89 lblBuildType->SetLabel(BuildType);
91 if (conncode != CURLE_OK){
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)));
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);
117 lblAvailableVer->SetLabel(wxT("Unable to determine."));
119 lblUpdateMessage->SetLabel(wxT("Cannot determine the available version at this time. Please retry in a while."));
127 if (BuildType == wxT("source")){
129 // Write message about getting the update
130 // from Xestia Gelforn.
132 if (CurrentVerDouble >= VersionCodeDouble){
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)."));
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)."));
144 btnVisitGelforn->Hide();
146 // Display message based on type returned.
148 if (CurrentVerDouble >= VersionCodeDouble){
150 wxString UpdateMessage = wxT("Xestia Calendar is up to date.\n\n");
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."));
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."));
162 lblUpdateMessage->SetLabel(UpdateMessage);
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)"));
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."));
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."));
186 void frmUpdate::VisitGelforn( wxCommandEvent& event )
189 // Launch the Xestia Gelforn website.
191 wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
195 void frmUpdate::VisitPREMIUM( wxCommandEvent& event )
198 // Launch the Xestia PREMIUM website.
200 wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));
204 void frmUpdate::CloseWindow( wxCommandEvent& event )
207 // Close this window.