From b8f13e45be884dc12884ebe8f3dcd9eecb23a106 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:20:29 +0200 Subject: 5.5 --- ui/check_version.cpp | 56 +++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) (limited to 'ui/check_version.cpp') diff --git a/ui/check_version.cpp b/ui/check_version.cpp index 5856f95a..56896836 100644 --- a/ui/check_version.cpp +++ b/ui/check_version.cpp @@ -15,56 +15,46 @@ #include #include "msg_popup.h" #include "../lib/ffs_paths.h" -#include -#include #include +using namespace zen; -bool getOnlineVersion(wxString& version) + +wxString getOnlineVersion() //empty string on error; { wxWindowDisabler dummy; wxHTTP webAccess; - webAccess.SetHeader(wxT("Content-type"), wxT("text/html; charset=utf-8")); - webAccess.SetTimeout(5); //5 seconds of timeout instead of 10 minutes... + webAccess.SetHeader(L"Content-type", L"text/html; charset=utf-8"); + webAccess.SetTimeout(5); //5 seconds of timeout instead of 10 minutes(WTF are they thinking???)... - if (webAccess.Connect(wxT("freefilesync.cvs.sourceforge.net"))) //only the server, no pages here yet... + if (webAccess.Connect(L"freefilesync.cvs.sourceforge.net")) //only the server, no pages here yet... { //wxApp::IsMainLoopRunning(); // should return true - std::unique_ptr httpStream(webAccess.GetInputStream(wxT("/viewvc/freefilesync/version/version.txt"))); + std::unique_ptr httpStream(webAccess.GetInputStream(L"/viewvc/freefilesync/version/version.txt")); //must be deleted BEFORE webAccess is closed if (httpStream && webAccess.GetError() == wxPROTO_NOERR) { - wxString newestVersion; - wxStringOutputStream out_stream(&newestVersion); + wxString onlineVersion; + wxStringOutputStream out_stream(&onlineVersion); httpStream->Read(out_stream); - if (!newestVersion.empty()) - { - version = newestVersion; - return true; - } + return onlineVersion; } } - - return false; + return wxString(); } const wchar_t VERSION_SEP = L'.'; - std::vector parseVersion(const wxString& version) { - std::vector output; + std::vector digits = split(version, VERSION_SEP); - wxStringTokenizer tkz(version, VERSION_SEP, wxTOKEN_RET_EMPTY); - while (tkz.HasMoreTokens()) - { - const wxString& token = tkz.GetNextToken(); - output.push_back(zen::stringTo(token)); - } + std::vector output; + std::transform(digits.begin(), digits.end(), std::back_inserter(output), [&](const wxString& d) { return stringTo(d); }); return output; } @@ -74,18 +64,18 @@ bool isNewerVersion(const wxString& onlineVersion) std::vector current = parseVersion(zen::currentVersion); std::vector online = parseVersion(onlineVersion); - if (online.empty() || online[0] == 0) //onlineVersion may be "This website has been moved..." In this case better check for an update + if (online.empty() || online[0] == 0) //online version may be "This website has been moved..." In this case better check for an update return true; return std::lexicographical_compare(current.begin(), current.end(), - online.begin(), online.end()); + online .begin(), online .end()); } void zen::checkForUpdateNow(wxWindow* parent) { - wxString onlineVersion; - if (!getOnlineVersion(onlineVersion)) + const wxString onlineVersion = getOnlineVersion(); + if (onlineVersion.empty()) { wxMessageBox(_("Unable to connect to sourceforge.net!"), _("Error"), wxOK | wxICON_ERROR, parent); return; @@ -94,7 +84,7 @@ void zen::checkForUpdateNow(wxWindow* parent) if (isNewerVersion(onlineVersion)) { if (showQuestionDlg(parent, ReturnQuestionDlg::BUTTON_YES | ReturnQuestionDlg::BUTTON_CANCEL, - _("A newer version of FreeFileSync is available:") + L" " + onlineVersion + L"\n\n" + _("Download now?")) == ReturnQuestionDlg::BUTTON_YES) + _("A new version of FreeFileSync is available:") + L" " + onlineVersion + L"\n\n" + _("Download now?")) == ReturnQuestionDlg::BUTTON_YES) wxLaunchDefaultBrowser(L"http://sourceforge.net/projects/freefilesync/files/freefilesync/v" + onlineVersion + L"/"); } else @@ -105,7 +95,7 @@ void zen::checkForUpdateNow(wxWindow* parent) void zen::checkForUpdatePeriodically(wxWindow* parent, long& lastUpdateCheck) { #ifdef FFS_LINUX - if (!zen::isPortableVersion()) //don't check for updates in installer version -> else: handled by .deb + if (!zen::isPortableVersion()) //don't check for updates in locally installed version -> handled by system updater return; #endif @@ -132,8 +122,8 @@ void zen::checkForUpdatePeriodically(wxWindow* parent, long& lastUpdateCheck) } else if (wxGetLocalTime() >= lastUpdateCheck + 7 * 24 * 3600) //check weekly { - wxString onlineVersion; - if (!getOnlineVersion(onlineVersion)) + const wxString onlineVersion = getOnlineVersion(); + if (onlineVersion.empty()) return; //do not handle error lastUpdateCheck = wxGetLocalTime(); @@ -141,7 +131,7 @@ void zen::checkForUpdatePeriodically(wxWindow* parent, long& lastUpdateCheck) if (isNewerVersion(onlineVersion)) { if (showQuestionDlg(parent, ReturnQuestionDlg::BUTTON_YES | ReturnQuestionDlg::BUTTON_CANCEL, - _("A newer version of FreeFileSync is available:") + L" " + onlineVersion + L"\n\n" + _("Download now?")) == ReturnQuestionDlg::BUTTON_YES) + _("A new version of FreeFileSync is available:") + L" " + onlineVersion + L"\n\n" + _("Download now?")) == ReturnQuestionDlg::BUTTON_YES) wxLaunchDefaultBrowser(L"http://sourceforge.net/projects/freefilesync/files/freefilesync/v" + onlineVersion + L"/"); } } -- cgit