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);
80 double availableVersion;
81 double currentVersion;
83 // Setup the running version.
85 lblRunningVer->SetLabel(runningVer);
87 // Setup the build type.
89 wxString buildType = wxT(XSDCAL_SOURCE);
90 lblBuildType->SetLabel(buildType);
92 if (connCode != CURLE_OK){
94 lblAvailableVer->SetLabel(_("Unable to determine."));
95 curl_easy_cleanup(conn);
96 curl_global_cleanup();
98 lblUpdateMessage->SetLabel(_("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(connCode)));
104 // Cleanup connections.
106 curl_easy_cleanup(conn);
108 // Setup the avaiable version.
110 runningVer.ToDouble(¤tVersion);
112 if (versionCode.ToDouble(&availableVersion)){
114 lblAvailableVer->SetLabel(versionCode);
118 lblAvailableVer->SetLabel(_("Unable to determine."));
120 lblUpdateMessage->SetLabel(_("Cannot determine the available version at this time. Please retry in a while."));
128 if (buildType == wxT("source")){
130 // Write message about getting the update
131 // from Xestia Gelforn.
133 if (currentVersion >= availableVersion){
135 lblUpdateMessage->SetLabel(_("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)."));
139 lblUpdateMessage->SetLabel(_("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)."));
145 btnVisitGelforn->Hide();
147 // Display message based on type returned.
149 if (currentVersion >= availableVersion){
151 wxString updateMessage = _("Xestia Calendar is up to date.\n\n");
153 if (supportCode == wxT("U")){
155 updateMessage.Append(_("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."));
157 } else if (supportCode == wxT("X")){
159 updateMessage.Append(_("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."));
163 lblUpdateMessage->SetLabel(updateMessage);
169 if (supportCode == wxT("S")){
171 lblUpdateMessage->SetLabel(_("An updated version of Xestia Calendar for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
173 } else if (supportCode == wxT("U")){
175 lblUpdateMessage->SetLabel(_("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."));
177 } else if (supportCode == wxT("X")){
179 lblUpdateMessage->SetLabel(_("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."));
187 void frmUpdate::VisitGelforn( wxCommandEvent& event )
190 // Launch the Xestia Gelforn website.
192 wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/"));
196 void frmUpdate::VisitPREMIUM( wxCommandEvent& event )
199 // Launch the Xestia PREMIUM website.
201 wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/"));
205 void frmUpdate::CloseWindow( wxCommandEvent& event )
208 // Close this window.