From 420fb6c9b3427f65cfe24411944ee46b58cfcfb4 Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 16:57:03 +0200 Subject: 1.17 --- ui/checkVersion.cpp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 ui/checkVersion.cpp (limited to 'ui/checkVersion.cpp') diff --git a/ui/checkVersion.cpp b/ui/checkVersion.cpp new file mode 100644 index 00000000..5344b45e --- /dev/null +++ b/ui/checkVersion.cpp @@ -0,0 +1,70 @@ +#include "checkVersion.h" + +#include +#include +#include "../version/version.h" +#include +#include + + +class CloseConnectionOnExit +{ +public: + CloseConnectionOnExit(wxInputStream* httpStream, wxHTTP& webAccess) : + m_httpStream(httpStream), + m_webAccess(webAccess) {} + + ~CloseConnectionOnExit() + { + delete m_httpStream; //must be deleted BEFORE webAccess is closed + m_webAccess.Close(); + } + +private: + wxInputStream* m_httpStream; + wxHTTP& m_webAccess; +}; + + +void FreeFileSync::checkForNewVersion() +{ + wxHTTP webAccess; + wxInputStream* httpStream = NULL; + + wxWindowDisabler dummy; + CloseConnectionOnExit dummy2(httpStream, webAccess); + + webAccess.SetHeader(wxT("Content-type"), wxT("text/html; charset=utf-8")); + webAccess.SetTimeout(10); //10 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 + + httpStream = webAccess.GetInputStream(wxT("/viewvc/*checkout*/freefilesync/version/version.txt")); + + if (httpStream && webAccess.GetError() == wxPROTO_NOERR) + { + wxString newestVersion; + wxStringOutputStream out_stream(&newestVersion); + httpStream->Read(out_stream); + if (!newestVersion.empty()) + { + if (FreeFileSync::currentVersion == newestVersion) + { + wxMessageBox(_("FreeFileSync is up to date!"), _("Information"), wxICON_INFORMATION); + return; + } + else + { + const int rv = wxMessageBox(wxString(_("A newer version is available:")) + wxT(" v") + newestVersion + wxT(". ") + _("Download now?"), _("Information"), wxYES_NO | wxICON_QUESTION); + if (rv == wxYES) + wxLaunchDefaultBrowser(wxT("http://sourceforge.net/project/showfiles.php?group_id=234430")); + return; + } + } + } + } + + wxMessageBox(_("Unable to connect to sourceforge.net!"), _("Error"), wxOK | wxICON_ERROR); +} -- cgit