// ************************************************************************** // * This file is part of the FreeFileSync project. It is distributed under * // * GNU General Public License: http://www.gnu.org/licenses/gpl.html * // * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "check_version.h" #include #include #include #include #include "../version/version.h" #include #include #include #include "msg_popup.h" #include "../lib/ffs_paths.h" #include #include #include bool getOnlineVersion(wxString& version) { 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... if (webAccess.Connect(wxT("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"))); //must be deleted BEFORE webAccess is closed if (httpStream && webAccess.GetError() == wxPROTO_NOERR) { wxString newestVersion; wxStringOutputStream out_stream(&newestVersion); httpStream->Read(out_stream); if (!newestVersion.empty()) { version = newestVersion; return true; } } } return false; } const wxChar VERSION_SEP = wxT('.'); std::vector parseVersion(const wxString& version) { std::vector output; wxStringTokenizer tkz(version, VERSION_SEP, wxTOKEN_RET_EMPTY); while (tkz.HasMoreTokens()) { const wxString& token = tkz.GetNextToken(); output.push_back(zen::stringTo(token)); } return output; } bool newerVersionExists(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 return true; return std::lexicographical_compare(current.begin(), current.end(), online.begin(), online.end()); } void zen::checkForUpdateNow(wxWindow* parent) { wxString onlineVersion; if (!getOnlineVersion(onlineVersion)) { wxMessageBox(_("Unable to connect to sourceforge.net!"), _("Error"), wxOK | wxICON_ERROR, parent); return; } if (newerVersionExists(onlineVersion)) { const int rv = wxMessageBox(_("A newer version of FreeFileSync is available:") + L" v" + onlineVersion + L". " + _("Download now?"), _("Information"), wxYES_NO | wxICON_QUESTION, parent); if (rv == wxYES) wxLaunchDefaultBrowser(wxString(L"http://sourceforge.net/projects/freefilesync/files/freefilesync/v") + onlineVersion + L"/"); } else wxMessageBox(_("FreeFileSync is up to date!"), _("Information"), wxICON_INFORMATION, 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 return; #endif if (lastUpdateCheck != -1) { if (lastUpdateCheck == 0) { const bool checkRegularly = showQuestionDlg(parent, ReturnQuestionDlg::BUTTON_YES | ReturnQuestionDlg::BUTTON_NO, _("Do you want FreeFileSync to automatically check for updates every week?") + L"\n" + _("(Requires an Internet connection!)")) == ReturnQuestionDlg::BUTTON_YES; if (checkRegularly) { lastUpdateCheck = 123; //some old date (few seconds after 1970) checkForUpdatePeriodically(parent, lastUpdateCheck); //check for updates now } else lastUpdateCheck = -1; //don't check for updates anymore } else if (wxGetLocalTime() >= lastUpdateCheck + 7 * 24 * 3600) //check weekly { wxString onlineVersion; if (!getOnlineVersion(onlineVersion)) return; //do not handle error lastUpdateCheck = wxGetLocalTime(); if (newerVersionExists(onlineVersion)) { const int rv = wxMessageBox(_("A newer version of FreeFileSync is available:") + L" v" + onlineVersion + L". " + _("Download now?"), _("Information"), wxYES_NO | wxICON_QUESTION, parent); if (rv == wxYES) wxLaunchDefaultBrowser(wxString(L"http://sourceforge.net/projects/freefilesync/files/freefilesync/v") + onlineVersion + L"/"); } } } }