diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:57:03 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:57:03 +0200 |
commit | 420fb6c9b3427f65cfe24411944ee46b58cfcfb4 (patch) | |
tree | 58269ba5ee7a22d2df004f03b100cc234b8c3f14 /ui/checkVersion.cpp | |
parent | 1.16 (diff) | |
download | FreeFileSync-420fb6c9b3427f65cfe24411944ee46b58cfcfb4.tar.gz FreeFileSync-420fb6c9b3427f65cfe24411944ee46b58cfcfb4.tar.bz2 FreeFileSync-420fb6c9b3427f65cfe24411944ee46b58cfcfb4.zip |
1.17
Diffstat (limited to 'ui/checkVersion.cpp')
-rw-r--r-- | ui/checkVersion.cpp | 70 |
1 files changed, 70 insertions, 0 deletions
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 <wx/protocol/http.h> +#include <wx/sstream.h> +#include "../version/version.h" +#include <wx/msgdlg.h> +#include <wx/utils.h> + + +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); +} |