BUG-1850: minimizing the impact of SF down

This commit is contained in:
RKrom 2015-11-07 23:05:17 +01:00
parent 3ccc1c0f9f
commit c2b0bb98b4
2 changed files with 24 additions and 20 deletions

View file

@ -34,21 +34,20 @@ namespace Greenshot.Experimental {
/// Description of RssFeedHelper. /// Description of RssFeedHelper.
/// </summary> /// </summary>
public static class UpdateHelper { public static class UpdateHelper {
private static ILog LOG = LogManager.GetLogger(typeof(UpdateHelper)); private static readonly ILog LOG = LogManager.GetLogger(typeof(UpdateHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private const string STABLE_DOWNLOAD_LINK = "http://getgreenshot.org/downloads/"; private const string STABLE_DOWNLOAD_LINK = "http://getgreenshot.org/downloads/";
private const string VERSION_HISTORY_LINK = "http://getgreenshot.org/version-history/"; private const string VERSION_HISTORY_LINK = "http://getgreenshot.org/version-history/";
private static object lockObject = new object(); private static readonly object LockObject = new object();
private static SourceforgeFile latestGreenshot; private static SourceforgeFile _latestGreenshot;
private static SourceforgeFile currentGreenshot; private static string _downloadLink = STABLE_DOWNLOAD_LINK;
private static string downloadLink = STABLE_DOWNLOAD_LINK;
/// <summary> /// <summary>
/// Is an update check needed? /// Is an update check needed?
/// </summary> /// </summary>
/// <returns>bool true if yes</returns> /// <returns>bool true if yes</returns>
public static bool IsUpdateCheckNeeded() { public static bool IsUpdateCheckNeeded() {
lock (lockObject) { lock (LockObject) {
if (conf.UpdateCheckInterval == 0) { if (conf.UpdateCheckInterval == 0) {
return false; return false;
} }
@ -60,7 +59,7 @@ namespace Greenshot.Experimental {
return false; 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); 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)) { if (!SourceForgeHelper.IsRSSModifiedAfter(conf.LastUpdateCheck)) {
LOG.DebugFormat("RSS feed has not been updated since after {0}", conf.LastUpdateCheck); LOG.DebugFormat("RSS feed has not been updated since after {0}", conf.LastUpdateCheck);
return false; return false;
} }
@ -73,18 +72,18 @@ namespace Greenshot.Experimental {
/// Read the RSS feed to see if there is a Greenshot update /// Read the RSS feed to see if there is a Greenshot update
/// </summary> /// </summary>
public static void CheckAndAskForUpdate() { public static void CheckAndAskForUpdate() {
lock (lockObject) { lock (LockObject) {
Version currentVersion = Assembly.GetExecutingAssembly().GetName().Version; Version currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
// Test like this: // Test like this:
// currentVersion = new Version("0.8.1.1198"); // currentVersion = new Version("0.8.1.1198");
try { try {
latestGreenshot = null; _latestGreenshot = null;
ProcessRSSInfo(currentVersion); ProcessRSSInfo(currentVersion);
if (latestGreenshot != null) { if (_latestGreenshot != null) {
MainForm.Instance.NotifyIcon.BalloonTipClicked += HandleBalloonTipClick; MainForm.Instance.NotifyIcon.BalloonTipClicked += HandleBalloonTipClick;
MainForm.Instance.NotifyIcon.BalloonTipClosed += CleanupBalloonTipClick; MainForm.Instance.NotifyIcon.BalloonTipClosed += CleanupBalloonTipClick;
MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", Language.GetFormattedString(LangKey.update_found, "'" + latestGreenshot.File + "'"), ToolTipIcon.Info); MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", Language.GetFormattedString(LangKey.update_found, "'" + _latestGreenshot.File + "'"), ToolTipIcon.Info);
} }
conf.LastUpdateCheck = DateTime.Now; conf.LastUpdateCheck = DateTime.Now;
} catch (Exception e) { } catch (Exception e) {
@ -100,14 +99,14 @@ namespace Greenshot.Experimental {
private static void HandleBalloonTipClick(object sender, EventArgs e) { private static void HandleBalloonTipClick(object sender, EventArgs e) {
try { try {
if (latestGreenshot != null) { if (_latestGreenshot != null) {
// "Direct" download link // "Direct" download link
// Process.Start(latestGreenshot.Link); // Process.Start(latestGreenshot.Link);
// Go to getgreenshot.org // Go to getgreenshot.org
Process.Start(downloadLink); Process.Start(_downloadLink);
} }
} catch (Exception) { } catch (Exception) {
MessageBox.Show(Language.GetFormattedString(LangKey.error_openlink, downloadLink), Language.GetString(LangKey.error)); MessageBox.Show(Language.GetFormattedString(LangKey.error_openlink, _downloadLink), Language.GetString(LangKey.error));
} finally { } finally {
CleanupBalloonTipClick(sender, e); CleanupBalloonTipClick(sender, e);
} }
@ -158,18 +157,17 @@ namespace Greenshot.Experimental {
int versionCompare = rssFile.Version.CompareTo(currentVersion); int versionCompare = rssFile.Version.CompareTo(currentVersion);
if (versionCompare > 0) { if (versionCompare > 0) {
LOG.DebugFormat("Found newer Greenshot '{0}' with version {1} published at {2} : {3}", file, rssFile.Version, rssFile.Pubdate.ToLocalTime(), rssFile.Link); LOG.DebugFormat("Found newer Greenshot '{0}' with version {1} published at {2} : {3}", file, rssFile.Version, rssFile.Pubdate.ToLocalTime(), rssFile.Link);
if (latestGreenshot == null || rssFile.Version.CompareTo(latestGreenshot.Version) > 0) { if (_latestGreenshot == null || rssFile.Version.CompareTo(_latestGreenshot.Version) > 0) {
latestGreenshot = rssFile; _latestGreenshot = rssFile;
if (rssFile.isReleaseCandidate || rssFile.isUnstable) { if (rssFile.isReleaseCandidate || rssFile.isUnstable) {
downloadLink = VERSION_HISTORY_LINK; _downloadLink = VERSION_HISTORY_LINK;
} else { } else {
downloadLink = STABLE_DOWNLOAD_LINK; _downloadLink = STABLE_DOWNLOAD_LINK;
} }
} }
} else if (versionCompare < 0) { } else if (versionCompare < 0) {
LOG.DebugFormat("Skipping older greenshot with version {0}", rssFile.Version); LOG.DebugFormat("Skipping older greenshot with version {0}", rssFile.Version);
} else if (versionCompare == 0) { } else if (versionCompare == 0) {
currentGreenshot = rssFile;
LOG.DebugFormat("Found current version as exe {0} with version {1} published at {2} : {3}", file, rssFile.Version, rssFile.Pubdate.ToLocalTime(), rssFile.Link); LOG.DebugFormat("Found current version as exe {0} with version {1} published at {2} : {3}", file, rssFile.Version, rssFile.Pubdate.ToLocalTime(), rssFile.Link);
} }
} }

View file

@ -104,8 +104,14 @@ namespace GreenshotPlugin.Core {
/// </summary> /// </summary>
/// <param name="updateTime">DateTime</param> /// <param name="updateTime">DateTime</param>
/// <returns>true if the feed is newer</returns> /// <returns>true if the feed is newer</returns>
public static bool isRSSModifiedAfter(DateTime updateTime) { public static bool IsRSSModifiedAfter(DateTime updateTime) {
DateTime lastModified = NetworkHelper.GetLastModified(new Uri(RSSFEED)); DateTime lastModified = NetworkHelper.GetLastModified(new Uri(RSSFEED));
if (lastModified == DateTime.MinValue)
{
// Time could not be read, just take now and add one hour to it.
// This assist BUG-1850
lastModified = DateTime.Now.AddHours(1);
}
return updateTime.CompareTo(lastModified) < 0; return updateTime.CompareTo(lastModified) < 0;
} }