예제 #1
0
        /// <summary>
        /// Gets the specified URL.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        public static byte[] Get(string url)
        {
            var f = new Fetch();

            f.Load(url);

            return(f.ResponseData);
        }
예제 #2
0
        public bool CheckForUpdate()
        {
            try
            {
                Console.WriteLine("Check starting.");

                var remoteUri = new Uri(_localConfig.RemoteConfigUri);

                Console.WriteLine("Fetching '{0}'.", remoteUri.AbsoluteUri);
                var http = new Fetch
                {
                    Retries    = 5,
                    RetrySleep = 30000,
                    Timeout    = 30000
                };

                http.Load(remoteUri.AbsoluteUri);
                if (!http.Success)
                {
                    Console.WriteLine("Fetch error: {0}", http.Response.StatusDescription);
                    _remoteConfig = null;
                    return(false);
                }

                string data = Encoding.UTF8.GetString(http.ResponseData);
                _remoteConfig = new Manifest(data);

                if (_remoteConfig == null)
                {
                    return(false);
                }

                if (_localConfig.SecurityToken != _remoteConfig.SecurityToken)
                {
                    Console.WriteLine("Security token mismatch.");
                    return(false);
                }

                Console.WriteLine("Remote config is valid.");
                Console.WriteLine("Local version is  {0}.", _localConfig.Version);
                Console.WriteLine("Remote version is {0}.", _remoteConfig.Version);

                if (_remoteConfig.Version == _localConfig.Version)
                {
                    Console.WriteLine("Versions are the same.");
                    Console.WriteLine("Check ending.");
                    return(false);
                }

                if (_remoteConfig.Version < _localConfig.Version)
                {
                    Console.WriteLine("Remote version is older.");
                    Console.WriteLine("Check ending.");
                    return(false);
                }

                Console.WriteLine("Remote version is newer. Updating.");
                _updating = true;

                switch (MessageBox.Show("Preparing to download update.", "New Update Available"))
                {
                case DialogResult.OK:
                default:
                    Update();
                    break;
                }

                _updating = false;
                Console.WriteLine("Check ending.");

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Update Error");

                return(false);
            }
        }