Exemplo n.º 1
0
        /// <summary>
        ///     check codeplex's rss feed to see if we have a new release available.
        /// </summary>
        private static void CheckForNewRelease(CommandLineArgs commandLineArgs, bool forceCheck = false)
        {
            if (forceCheck == false)
            {
                if (!Settings.CheckForNewRelease)
                {
                    Log.Debug("The user has choosen to deny Terminals the update check.");
                    return;
                }
            }

            Boolean checkForUpdate = true;
            string  releaseFile    = Path.Combine(AssemblyInfo.DirectoryConfigFiles, "LastUpdateCheck.txt");

            if (File.Exists(releaseFile))
            {
                string text = null;
                using (FileStream fs = new FileStream(releaseFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite & FileShare.Delete))
                {
                    using (StreamReader stream = new StreamReader(fs))
                    {
                        text = stream.ReadToEnd().Trim();;
                    }
                }

                if (text != String.Empty)
                {
                    DateTime lastUpdate = DateTime.MinValue;
                    if (DateTime.TryParse(text, out lastUpdate))
                    {
                        //don't run the update if the file is today or later .. if we have checked today or not
                        if (lastUpdate.Date >= DateTime.Now.Date)
                        {
                            Log.Debug("No need to check for a new Terminals release. The release has already been checked recently.");
                            checkForUpdate = false;
                        }
                    }
                }
            }

            if (checkForUpdate)
            {
                Log.Debug("Start to check for a new Terminals release.");

                try
                {
                    Log.Debug("Connecting to the internet to github.com to check if a new Terminals version is available.");

                    XmlReader responseReader = XmlReader.Create(Configuration.Url.GitHubReleasesFeed);

                    Log.Debug("Loading syndication feed.");

                    SyndicationFeed feed = SyndicationFeed.Load(responseReader);

                    // Only the first element would be enough normally - but to be sure
                    // check all of the releases
                    foreach (SyndicationItem item in feed.Items)
                    {
                        // Don't check this release - it's deprecated
                        if (item.Title.Text.ToUpperInvariant().Contains("DEPRECATED"))
                        {
                            continue;
                        }

                        // Don't check this release - it's broken
                        if (item.Title.Text.ToUpperInvariant().Contains("BROKEN"))
                        {
                            continue;
                        }

                        string         title    = item.Title.Text;
                        string         version  = title.Replace("Terminals", "").Trim();
                        DateTimeOffset feedDate = item.LastUpdatedTime;

                        Log.Debug("Release '" + title + "' has been discovered.");

                        try
                        {
                            feedDate = Convert.ToDateTime(Web.HTTPAsString(string.Format(Configuration.Url.GitHubLatestRelease_Binary, version).Replace("Terminals.zip", "TerminalsBuildDate")).Replace("?", ""));
                            Log.Info("Received release date \"" + feedDate.ToString() + "\" from the TerminalsBuildDate file stored on GitHub in " + title);
                        }
                        catch (Exception ex)
                        {
                            Log.Debug("Unable to get the release date from the TerminalsBuildDate file stored on GitHub in " + title + ". Using the syndication feed date.", ex);
                        }

                        //check the date the item was build (stored in TerminalsBuildDate), if not available check when it has been published (date in syndication feed).
                        // If the build date is old than the feed date, then it's probably a new build!
                        if (new Version(version) >= AssemblyInfo.Version && feedDate > AssemblyInfo.BuildDate)
                        {
                            dynamic content = item.Content;

                            // Skip prereleases if we aren't already on a prerelease of the same version
                            if (AssemblyInfo.Version < new Version(version) && content.Text.ToLowerInvariant().Contains("this is just a preview"))
                            {
                                continue;
                            }

                            Log.Debug("Release '" + title + "'(" + feedDate.ToString() + ") is newer than the currently installed Terminals version '" + AssemblyInfo.Version + "'(" + AssemblyInfo.BuildDate.ToString() + ").");

                            FormsExtensions.InvokeIfNecessary(Invoker, () => { MainForm.ReleaseAvailable = true; MainForm.ReleaseDescription = title; });

                            Settings.UpdateSource = string.Format(Configuration.Url.GitHubLatestRelease_Binary, version);
                            commandLineArgs.AutomaticallyUpdate = true;
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Warn("Unable to check for a new Terminals version on " + Configuration.Url.GitHubRepositry, ex);
                }

                File.WriteAllText(releaseFile, DateTime.Now.ToString());
            }
        }
Exemplo n.º 2
0
 private static string Download(String Url)
 {
     return(Web.HTTPAsString(Url));
 }
Exemplo n.º 3
0
 private static bool DownloadNewBuild(String Url, String Filename)
 {
     Log.Info("Downloading new Terminals release \"" + Url + "\" to \"" + Filename + "\"");
     return(Web.SaveHTTPToFile(Url, Filename));
 }
Exemplo n.º 4
0
 private static bool DownloadNewBuild(String Url, String Filename)
 {
     return(Web.SaveHTTPToFile(Url, Filename));
 }