Ejemplo n.º 1
0
        /// <summary>
        /// Read the RSS feed to see if there is a Greenshot update
        /// </summary>
        public static void CheckAndAskForUpdate()
        {
            lock (LockObject) {
                Version currentVersion = Assembly.GetExecutingAssembly().GetName().Version;
                // Test like this:
                // currentVersion = new Version("0.8.1.1198");

                try {
                    _latestGreenshot = null;
                    ProcessRSSInfo(currentVersion);
                    if (_latestGreenshot != null)
                    {
                        MainForm.Instance.NotifyIcon.BalloonTipClicked += HandleBalloonTipClick;
                        MainForm.Instance.NotifyIcon.BalloonTipClosed  += CleanupBalloonTipClick;
                        MainForm.Instance.NotifyIcon.ShowBalloonTip(10000, "Greenshot", Language.GetFormattedString(LangKey.update_found, "'" + _latestGreenshot.File + "'"), ToolTipIcon.Info);
                    }
                    conf.LastUpdateCheck = DateTime.Now;
                } catch (Exception e) {
                    LOG.Error("An error occured while checking for updates, the error will be ignored: ", e);
                }
            }
        }
Ejemplo n.º 2
0
        private static void ProcessRSSInfo(Version currentVersion)
        {
            // Reset latest Greenshot
            Dictionary <string, Dictionary <string, SourceforgeFile> > rssFiles = SourceForgeHelper.readRSS();

            if (rssFiles == null)
            {
                return;
            }

            // Retrieve the current and latest greenshot
            foreach (string fileType in rssFiles.Keys)
            {
                foreach (string file in rssFiles[fileType].Keys)
                {
                    SourceforgeFile rssFile = rssFiles[fileType][file];
                    if (fileType.StartsWith("Greenshot"))
                    {
                        // check for exe
                        if (rssFile.File == null || !rssFile.File.EndsWith(".exe"))
                        {
                            continue;
                        }
                        // Check if non stable
                        if (!conf.CheckUnstable && rssFile.File.ToLower().Contains("unstable"))
                        {
                            continue;
                        }
                        if (rssFile.Version == null)
                        {
                            LOG.DebugFormat("Skipping unversioned exe {0} with published at {1} : {2}", file, rssFile.Pubdate.ToLocalTime(), rssFile.Link);
                            continue;
                        }
                        int versionCompare = rssFile.Version.CompareTo(currentVersion);
                        if (versionCompare > 0)
                        {
                            LOG.DebugFormat("Found newer version as exe {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)
                            {
                                latestGreenshot = rssFile;
                            }
                        }
                        else if (versionCompare < 0)
                        {
                            LOG.DebugFormat("Skipping older greenshot with version {0}", rssFile.Version);
                        }
                        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);
                        }
                    }
                }
            }

            //			// check for language file updates
            //			// Directory to store the language files
            //			string languageFilePath = Path.GetDirectoryName(Language.GetInstance().GetHelpFilePath());
            //			LOG.DebugFormat("Language file path: {0}", languageFilePath);
            //			foreach(string fileType in rssFiles.Keys) {
            //				foreach(string file in rssFiles[fileType].Keys) {
            //					RssFile rssFile = rssFiles[fileType][file];
            //					if (fileType.Equals("Translations")) {
            //						LOG.DebugFormat("Found translation {0} with language {1} published at {2} : {3}", file, rssFile.Language, rssFile.Pubdate.ToLocalTime(), rssFile.Link);
            //						string languageFile = Path.Combine(languageFilePath, file);
            //						if (!File.Exists(languageFile)) {
            //							LOG.DebugFormat("Found not installed language: {0}", rssFile.Language);
            //							// Example to download language files
            //							//string languageFileContent = GreenshotPlugin.Core.NetworkHelper.DownloadFileAsString(new Uri(rssFile.Link), Encoding.UTF8);
            //							//TextWriter writer = new StreamWriter(languageFile, false, Encoding.UTF8);
            //							//LOG.InfoFormat("Writing {0}", languageFile);
            //							//writer.Write(languageFileContent);
            //							//writer.Close();
            //						}
            //					}
            //				}
            //			}
        }
Ejemplo n.º 3
0
        private static void ProcessRSSInfo(Version currentVersion)
        {
            // Reset latest Greenshot
            Dictionary <string, Dictionary <string, SourceforgeFile> > rssFiles = SourceForgeHelper.readRSS();

            if (rssFiles == null)
            {
                return;
            }

            // Retrieve the current and latest greenshot
            foreach (string fileType in rssFiles.Keys)
            {
                foreach (string file in rssFiles[fileType].Keys)
                {
                    SourceforgeFile rssFile = rssFiles[fileType][file];
                    if (fileType.StartsWith("Greenshot"))
                    {
                        // check for exe
                        if (!rssFile.isExe)
                        {
                            continue;
                        }

                        // do we have a version?
                        if (rssFile.Version == null)
                        {
                            LOG.DebugFormat("Skipping unversioned exe {0} which is published at {1} : {2}", file, rssFile.Pubdate.ToLocalTime(), rssFile.Link);
                            continue;
                        }

                        // if the file is unstable, we will skip it when:
                        // the current version is a release or release candidate AND check unstable is turned off.
                        if (rssFile.isUnstable)
                        {
                            // Skip if we shouldn't check unstables
                            if ((conf.BuildState == BuildStates.RELEASE) && !conf.CheckForUnstable)
                            {
                                continue;
                            }
                        }

                        // if the file is a release candidate, we will skip it when:
                        // the current version is a release AND check unstable is turned off.
                        if (rssFile.isReleaseCandidate)
                        {
                            if (conf.BuildState == BuildStates.RELEASE && !conf.CheckForUnstable)
                            {
                                continue;
                            }
                        }

                        // Compare versions
                        int versionCompare = rssFile.Version.CompareTo(currentVersion);
                        if (versionCompare > 0)
                        {
                            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)
                            {
                                _latestGreenshot = rssFile;
                                if (rssFile.isReleaseCandidate || rssFile.isUnstable)
                                {
                                    _downloadLink = VERSION_HISTORY_LINK;
                                }
                                else
                                {
                                    _downloadLink = STABLE_DOWNLOAD_LINK;
                                }
                            }
                        }
                        else if (versionCompare < 0)
                        {
                            LOG.DebugFormat("Skipping older greenshot with version {0}", rssFile.Version);
                        }
                        else if (versionCompare == 0)
                        {
                            LOG.DebugFormat("Found current version as exe {0} with version {1} published at {2} : {3}", file, rssFile.Version, rssFile.Pubdate.ToLocalTime(), rssFile.Link);
                        }
                    }
                }
            }

//			// check for language file updates
//			// Directory to store the language files
//			string languageFilePath = Path.GetDirectoryName(Language.GetInstance().GetHelpFilePath());
//			LOG.DebugFormat("Language file path: {0}", languageFilePath);
//			foreach(string fileType in rssFiles.Keys) {
//				foreach(string file in rssFiles[fileType].Keys) {
//					RssFile rssFile = rssFiles[fileType][file];
//					if (fileType.Equals("Translations")) {
//						LOG.DebugFormat("Found translation {0} with language {1} published at {2} : {3}", file, rssFile.Language, rssFile.Pubdate.ToLocalTime(), rssFile.Link);
//						string languageFile = Path.Combine(languageFilePath, file);
//						if (!File.Exists(languageFile)) {
//							LOG.DebugFormat("Found not installed language: {0}", rssFile.Language);
//							// Example to download language files
//							//string languageFileContent = GreenshotPlugin.Core.NetworkHelper.DownloadFileAsString(new Uri(rssFile.Link), Encoding.UTF8);
//							//TextWriter writer = new StreamWriter(languageFile, false, Encoding.UTF8);
//							//LOG.InfoFormat("Writing {0}", languageFile);
//							//writer.Write(languageFileContent);
//							//writer.Close();
//						}
//					}
//				}
//			}
        }