From c6d6431a81431c17e64a407437dc68da923f88eb Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 14 Nov 2014 10:45:45 +0100 Subject: [PATCH] For 1.2 RC3 I modified the update check so that it first retrieves the last modified date of the project feed (HTTP HEAD method), if the date is newer than the last check than it will download the feed. This should reduce the amount of traffic on our website. [skip ci] --- Greenshot/Helpers/UpdateHelper.cs | 4 ++++ .../additional_files/readme.txt.template | 10 +++++++++ GreenshotPlugin/Core/CoreConfiguration.cs | 8 +++++-- GreenshotPlugin/Core/NetworkHelper.cs | 21 +++++++++++++++++++ GreenshotPlugin/Core/SourceForgeHelper.cs | 10 +++++++++ 5 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Greenshot/Helpers/UpdateHelper.cs b/Greenshot/Helpers/UpdateHelper.cs index 6c8d2b178..3623c6c87 100644 --- a/Greenshot/Helpers/UpdateHelper.cs +++ b/Greenshot/Helpers/UpdateHelper.cs @@ -60,6 +60,10 @@ namespace Greenshot.Experimental { return false; } LOG.DebugFormat("Update check is due, last check was {0} check needs to be made after {1} (which is one {2} later)", conf.LastUpdateCheck, checkTime, conf.UpdateCheckInterval); + if (!SourceForgeHelper.isRSSModifiedAfter(conf.LastUpdateCheck)) { + LOG.DebugFormat("RSS feed has not been updated since after {0}", conf.LastUpdateCheck); + return false; + } } } return true; diff --git a/Greenshot/releases/additional_files/readme.txt.template b/Greenshot/releases/additional_files/readme.txt.template index 471a5bc84..d1a91f9a3 100644 --- a/Greenshot/releases/additional_files/readme.txt.template +++ b/Greenshot/releases/additional_files/readme.txt.template @@ -7,6 +7,16 @@ CHANGE LOG: @DETAILVERSION@ +Features: + +Changes: + +Bugs Resolved: + + + +1.2.2.43-380f581 RC2 + Features: * Added the possibility to select the region to capture by using the keyboard, use the cursor keys to move the cursor (ctrl-key speeds up the movement) and the enter key to mark the start and ending. * FEATURE-757: Greenshot will now store the last used region in the greenshot.ini, which makes it also available after a restart. diff --git a/GreenshotPlugin/Core/CoreConfiguration.cs b/GreenshotPlugin/Core/CoreConfiguration.cs index 535c581f3..81a958758 100644 --- a/GreenshotPlugin/Core/CoreConfiguration.cs +++ b/GreenshotPlugin/Core/CoreConfiguration.cs @@ -410,8 +410,12 @@ namespace GreenshotPlugin.Core { // CheckForUnstable = true; if (string.IsNullOrEmpty(LastSaveWithVersion)) { - // Store version, this can be used later to fix settings after an update - LastSaveWithVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); + try { + // Store version, this can be used later to fix settings after an update + LastSaveWithVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); + } catch { + + } // Disable the AutoReduceColors as it causes issues with Mozzila applications and some others OutputFileAutoReduceColors = false; } diff --git a/GreenshotPlugin/Core/NetworkHelper.cs b/GreenshotPlugin/Core/NetworkHelper.cs index 8599e66d3..101ca3582 100644 --- a/GreenshotPlugin/Core/NetworkHelper.cs +++ b/GreenshotPlugin/Core/NetworkHelper.cs @@ -336,6 +336,27 @@ namespace GreenshotPlugin.Core { return responseData; } + + /// + /// Get LastModified for a URI + /// + /// Uri + /// DateTime + public static DateTime GetLastModified(Uri uri) { + HttpWebRequest webRequest; + try { + webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(uri); + webRequest.Method = "HEAD"; + HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); + LOG.DebugFormat("RSS feed was updated at {0}", webResponse.LastModified); + return webResponse.LastModified; + } catch (Exception wE) { + LOG.WarnFormat("Problem requesting HTTP - HEAD on uri {0}", uri); + LOG.Warn(wE.Message); + // Pretend it is old + return DateTime.MinValue; + } + } } /// diff --git a/GreenshotPlugin/Core/SourceForgeHelper.cs b/GreenshotPlugin/Core/SourceForgeHelper.cs index 49ca5041c..c3800d27e 100644 --- a/GreenshotPlugin/Core/SourceForgeHelper.cs +++ b/GreenshotPlugin/Core/SourceForgeHelper.cs @@ -98,6 +98,16 @@ namespace GreenshotPlugin.Core { private static ILog LOG = LogManager.GetLogger(typeof(SourceForgeHelper)); private const String RSSFEED = "http://getgreenshot.org/project-feed/"; + /// + /// This is using the HTTP HEAD Method to check if the RSS Feed is modified after the supplied date + /// + /// DateTime + /// true if the feed is newer + public static bool isRSSModifiedAfter(DateTime updateTime) { + DateTime lastModified = NetworkHelper.GetLastModified(new Uri(RSSFEED)); + return updateTime.CompareTo(lastModified) < 0; + } + /// /// Read the Greenshot RSS feed, so we can use this information to check for updates ///