Пример #1
0
        public static UpdaterResult CheckForUpdates() {
            UpdaterMode mode = ConfigKey.UpdaterMode.GetEnum<UpdaterMode>();
            if( mode == UpdaterMode.Disabled ) return UpdaterResult.NoUpdate;

            string url = String.Format( UpdateUrl, CurrentRelease.Revision );
            if( RaiseCheckingForUpdatesEvent( ref url ) ) return UpdaterResult.NoUpdate;

            Logger.Log( LogType.SystemActivity, "Checking for fCraft updates..." );
            try {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );

                request.Method = "GET";
                request.UserAgent = "fCraft";
                request.Timeout = UpdateCheckTimeout;
                request.ReadWriteTimeout = UpdateCheckTimeout;
                request.CachePolicy = new HttpRequestCachePolicy( HttpRequestCacheLevel.BypassCache );
                request.UserAgent = UserAgent;

                using( WebResponse response = request.GetResponse() ) {
                    // ReSharper disable AssignNullToNotNullAttribute
                    // ReSharper disable PossibleNullReferenceException
                    using( XmlTextReader reader = new XmlTextReader( response.GetResponseStream() ) ) {
                        // ReSharper restore AssignNullToNotNullAttribute
                        XDocument doc = XDocument.Load( reader );
                        XElement root = doc.Root;
                        if( root.Attribute( "result" ).Value == "update" ) {
                            string downloadUrl = root.Attribute( "url" ).Value;
                            var releases = new List<ReleaseInfo>();
                            // ReSharper disable LoopCanBeConvertedToQuery
                            foreach( XElement el in root.Elements( "Release" ) ) {
                                releases.Add(
                                    new ReleaseInfo(
                                        Int32.Parse( el.Attribute( "v" ).Value ),
                                        Int32.Parse( el.Attribute( "r" ).Value ),
                                        Int64.Parse( el.Attribute( "date" ).Value ).ToDateTime(),
                                        el.Element( "Summary" ).Value,
                                        el.Element( "ChangeLog" ).Value,
                                        ReleaseInfo.StringToReleaseFlags( el.Attribute( "flags" ).Value )
                                    )
                                );
                            }
                            // ReSharper restore LoopCanBeConvertedToQuery
                            // ReSharper restore PossibleNullReferenceException
                            UpdaterResult result = new UpdaterResult( (releases.Count > 0), new Uri( downloadUrl ),
                                                                      releases.ToArray() );
                            RaiseCheckedForUpdatesEvent( UpdateUrl, result );
                            return result;
                        } else {
                            return UpdaterResult.NoUpdate;
                        }
                    }
                }
            } catch( Exception ex ) {
                Logger.Log( LogType.Error,
                            "An error occured while trying to check for updates: {0}: {1}",
                            ex.GetType(), ex.Message );
                return UpdaterResult.NoUpdate;
            }
        }
Пример #2
0
        static void RaiseCheckedForUpdatesEvent([NotNull] string url, [NotNull] UpdaterResult result)
        {
            var h = CheckedForUpdates;

            if (h != null)
            {
                h(null, new CheckedForUpdatesEventArgs(url, result));
            }
        }
Пример #3
0
        static void RaiseCheckedForUpdatesEvent(string url, UpdaterResult result)
        {
            var handler = CheckedForUpdates;

            if (handler != null)
            {
                handler(null, new CheckedForUpdatesEventArgs(url, result));
            }
        }
Пример #4
0
        static void FireCheckedForUpdatesEvent(string url, UpdaterResult result)
        {
            var h = CheckedForUpdates;

            if (h != null)
            {
                h(null, new CheckedForUpdatesEventArgs(url, result));
            }
        }
Пример #5
0
 public UpdateWindow( UpdaterResult _update, bool _auto ) {
     InitializeComponent();
     updaterFullPath = Path.Combine( Paths.WorkingPath, Paths.UpdaterFile );
     update = _update;
     auto = _auto;
     CreateDetailedChangeLog();
     lVersion.Text = String.Format( lVersion.Text,
                                    Updater.CurrentRelease.VersionString,
                                    update.LatestRelease.VersionString,
                                    update.LatestRelease.Age.TotalDays );
     Shown += Download;
 }
Пример #6
0
 public UpdateWindow( UpdaterResult _update, MainForm _parent, bool _auto )
 {
     InitializeComponent();
     parent = _parent;
     update = _update;
     auto = _auto;
     changelog.Text = update.ChangeLog;
     title.Text = String.Format( "A new version is available: v{0:0.000}, released {1:0} day(s) ago.",
                                 Decimal.Divide( update.NewVersionNumber, 1000 ),
                                 DateTime.Now.Subtract( update.ReleaseDate ).TotalDays );
     Shown += Download;
 }
Пример #7
0
        public static UpdaterResult CheckForUpdates() {
            UpdaterMode mode = ConfigKey.UpdaterMode.GetEnum<UpdaterMode>();
            if( mode == UpdaterMode.Disabled ) return UpdaterResult.NoUpdate;

            string url = String.Format( UpdateUri, CurrentRelease.Revision );
            if( RaiseCheckingForUpdatesEvent( ref url ) ) return UpdaterResult.NoUpdate;

            Logger.Log( LogType.SystemActivity, "Checking for fCraft updates..." );
            try {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );

                request.Method = "GET";
                request.Timeout = UpdateCheckTimeout;
                request.ReadWriteTimeout = UpdateCheckTimeout;
                request.CachePolicy = new HttpRequestCachePolicy( HttpRequestCacheLevel.BypassCache );
                request.UserAgent = UserAgent;

                using( WebResponse response = request.GetResponse() ) {
                    using( XmlTextReader reader = new XmlTextReader( response.GetResponseStream() ) ) {
                        XDocument doc = XDocument.Load( reader );
                        XElement root = doc.Root;
                        if( root.Attribute( "result" ).Value == "update" ) {
                            string downloadUrl = root.Attribute( "url" ).Value;
                            var releases = new List<ReleaseInfo>();
                            foreach( XElement el in root.Elements( "Release" ) ) {
                                releases.Add(
                                    new ReleaseInfo(
                                        Int32.Parse( el.Attribute( "v" ).Value ),
                                        Int32.Parse( el.Attribute( "r" ).Value ),
                                        Int64.Parse( el.Attribute( "date" ).Value ).ToDateTime(),
                                        el.Element( "Summary" ).Value,
                                        el.Element( "ChangeLog" ).Value,
                                        ReleaseInfo.StringToReleaseFlags( el.Attribute( "flags" ).Value )
                                    )
                                );
                            }
                            UpdaterResult result = new UpdaterResult( (releases.Count > 0), new Uri( downloadUrl ),
                                                                      releases.ToArray() );
                            RaiseCheckedForUpdatesEvent( UpdateUri, result );
                            return result;
                        } else {
                            return UpdaterResult.NoUpdate;
                        }
                    }
                }
            } catch( Exception ex ) {
                Logger.Log( LogType.Error,
                            "An error occured while trying to check for updates: {0}: {1}",
                            ex.GetType(), ex.Message );
                return UpdaterResult.NoUpdate;
            }
        }
Пример #8
0
        public static UpdaterResult CheckForUpdates()
        {
            UpdaterResult result = new UpdaterResult( version );
            if( Config.GetString( ConfigKey.AutomaticUpdates ) == "Disabled" ) return result;
            try {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( "http://fcraft.fragmer.net/version.log" );

                request.Method = "GET";
                request.UserAgent = "fCraft";
                request.Timeout = 6000;
                request.ReadWriteTimeout = 6000;
                request.CachePolicy = new RequestCachePolicy( System.Net.Cache.RequestCacheLevel.NoCacheNoStore );

                using( WebResponse response = request.GetResponse() ) {
                    using( StreamReader reader = new StreamReader( response.GetResponseStream() ) ) {
                        result.DownloadLink = reader.ReadLine();
                        result.ReleaseDate = DateTime.Parse( reader.ReadLine() );

                        string line = reader.ReadLine();
                        while( !reader.EndOfStream ) {
                            int logVersion = Int32.Parse( line );
                            if( logVersion <= version ) break;
                            else if( result.NewVersionNumber < logVersion ) result.NewVersionNumber = logVersion;
                            result.ChangeLog += logVersion.ToString() + ":" + Environment.NewLine;
                            line = reader.ReadLine();
                            while( line.StartsWith( " " ) ) {
                                result.ChangeLog += line + Environment.NewLine;
                                if( reader.EndOfStream ) break;
                                line = reader.ReadLine();
                            }
                            result.ChangeLog += Environment.NewLine;
                        }

                        if( result.NewVersionNumber > version ) {
                            result.UpdateAvailable = true;
                        }
                    }
                }
                request.Abort();
            } catch( Exception ex ) {
                Logger.Log( "An error occured while trying to check for updates: {0}: {1}", LogType.Error,
                               ex.GetType().ToString(), ex.Message );
            }
            return result;
        }
Пример #9
0
        /// <summary> Checks fCraft.net for updated versions of fCraft. </summary>
        public static UpdaterResult CheckForUpdates() {
            UpdaterMode mode = ConfigKey.UpdaterMode.GetEnum<UpdaterMode>();
            if( mode == UpdaterMode.Disabled ) return UpdaterResult.NoUpdate;

            string url = String.Format( UpdateUri, CurrentRelease.Revision );
            if( RaiseCheckingForUpdatesEvent( ref url ) ) return UpdaterResult.NoUpdate;

            Logger.Log( LogType.SystemActivity, "Checking for fCraft updates..." );
            try {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create( url );

                request.CachePolicy = Server.CachePolicy;
                request.Method = "GET";
                request.ReadWriteTimeout = (int)UpdateCheckTimeout.TotalMilliseconds;
                request.ServicePoint.BindIPEndPointDelegate = Server.BindIPEndPointCallback;
                request.Timeout = (int)UpdateCheckTimeout.TotalMilliseconds;
                request.UserAgent = UserAgent;

                using( WebResponse response = request.GetResponse() ) {
                    // ReSharper disable AssignNullToNotNullAttribute
                    using( XmlTextReader reader = new XmlTextReader( response.GetResponseStream() ) ) {
                        // ReSharper restore AssignNullToNotNullAttribute
                        XDocument doc = XDocument.Load( reader );
                        XElement root = doc.Root;
                        // ReSharper disable PossibleNullReferenceException
                        if( root.Attribute( "result" ).Value == "update" ) {
                            string downloadUrl = root.Attribute( "url" ).Value;
                            var releases = new List<ReleaseInfo>();
                            foreach( XElement el in root.Elements( "Release" ) ) {
                                releases.Add(
                                    new ReleaseInfo(
                                        Int32.Parse( el.Attribute( "v" ).Value ),
                                        Int32.Parse( el.Attribute( "r" ).Value ),
                                        DateTimeUtil.TryParseDateTime( Int64.Parse( el.Attribute( "date" ).Value ) ),
                                        el.Element( "Summary" ).Value,
                                        el.Element( "ChangeLog" ).Value,
                                        ReleaseInfo.StringToReleaseFlags( el.Attribute( "flags" ).Value )
                                    )
                                );
                            }
                            // ReSharper restore PossibleNullReferenceException
                            UpdaterResult result = new UpdaterResult( ( releases.Count > 0 ), new Uri( downloadUrl ),
                                                                      releases.ToArray() );
                            RaiseCheckedForUpdatesEvent( UpdateUri, result );
                            return result;
                        } else {
                            return UpdaterResult.NoUpdate;
                        }
                    }
                }
            } catch( Exception ex ) {
                Logger.Log( LogType.Error,
                            "An error occurred while trying to check for updates: {0}: {1}",
                            ex.GetType(), ex.Message );
                return UpdaterResult.NoUpdate;
            }
        }
Пример #10
0
 static void RaiseCheckedForUpdatesEvent( string url, UpdaterResult result ) {
     var h = CheckedForUpdates;
     if( h != null ) h( null, new CheckedForUpdatesEventArgs( url, result ) );
 }
Пример #11
0
        public static UpdaterResult CheckForUpdates(World world)
        {
            UpdaterResult result = new UpdaterResult(version);

            if (world.config.GetString("AutomaticUpdates") == "Disabled")
            {
                return(result);
            }
            try {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://fcraft.fragmer.net/version.log");

                request.Method           = "GET";
                request.UserAgent        = "fCraft";
                request.Timeout          = 6000;
                request.ReadWriteTimeout = 6000;
                request.CachePolicy      = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);

                using (WebResponse response = request.GetResponse()) {
                    using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
                        result.DownloadLink = reader.ReadLine();
                        result.ReleaseDate  = DateTime.Parse(reader.ReadLine());

                        string line = reader.ReadLine();
                        while (!reader.EndOfStream)
                        {
                            int logVersion = Int32.Parse(line);
                            if (logVersion <= version)
                            {
                                break;
                            }
                            else if (result.NewVersionNumber < logVersion)
                            {
                                result.NewVersionNumber = logVersion;
                            }
                            result.ChangeLog += logVersion.ToString() + ":" + Environment.NewLine;
                            line              = reader.ReadLine();
                            while (line.StartsWith(" "))
                            {
                                result.ChangeLog += line + Environment.NewLine;
                                if (reader.EndOfStream)
                                {
                                    break;
                                }
                                line = reader.ReadLine();
                            }
                            result.ChangeLog += Environment.NewLine;
                        }

                        if (result.NewVersionNumber > version)
                        {
                            result.UpdateAvailable = true;
                        }
                    }
                }
                request.Abort();
            } catch (Exception ex) {
                world.log.Log("An error occured while trying to check for updates: {0}: {1}", LogType.Error,
                              ex.GetType().ToString(), ex.Message);
            }
            return(result);
        }