#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); }