Beispiel #1
0
        /// <summary>
        /// 检查更新
        /// </summary>
        /// <param name="IndexUrls">更新Index组</param>
        /// <param name="ResultsCallback">检查结果回调</param>
        /// <param name="BaseVersion">母包版本</param>
        /// <param name="PatchVersion">补丁包版本</param>
        /// <param name="CheckUrlCallback">检查Url过程回调</param>
        public void CheckUpgrade(string[] IndexUrls, int BaseVersion, int PatchVersion, Action <EUpgradeCheckResults> ResultsCallback, Action <int> CheckUrlCallback = null)
        {
            int i = 0;


            void DoItOnce(string IndexUrl) // 用来递归的函数
            {
                if (CheckUrlCallback != null)
                {
                    CheckUrlCallback(i);
                }
                XLog.Print("检查更新,获取更新索引:" + IndexUrl);
                CheckupgradeSingle(IndexUrl, (isSuccess, JsonText, ErrType) =>
                {
                    if (isSuccess)
                    {
                        //成功
                        var jsonObj = JsonUtility.FromJson <StaticUpgradeConfigJsonTpl>(JsonText);
                        mUpgradeTpl = jsonObj;
                        //检查更新结果类型
                        if (mUpgradeTpl.IsNeedUpgrade(BaseVersion, PatchVersion))
                        {
                            //需要更新
                            ResultsCallback(EUpgradeCheckResults.upgrade);
                        }
                        else
                        {
                            //已经是最新的
                            ResultsCallback(EUpgradeCheckResults.newest);
                        }
                        return;
                    }
                    else
                    {
                        XLog.Print("检查更新失败:" + ErrType.ToString());
                        //失败
                        i++;
                        if (IndexUrls.Length - 1 >= i)
                        {
                            //递归
                            DoItOnce(IndexUrls[i]);
                        }
                        else
                        {
                            //全部检查过了,对外告知检查失败
                            //把最后一次检查的报错放出去
                            switch (ErrType)
                            {
                            case EGetIndexJsonErrorType.connect_error:
                                ResultsCallback(EUpgradeCheckResults.connect_error);
                                break;

                            case EGetIndexJsonErrorType.url_error:
                                ResultsCallback(EUpgradeCheckResults.error);
                                break;

                            default:
                                ResultsCallback(EUpgradeCheckResults.error);
                                break;
                            }
                            return;
                        }
                    }
                });
            }

            if (IndexUrls.Length - 1 >= i)
            {
                DoItOnce(IndexUrls[i]);
            }
        }