// frmUpdate.cpp - Update form.
//
// (c) 2012-2015 Xestia Software Development.
//
// This file is part of Xestia Address Book.
//
// Xestia Address Book 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 Address Book 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 Address Book. If not, see
#include
#include
#include "frmUpdate.h"
#include "version.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::CloseWindow( wxCommandEvent& event )
{
// Close this window.
this->Close();
}
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("http://update.xestia.co.uk/");
UpdateAddress.Append(XSDAB_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, XSDAB_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"), XSDAB_VERSION);
double VersionCodeDouble;
double CurrentVerDouble;
// Setup the running version.
lblRunningVer->SetLabel(RunningVer);
// Setup the build type.
wxString BuildType = wxT(XSDAB_SOURCE);
lblBuildType->SetLabel(BuildType);
if (conncode != CURLE_OK){
lblAvailableVer->SetLabel(wxT("Unable to determine."));
curl_easy_cleanup(conn);
curl_global_cleanup();
lblUpdateMessage->SetLabel(wxT("An error has occurred. The error message is: ") + wxString::Format(wxT("%s"), curl_easy_strerror(conncode)));
return;
}
// Cleanup connections.
curl_easy_cleanup(conn);
curl_global_cleanup();
// Setup the avaiable version.
RunningVer.ToDouble(&CurrentVerDouble);
if (VersionCode.ToDouble(&VersionCodeDouble)){
lblAvailableVer->SetLabel(VersionCode);
} else {
lblAvailableVer->SetLabel(wxT("Unable to determine."));
lblUpdateMessage->SetLabel(wxT("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 (CurrentVerDouble >= VersionCodeDouble){
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)."));
} else {
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)."));
}
} else {
btnVisitGelforn->Hide();
// Display message based on type returned.
if (CurrentVerDouble >= VersionCodeDouble){
wxString UpdateMessage = wxT("Xestia Address Book is up to date.\n\n");
if (SupportCode == wxT("U")){
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."));
} else if (SupportCode == wxT("X")){
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."));
}
lblUpdateMessage->SetLabel(UpdateMessage);
}
if (SupportCode == wxT("S")){
lblUpdateMessage->SetLabel(wxT("An updated version of Xestia Address Book for your system is available from Xestia PREMIUM (https://premium.xestia.co.uk)"));
} else if (SupportCode == wxT("U")){
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."));
} else if (SupportCode == wxT("X")){
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."));
}
}
}
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/"));
}