コード例 #1
0
ファイル: Updater.Methods.cs プロジェクト: yzwbrian/fy_update
        /// <summary>
        /// 异步检查完成
        /// </summary>
        /// <param name="e">结果</param>
        protected virtual void ClientCheckCompleted(DownloadStringCompletedEventArgs e)
        {
            //用户取消
            if (e.Cancelled)
            {
                this.OnNotify(new NotifyEventArgs("已取消更新。"));
                return;
            }
            //出错
            if (e.Error != null)
            {
                this.OnError(new ErrorEventArgs("下载更新信息失败:{0}。", e.Error.Message.TrimEnd(PERIOD)));
                return;
            }
            //解析
            Packages packages;

            try
            {
                packages = new Packages(e.Result);
            }
            catch (Exception exp)
            {
                this.OnError(new ErrorEventArgs("解析更新信息失败:{0}。", exp.Message.TrimEnd(PERIOD)));
                return;
            }
            //可用更新
            PackageCollection avaliables = packages.GetAvailables(HostConfig.CurrentVersion);
            bool uptodate = avaliables.Count < 1;

            this.OnNotify(new NotifyEventArgs(uptodate ? "已是最新版本。" : "发现新版本。"));
            CheckCompletedEventArgs ce = new CheckCompletedEventArgs(uptodate);

            this.OnCheckCompleted(ce);
            if (uptodate || ce.Handled)
            {
                return;
            }
            this.m_Avaliables = avaliables.GetEnumerator();
            //开始更新
            this.OnUpdateStarted(new UpdateStartedEventArgs(avaliables));
            this.ClientKillAsync();
        }