Esempio n. 1
0
        public AutoUpdateInfo CheckForUpdate()
        {
            try
            {
                WebRequest request = WebRequest.Create(iUpdateFeedLocation);
                request.Credentials = CredentialCache.DefaultCredentials;
                if (request.Proxy != null)
                {
                    request.Proxy.Credentials = CredentialCache.DefaultCredentials;
                }

                WebResponse response = request.GetResponse();

                using (Stream stream = response.GetResponseStream())
                {
                    ReleaseFeed feed = new ReleaseFeed(stream);

                    IReleaseJson update = feed.CheckForUpdate(iHelper.Version, iApplicationQuality, iApplicationTarget, Environment.OSVersion.Version.ToString(), DesiredQuality);

                    if (update != null)
                    {
                        UserLog.WriteLine(String.Format("{0} update available: {1}", update.Quality, update.Version));

                        return(new AutoUpdateInfo(iApplicationName,
                                                  update.Version,
                                                  feed.Json.History(),
                                                  update.UpdateUri(),
                                                  update.Quality(),
                                                  VersionSupport.Family(iHelper.Version) != VersionSupport.Family(update.Version)));
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                UserLog.WriteLine(String.Format("Error caught checking for updates: {0}", ex.ToString()));
            }

            return(null);
        }
Esempio n. 2
0
        public IReleaseJson CheckForUpdate(string aCurrentVersion, EReleaseQuality aCurrentQuality, string aCurrentPlatform, string aCurrentPlatformVersion, EReleaseQuality aDesiredQuality)
        {
            // select all releases that
            // - are for this platform
            // - have a min platform version that is less than or equal to this platform version
            // - have a quality that matches the desired quality
            var releases = Json.Releases.Where(r => r.Platform == aCurrentPlatform)
                           .Where(r => VersionSupport.ComparePartialVersions(aCurrentPlatformVersion, r.PlatformMinVersion) >= 0)
                           .Where(r => (r.Quality() & aDesiredQuality) == r.Quality());

            // select the release with the highest version for each release quality
            // - group by quality
            // - order releases in each group by ascending version
            // - select the last release in each group
            releases = releases.GroupBy(r => r.Quality())
                       .Select(g => g.OrderBy(r => r.Version, new VersionComparer()).Last());

            // pick the release with the highest version number and the highest quality (priority to version number)
            var release = releases.OrderBy(r => r.Version, new VersionComparer())
                          .ThenBy(r => r.Quality())
                          .LastOrDefault();

            if (release == null)
            {
                return(null);
            }

            // this version is a valid update if
            // - its version is greater than the current app version
            // - its version is the same as the current app version but its quality is greater than the current app quality
            // - its version is less than the current app version and the current app quality is not in the desired quality
            if (VersionSupport.ComparePartialVersions(release.Version, aCurrentVersion) > 0 ||
                (VersionSupport.ComparePartialVersions(release.Version, aCurrentVersion) == 0 && release.Quality() > aCurrentQuality) ||
                (VersionSupport.ComparePartialVersions(release.Version, aCurrentVersion) < 0 && (aCurrentQuality & aDesiredQuality) != aCurrentQuality))
            {
                return(release);
            }

            return(null);
        }
Esempio n. 3
0
        public AutoUpdateInfo CheckForUpdate()
        {
            WebResponse response = null;
            Stream      stream   = null;

            try
            {
                WebRequest request = WebRequest.Create(iUpdateFeedLocation);
                request.Credentials = CredentialCache.DefaultCredentials;
                if (request.Proxy != null)
                {
                    request.Proxy.Credentials = CredentialCache.DefaultCredentials;
                }
                response = request.GetResponse();
                stream   = response.GetResponseStream();

                XmlDocument       document = new XmlDocument();
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.XmlResolver = null;
                settings.ProhibitDtd = true;
                XmlReader xmlReader = XmlTextReader.Create(stream, settings);
                document.Load(xmlReader);

                XmlNamespaceManager xmlNsMan = new XmlNamespaceManager(document.NameTable);
                xmlNsMan.AddNamespace("ns", "urn:linn-co-uk/autoupdate");

                string latestVersion = iHelper.Version;
                string product       = iHelper.Product;

                AutoUpdateInfo result = null;

                KeyValuePair <EUpdateType, string>[] versionTypeNodeNames = new KeyValuePair <EUpdateType, string>[]
                {
                    new KeyValuePair <EUpdateType, string>(EUpdateType.Stable, "stable"),
                    new KeyValuePair <EUpdateType, string>(EUpdateType.Beta, "beta"),
                    new KeyValuePair <EUpdateType, string>(EUpdateType.Development, "development"),
                    new KeyValuePair <EUpdateType, string>(EUpdateType.Nightly, "nightly")
                };

                foreach (XmlNode applicationNode in document.SelectNodes(string.Format("/ns:autoupdate/ns:updateinfo[@version='{0}']/ns:application[@name='{1}']", iUpdateVersion, iApplicationName), xmlNsMan))
                {
                    Uri historyUri = new Uri(applicationNode.SelectSingleNode("ns:history", xmlNsMan).FirstChild.Value);

                    foreach (KeyValuePair <EUpdateType, string> versionType in versionTypeNodeNames)
                    {
                        if ((UpdateTypes & versionType.Key) == versionType.Key)
                        {
                            foreach (XmlNode versionNode in applicationNode.SelectNodes(string.Format("ns:{0}", versionType.Value), xmlNsMan))
                            {
                                string version = versionNode.Attributes["version"].Value;

                                if (VersionSupport.CompareVersions(version, latestVersion) > 0 ||
                                    (VersionSupport.CompareVersions(version, latestVersion) == 0 && versionType.Key > iApplicationBuildType))
                                {
                                    XmlNode uriNode = versionNode.SelectSingleNode(String.Format("ns:url[@target='{0}']", iApplicationTarget), xmlNsMan);
                                    if (uriNode != null)
                                    {
                                        UserLog.WriteLine(String.Format("{0} update available: {1}", versionType.Value, version));
                                        Uri uri = new Uri(uriNode.InnerText);
                                        result        = new AutoUpdateInfo(iApplicationName, version, historyUri, uri, versionType.Key, VersionSupport.Family(iHelper.Version) != VersionSupport.Family(version));
                                        latestVersion = version;
                                    }
                                }
                            }
                        }
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                UserLog.WriteLine(String.Format("Error caught checking for updates: {0}", ex.ToString()));
            }
            finally
            {
                if (response != null)
                {
                    response.Close();
                    response = null;
                }
                if (stream != null)
                {
                    stream.Close();
                    stream = null;
                }
            }

            return(null);
        }
Esempio n. 4
0
 public int Compare(string aVersionA, string aVersionB)
 {
     return VersionSupport.ComparePartialVersions(aVersionA, aVersionB);
 }