Beispiel #1
0
        public bool updateAvailable()
        {
            UpdateReleaseData latestRelease = latest;

            return(latestRelease != null && latestRelease.version.CompareTo(currentVersion) > 0);
        }
Beispiel #2
0
        public bool now(UpdateData updateData)
        {
            bool success = false;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(UPDATE_ADDR);
                request.UserAgent              = string.Format("Mozilla/5.0 (compatible; AVRDUDESS VERSION CHECKER {0})", AssemblyData.version.ToString());
                request.ReadWriteTimeout       = 30000;
                request.Timeout                = 30000;
                request.KeepAlive              = false;
                request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
#if DEBUG // Getting proxy info is slow, so don't use proxy in debug
                request.Proxy = null;
#endif

                updateData.releases = new List <UpdateReleaseData>();
                UpdateReleaseData release = null;

                // Do request
                using (Stream responseStream = request.GetResponse().GetResponseStream())
                {
                    // XML
                    using (XmlReader reader = XmlReader.Create(responseStream))
                    {
                        while (reader.Read())
                        {
                            string name = reader.Name;

                            if (name == "release")
                            {
                                if (reader.NodeType == XmlNodeType.Element)
                                {
                                    release = new UpdateReleaseData();
                                }
                                else if (reader.NodeType == XmlNodeType.EndElement && release != null)
                                {
                                    updateData.releases.Add(release);
                                    release = null;
                                    success = true; // We need at least 1 release entry otherwise something isn't right...
                                }
                            }
                            else if (reader.NodeType == XmlNodeType.Element)
                            {
                                reader.Read();
                                if (release == null)
                                {
                                    if (name == "updateAddr")
                                    {
                                        updateData.updateAddr = reader.ReadContentAsString();
                                    }
                                }
                                else
                                {
                                    switch (name)
                                    {
                                    case "major":
                                        release.major = reader.ReadContentAsInt();
                                        break;

                                    case "minor":
                                        release.minor = reader.ReadContentAsInt();
                                        break;

                                    case "date":
                                        release.dateUnix = reader.ReadContentAsLong();
                                        break;

                                    case "info":
                                        release.info = reader.ReadContentAsString();
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                saveTime();
            }
            catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }

            if (!success)
            {
                errorMsg = Language.Translation.get("_UPDATE_BADXML");
            }

            return(success);
        }