summaryrefslogtreecommitdiff
path: root/ui/checkVersion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ui/checkVersion.cpp')
-rw-r--r--ui/checkVersion.cpp70
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);
+}
bgstack15