// frmUpdate.cpp - frmUpdate form functions // // (c) 2016-2017 Xestia Software Development. // // This file is part of Xestia Calendar. // // Xestia Calendar is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by the // Free Software Foundation, version 3 of the license. // // Xestia Calendar is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License along // with Xestia Calendar. If not, see #include "frmUpdate.h" size_t WritebackFuncUpdate(char *ptr, size_t size, size_t nmemb, wxString *stream){ // Write back function for getting version information. wxString data; //wxString *PageInput; data = wxString::FromUTF8((char *)ptr); stream->Append(data); return size * nmemb; } frmUpdate::frmUpdate( wxWindow* parent ) : frmUpdateADT( parent ) { } void frmUpdate::FetchData() { // Connect to the update server and grab the // build type information. CURL *conn; conn = curl_easy_init(); CURLcode connCode; wxString pageData; wxString pageHeader; wxString updateAddress = wxT("https://update.xestia.co.uk/xestiacalendar/"); updateAddress.Append(XSDCAL_SOURCE); curl_easy_setopt(conn, CURLOPT_URL, (const char*)updateAddress.mb_str(wxConvUTF8)); curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_easy_setopt(conn, CURLOPT_TIMEOUT, 3); curl_easy_setopt(conn, CURLOPT_FAILONERROR, TRUE); curl_easy_setopt(conn, CURLOPT_USERAGENT, XSDCAL_USERAGENT); curl_easy_setopt(conn, CURLOPT_WRITEFUNCTION, WritebackFuncUpdate); curl_easy_setopt(conn, CURLOPT_WRITEDATA, &pageData); curl_easy_setopt(conn, CURLOPT_WRITEHEADER, &pageHeader); curl_easy_setopt(conn, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(conn, CURLOPT_NOPROGRESS, 1); connCode = (curl_easy_perform(conn)); // Split the data received. pageData.Trim(); wxString supportCode = pageData.Left(1); wxString versionCode = pageData.Mid(1, wxString::npos); wxString runningVer = wxString::Format(wxT("%s"), XSDCAL_VERSION); double availableVersion; double currentVersion; // Setup the running version. lblRunningVer->SetLabel(runningVer); // Setup the build type. wxString buildType = wxT(XSDCAL_SOURCE); lblBuildType->SetLabel(buildType); if (connCode != CURLE_OK){ lblAvailableVer->SetLabel(_("Unable to determine.")); curl_easy_cleanup(conn); curl_global_cleanup(); lblUpdateMessage->SetLabel(_("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(connCode))); return; } // Cleanup connections. curl_easy_cleanup(conn); // Setup the avaiable version. runningVer.ToDouble(¤tVersion); if (versionCode.ToDouble(&availableVersion)){ lblAvailableVer->SetLabel(versionCode); } else { lblAvailableVer->SetLabel(_("Unable to determine.")); lblUpdateMessage->SetLabel(_("Cannot determine the available version at this time. Please retry in a while.")); return; } // Set a message. if (buildType == wxT("source")){ // Write message about getting the update // from Xestia Gelforn. if (currentVersion >= availableVersion){ 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).")); } else { 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).")); } } else { btnVisitGelforn->Hide(); // Display message based on type returned. if (currentVersion >= availableVersion){ wxString updateMessage = _("Xestia Calendar is up to date.\n\n"); if (supportCode == wxT("U")){ 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.")); } else if (supportCode == wxT("X")){ 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.")); } lblUpdateMessage->SetLabel(updateMessage); } if (supportCode == wxT("S")){ lblUpdateMessage->SetLabel(_("An updated version of Xestia Calendar for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)")); } else if (supportCode == wxT("U")){ 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.")); } else if (supportCode == wxT("X")){ 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.")); } } } void frmUpdate::VisitGelforn( wxCommandEvent& event ) { // Launch the Xestia Gelforn website. wxLaunchDefaultBrowser(wxT("https://gelforn.xestia.co.uk/")); } void frmUpdate::VisitPREMIUM( wxCommandEvent& event ) { // Launch the Xestia PREMIUM website. wxLaunchDefaultBrowser(wxT("https://premium.xestia.co.uk/")); } void frmUpdate::CloseWindow( wxCommandEvent& event ) { // Close this window. this->Close(); }