コード例 #1
0
ファイル: UpdateManager.cs プロジェクト: ywscr/nUpdate
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns>
        public bool SearchForUpdates()
        {
            // It may be that this is not the first search call and previously saved data needs to be disposed.
            Cleanup();

            OnUpdateSearchStarted(this, EventArgs.Empty);
            if (!ConnectionManager.IsConnectionAvailable())
            {
                return(false);
            }

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = (SecurityProtocolType)3072;
            var configuration =
                UpdateConfiguration.Download(UpdateConfigurationFileUri, HttpAuthenticationCredentials, Proxy,
                                             SearchTimeout);

            var result = new UpdateResult(configuration, CurrentVersion,
                                          IncludeAlpha, IncludeBeta, Conditions);

            if (!result.UpdatesFound)
            {
                return(false);
            }

            PackageConfigurations = result.NewestConfigurations;
            double updatePackageSize = 0;

            foreach (var updateConfiguration in PackageConfigurations)
            {
                updateConfiguration.UpdatePackageUri = ConvertPackageUri(updateConfiguration.UpdatePackageUri);
                updateConfiguration.UpdatePhpFileUri = ConvertStatisticsUri(updateConfiguration.UpdatePhpFileUri);

                var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri);
                if (newPackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                updatePackageSize += newPackageSize.Value;
                if (updateConfiguration.Operations == null)
                {
                    continue;
                }
                if (_packageOperations == null)
                {
                    _packageOperations = new Dictionary <UpdateVersion, IEnumerable <Operation> >();
                }
                _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion),
                                       updateConfiguration.Operations);
            }

            TotalSize = updatePackageSize;
            return(true);
        }
コード例 #2
0
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns>
        /// <exception cref="SizeCalculationException">The calculation of the size of the available updates has failed.</exception>
        /// <exception cref="OperationCanceledException">The update search was canceled.</exception>
        public bool SearchForUpdates()
        {
            if (_searchCancellationTokenSource != null)
            {
                _searchCancellationTokenSource.Dispose();
            }
            _searchCancellationTokenSource = new CancellationTokenSource();

            if (!ConnectionChecker.IsConnectionAvailable())
            {
                return(false);
            }

            // Check for SSL and ignore it
            ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
            var configuration = UpdateConfiguration.Download(_updateConfigurationFileUri, Proxy);

            var result = new UpdateResult(configuration, CurrentVersion,
                                          IncludeAlpha, IncludeBeta);

            if (!result.UpdatesFound)
            {
                return(false);
            }


            _updateConfigurations = _configurationUpdateCallback == null ? result.NewestConfigurations : _configurationUpdateCallback.Invoke(result.NewestConfigurations);
            double updatePackageSize = 0;

            foreach (var updateConfiguration in _updateConfigurations)
            {
                var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri);
                if (newPackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                updatePackageSize += newPackageSize.Value;
                _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion),
                                       updateConfiguration.Operations);
            }

            TotalSize = updatePackageSize;
            if (_searchCancellationTokenSource.Token.IsCancellationRequested)
            {
                _packageOperations.Clear();
                _packageFilePaths.Clear();
                throw new OperationCanceledException();
            }

            return(true);
        }
コード例 #3
0
ファイル: UpdateManager.cs プロジェクト: huomm23/nUpdate
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns>
        /// <exception cref="SizeCalculationException">The calculation of the size of the available updates has failed.</exception>
        /// <exception cref="OperationCanceledException">The update search was canceled.</exception>
        public bool SearchForUpdates()
        {
            // It may be that this is not the first search call and previously saved data needs to be disposed.
            Cleanup();
            _searchCancellationTokenSource?.Dispose();
            _searchCancellationTokenSource = new CancellationTokenSource();

            if (!ConnectionChecker.IsConnectionAvailable())
            {
                return(false);
            }

            // Check for SSL and ignore it
            ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
            var configuration = UpdateConfiguration.Download(UpdateConfigurationFileUri, Proxy);

            var result = new UpdateResult(configuration, CurrentVersion,
                                          IncludeAlpha, IncludeBeta);

            if (!result.UpdatesFound)
            {
                return(false);
            }

            PackageConfigurations = result.NewestConfigurations;
            double updatePackageSize = 0;

            foreach (var updateConfiguration in PackageConfigurations)
            {
                var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri);
                if (newPackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                updatePackageSize += newPackageSize.Value;
                _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion),
                                       updateConfiguration.Operations);
            }

            TotalSize = updatePackageSize;
            if (_searchCancellationTokenSource.Token.IsCancellationRequested)
            {
                Cleanup();
                throw new OperationCanceledException();
            }

            return(true);
        }
コード例 #4
0
ファイル: UpdateManager.cs プロジェクト: zyj0021/nUpdate
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <returns>Returns <c>true</c> if updates were found; otherwise, <c>false</c>.</returns>
        public bool SearchForUpdates()
        {
            // It may be that this is not the first search call and previously saved data needs to be disposed.
            Cleanup();

            OnUpdateSearchStarted(this, EventArgs.Empty);
            if (!ConnectionManager.IsConnectionAvailable())
            {
                return(false);
            }

            // Check for SSL and ignore it
            ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };
            var configuration =
                UpdateConfiguration.Download(UpdateConfigurationFileUri, HttpAuthenticationCredentials, Proxy,
                                             SearchTimeout);

            var result = new UpdateResult(configuration, CurrentVersion,
                                          IncludeAlpha, IncludeBeta);

            if (!result.UpdatesFound)
            {
                return(false);
            }

            PackageConfigurations = result.NewestConfigurations;
            double updatePackageSize = 0;

            foreach (var updateConfiguration in PackageConfigurations)
            {
                updateConfiguration.UpdatePackageUri = ConvertPackageUri(updateConfiguration.UpdatePackageUri);
                updateConfiguration.UpdatePhpFileUri = ConvertStatisticsUri(updateConfiguration.UpdatePhpFileUri);

                var newPackageSize = GetUpdatePackageSize(updateConfiguration.UpdatePackageUri);
                if (newPackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                updatePackageSize += newPackageSize.Value;
                _packageOperations.Add(new UpdateVersion(updateConfiguration.LiteralVersion),
                                       updateConfiguration.Operations);
            }

            TotalSize = updatePackageSize;
            return(true);
        }
コード例 #5
0
ファイル: UpdateManager.cs プロジェクト: vector-man/nUpdate
        /// <summary>
        ///     Searches for updates.
        /// </summary>
        /// <exception cref="InvalidOperationException">There is already a search process running.</exception>
        /// <exception cref="NetworkException">There is no network connection available.</exception>
        /// <seealso cref="SearchForUpdatesAsync"/>
        public void SearchForUpdates()
        {
            if (_searchWebClient.IsBusy)
            {
                throw new InvalidOperationException(_lp.SearchProcessRunningExceptionText);
            }

            if (!ConnectionChecker.IsConnectionAvailable())
            {
                throw new NetworkException(_lp.NetworkConnectionExceptionText);
            }

            // Check for SSL and ignore it
            ServicePointManager.ServerCertificateValidationCallback += delegate { return(true); };

            var configurations = UpdateConfiguration.Download(UpdateConfigurationFileUri, Proxy);
            var result         = new UpdateResult(configurations, CurrentVersion,
                                                  IncludeAlpha, IncludeBeta);

            if (!result.UpdatesFound)
            {
                OnUpdateSearchFinished(false);
            }
            else
            {
                _updateConfiguration = result.NewestConfiguration;
                NewestVersion        = new UpdateVersion(_updateConfiguration.LiteralVersion);
                Changelog            = _updateConfiguration.Changelog.ContainsKey(LanguageCulture)
                    ? _updateConfiguration.Changelog.First(item => item.Key.Name == LanguageCulture.Name).Value
                    : _updateConfiguration.Changelog.First(item => item.Key.Name == new CultureInfo("en").Name).Value;
                Signature  = Convert.FromBase64String(_updateConfiguration.Signature);
                MustUpdate = _updateConfiguration.MustUpdate;
                Operations = _updateConfiguration.Operations;

                var updatePackageSize = GetUpdatePackageSize(_updateConfiguration.UpdatePackageUri);
                if (updatePackageSize == null)
                {
                    throw new SizeCalculationException(_lp.PackageSizeCalculationExceptionText);
                }

                PackageSize = updatePackageSize.Value;
                OnUpdateSearchFinished(true);
            }
        }