diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:57:45 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 16:57:45 +0200 |
commit | 2a3ebac62eb6dd88122c0f447ea90ce368373d3a (patch) | |
tree | fae5c18deaecfb6f39d4d66dd3de8ce730b2025b /ui/checkVersion.cpp | |
parent | 1.17 (diff) | |
download | FreeFileSync-2a3ebac62eb6dd88122c0f447ea90ce368373d3a.tar.gz FreeFileSync-2a3ebac62eb6dd88122c0f447ea90ce368373d3a.tar.bz2 FreeFileSync-2a3ebac62eb6dd88122c0f447ea90ce368373d3a.zip |
1.18
Diffstat (limited to 'ui/checkVersion.cpp')
-rw-r--r-- | ui/checkVersion.cpp | 94 |
1 files changed, 80 insertions, 14 deletions
diff --git a/ui/checkVersion.cpp b/ui/checkVersion.cpp index 5344b45e..914e5e09 100644 --- a/ui/checkVersion.cpp +++ b/ui/checkVersion.cpp @@ -5,6 +5,8 @@ #include "../version/version.h" #include <wx/msgdlg.h> #include <wx/utils.h> +#include <wx/timer.h> +#include "../library/globalFunctions.h" class CloseConnectionOnExit @@ -26,7 +28,7 @@ private: }; -void FreeFileSync::checkForNewVersion() +bool getOnlineVersion(wxString& version) { wxHTTP webAccess; wxInputStream* httpStream = NULL; @@ -50,21 +52,85 @@ void FreeFileSync::checkForNewVersion() 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; - } + version = newestVersion; + return true; } } } - wxMessageBox(_("Unable to connect to sourceforge.net!"), _("Error"), wxOK | wxICON_ERROR); + return false; } + + +bool newerVersionExists(const wxString& onlineVersion) +{ + const wxString currentMajor = FreeFileSync::currentVersion.BeforeLast(wxT('.')); + const wxString onlineMajor = onlineVersion.BeforeLast(wxT('.')); + + if (currentMajor != onlineMajor) + return globalFunctions::wxStringToInt(currentMajor) < globalFunctions::wxStringToInt(onlineMajor); + + const wxString currentMinor = FreeFileSync::currentVersion.AfterLast(wxT('.')); + const wxString onlineMinor = onlineVersion.AfterLast(wxT('.')); + + return globalFunctions::wxStringToInt(currentMinor) < globalFunctions::wxStringToInt(onlineMinor); +} + + +void FreeFileSync::checkForUpdateNow() +{ + wxString onlineVersion; + if (!getOnlineVersion(onlineVersion)) + { + wxMessageBox(_("Unable to connect to sourceforge.net!"), _("Error"), wxOK | wxICON_ERROR); + return; + } + + if (newerVersionExists(onlineVersion)) + { + const int rv = wxMessageBox(wxString(_("A newer version of FreeFileSync is available:")) + wxT(" v") + onlineVersion + wxT(". ") + _("Download now?"), _("Information"), wxYES_NO | wxICON_QUESTION); + if (rv == wxYES) + wxLaunchDefaultBrowser(wxT("http://sourceforge.net/project/showfiles.php?group_id=234430")); + } + else + wxMessageBox(_("FreeFileSync is up to date!"), _("Information"), wxICON_INFORMATION); +} + + +void FreeFileSync::checkForUpdatePeriodically(long& lastUpdateCheck) +{ + if (lastUpdateCheck != -1) + { + if (lastUpdateCheck == 0) + { + const int rv = wxMessageBox(_("Do you want FreeFileSync to automatically check for updates every week?"), _("Information"), wxYES_NO | wxICON_QUESTION); + if (rv == wxYES) + { + lastUpdateCheck = 123; //some old date (few seconds after 1970) + + checkForUpdatePeriodically(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(wxString(_("A newer version of FreeFileSync is available:")) + wxT(" v") + onlineVersion + wxT(". ") + _("Download now?"), _("Information"), wxYES_NO | wxICON_QUESTION); + if (rv == wxYES) + wxLaunchDefaultBrowser(wxT("http://sourceforge.net/project/showfiles.php?group_id=234430")); + } + } + } +} + + + + |