/// <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); } } }
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(); // } // } // } // } }
/// <summary> /// Read the Greenshot RSS feed, so we can use this information to check for updates /// </summary> /// <returns>Dictionary<string, Dictionary<string, RssFile>> with files and their RssFile "description"</returns> public static Dictionary <string, Dictionary <string, SourceforgeFile> > readRSS() { XmlDocument rssDoc = new XmlDocument(); try { HttpWebRequest webRequest = NetworkHelper.CreateWebRequest(RSSFEED); XmlTextReader rssReader = new XmlTextReader(webRequest.GetResponse().GetResponseStream()); // Load the XML content into a XmlDocument rssDoc.Load(rssReader); } catch (Exception wE) { LOG.WarnFormat("Problem reading RSS from {0}", RSSFEED); LOG.Warn(wE.Message); return(null); } // Loop for the <rss> tag XmlNode nodeRss = null; for (int i = 0; i < rssDoc.ChildNodes.Count; i++) { // If it is the rss tag if (rssDoc.ChildNodes[i].Name == "rss") { // <rss> tag found nodeRss = rssDoc.ChildNodes[i]; } } if (nodeRss == null) { LOG.Debug("No RSS Feed!"); return(null); } // Loop for the <channel> tag XmlNode nodeChannel = null; for (int i = 0; i < nodeRss.ChildNodes.Count; i++) { // If it is the channel tag if (nodeRss.ChildNodes[i].Name == "channel") { // <channel> tag found nodeChannel = nodeRss.ChildNodes[i]; } } if (nodeChannel == null) { LOG.Debug("No channel in RSS feed!"); return(null); } Dictionary <string, Dictionary <string, SourceforgeFile> > rssFiles = new Dictionary <string, Dictionary <string, SourceforgeFile> >(); // Loop for the <title>, <link>, <description> and all the other tags for (int i = 0; i < nodeChannel.ChildNodes.Count; i++) { // If it is the item tag, then it has children tags which we will add as items to the ListView if (nodeChannel.ChildNodes[i].Name == "item") { XmlNode nodeItem = nodeChannel.ChildNodes[i]; string sfLink = nodeItem["link"].InnerText; string pubdate = nodeItem["pubDate"].InnerText; try { Match match = Regex.Match(Uri.UnescapeDataString(sfLink), @"^http.*sourceforge.*\/projects\/([^\/]+)\/files\/([^\/]+)\/([^\/]+)\/(.+)\/download$"); if (match.Success) { string project = match.Groups[1].Value; string subdir = match.Groups[2].Value; string type = match.Groups[3].Value; string file = match.Groups[4].Value; // !!! Change this to the mirror !!! string mirror = "kent"; string directLink = Uri.EscapeUriString("http://" + mirror + ".dl.sourceforge.net/project/" + project + "/" + subdir + "/" + type + "/" + file); Dictionary <string, SourceforgeFile> filesForType; if (rssFiles.ContainsKey(type)) { filesForType = rssFiles[type]; } else { filesForType = new Dictionary <string, SourceforgeFile>(); rssFiles.Add(type, filesForType); } SourceforgeFile rssFile = new SourceforgeFile(file, pubdate, sfLink, directLink); if (file.EndsWith(".exe") || file.EndsWith(".zip")) { string version = Regex.Replace(file, @".*[a-zA-Z_]\-", ""); version = version.Replace(@"\-[a-zA-Z]+.*", ""); version = Regex.Replace(version, @"\.exe$", ""); version = Regex.Replace(version, @"\.zip$", ""); version = Regex.Replace(version, @"RC[0-9]+", ""); if (version.Trim().Length > 0) { version = version.Replace('-', '.'); version = version.Replace(',', '.'); version = Regex.Replace(version, @"^[a-zA-Z_]*\.", ""); version = Regex.Replace(version, @"\.[a-zA-Z_]*$", ""); try { rssFile.Version = new Version(version); } catch (Exception) { LOG.DebugFormat("Found invalid version {0} in file {1}", version, file); } } } else if (type.Equals("Translations")) { string culture = Regex.Replace(file, @"[a-zA-Z]+-(..-..)\.(xml|html)", "$1"); try { //CultureInfo cultureInfo = new CultureInfo(culture); rssFile.Language = culture; //cultureInfo.NativeName; } catch (Exception) { LOG.WarnFormat("Can't read the native name of the culture {0}", culture); } } filesForType.Add(file, rssFile); } } catch (Exception ex) { LOG.WarnFormat("Couldn't read RSS entry for: {0}", nodeChannel["title"].InnerText); LOG.Warn("Reason: ", ex); } } } return(rssFiles); }
/// <summary> /// Read the Greenshot RSS feed, so we can use this information to check for updates /// </summary> /// <returns>Dictionary<string, Dictionary<string, RssFile>> with files and their RssFile "description"</returns> public static Dictionary<string, Dictionary<string, SourceforgeFile>> readRSS() { HttpWebRequest webRequest; XmlDocument rssDoc = new XmlDocument(); try { webRequest = (HttpWebRequest)NetworkHelper.CreateWebRequest(RSSFEED); XmlTextReader rssReader = new XmlTextReader(webRequest.GetResponse().GetResponseStream()); // Load the XML content into a XmlDocument rssDoc.Load(rssReader); } catch (Exception wE) { LOG.WarnFormat("Problem reading RSS from {0}", RSSFEED); LOG.Warn(wE.Message); return null; } // Loop for the <rss> tag XmlNode nodeRss = null; for (int i = 0; i < rssDoc.ChildNodes.Count; i++) { // If it is the rss tag if (rssDoc.ChildNodes[i].Name == "rss") { // <rss> tag found nodeRss = rssDoc.ChildNodes[i]; } } if (nodeRss == null) { LOG.Debug("No RSS Feed!"); return null; } // Loop for the <channel> tag XmlNode nodeChannel = null; for (int i = 0; i < nodeRss.ChildNodes.Count; i++) { // If it is the channel tag if (nodeRss.ChildNodes[i].Name == "channel") { // <channel> tag found nodeChannel = nodeRss.ChildNodes[i]; } } if (nodeChannel == null) { LOG.Debug("No channel in RSS feed!"); return null; } Dictionary<string, Dictionary<string, SourceforgeFile>> rssFiles = new Dictionary<string, Dictionary<string, SourceforgeFile>>(); // Loop for the <title>, <link>, <description> and all the other tags for (int i = 0; i < nodeChannel.ChildNodes.Count; i++) { // If it is the item tag, then it has children tags which we will add as items to the ListView if (nodeChannel.ChildNodes[i].Name == "item") { XmlNode nodeItem = nodeChannel.ChildNodes[i]; string sfLink = nodeItem["link"].InnerText; string pubdate = nodeItem["pubDate"].InnerText; try { Match match= Regex.Match(Uri.UnescapeDataString(sfLink), @"^http.*sourceforge.*\/projects\/([^\/]+)\/files\/([^\/]+)\/([^\/]+)\/(.+)\/download$"); if (match.Success) { string project = match.Groups[1].Value; string subdir = match.Groups[2].Value; string type = match.Groups[3].Value; string file = match.Groups[4].Value; // !!! Change this to the mirror !!! string mirror = "kent"; string directLink = Uri.EscapeUriString("http://"+mirror+".dl.sourceforge.net/project/"+project+"/"+subdir+"/"+type+"/"+file); Dictionary<string, SourceforgeFile> filesForType; if (rssFiles.ContainsKey(type)) { filesForType = rssFiles[type]; } else { filesForType = new Dictionary<string, SourceforgeFile>(); rssFiles.Add(type, filesForType); } SourceforgeFile rssFile = new SourceforgeFile(file, pubdate, sfLink, directLink); if (file.EndsWith(".exe") ||file.EndsWith(".zip")) { string version = Regex.Replace(file, @".*[a-zA-Z_]\-", ""); version = version.Replace(@"\-[a-zA-Z]+.*",""); version = Regex.Replace(version, @"\.exe$", ""); version = Regex.Replace(version, @"\.zip$", ""); version = Regex.Replace(version, @"RC[0-9]+", ""); if (version.Trim().Length > 0) { version = version.Replace('-','.'); version = version.Replace(',','.'); version = Regex.Replace(version, @"^[a-zA-Z_]*\.", ""); version = Regex.Replace(version, @"\.[a-zA-Z_]*$", ""); try { rssFile.Version = new Version(version); } catch (Exception) { LOG.DebugFormat("Found invalid version {0} in file {1}", version, file); } } } else if (type.Equals("Translations")) { string culture = Regex.Replace(file, @"[a-zA-Z]+-(..-..)\.(xml|html)", "$1"); try { //CultureInfo cultureInfo = new CultureInfo(culture); rssFile.Language = culture;//cultureInfo.NativeName; } catch (Exception) { LOG.WarnFormat("Can't read the native name of the culture {0}", culture); } } filesForType.Add(file, rssFile); } } catch (Exception ex) { LOG.WarnFormat("Couldn't read RSS entry for: {0}", nodeChannel["title"].InnerText); LOG.Warn("Reason: ", ex); } } } return rssFiles; }
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) { 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(); // } // } // } // } }