Beispiel #1
0
        /// <summary>
        /// 1.从CDN下载版本信息列表
        /// </summary>
        /// <param name="_url">CDN地址</param>
        /// <param name="_completed">可选:完成后回调</param>
        /// <param name="_password">可选:版本文件的密码</param>
        /// <param name="_validSeconds">可选:默认为1天的有效期,超过有效期,会从服务器下载新的版本信息</param>
        /// <returns></returns>
        static public URemoteVersionRequest DownloadVersionFile(string _url, Action <URemoteVersionRequest> _completed = null, string _password = null, float _validSeconds = 7200)
        {
            FileVersionUpdateInfo outInfo;

            if (false == VersionFiles.TryGetValue(_url, out outInfo))
            {
                outInfo       = new FileVersionUpdateInfo();
                outInfo.State = EDownloadState.Fail;
                VersionFiles.Add(_url, outInfo);
            }

            if (outInfo.State == EDownloadState.Success)
            {
                if ((DateTime.Now - outInfo.LastUpdate).TotalSeconds >= _validSeconds)
                {
                    outInfo.State = EDownloadState.Fail;
                }
                else
                {
                    _completed?.Invoke(outInfo.Request);
                    return(outInfo.Request);
                }
            }

            if (outInfo.State == EDownloadState.Fail)
            {
                outInfo.State = EDownloadState.Downloading;

                outInfo.Request = new URemoteVersionLoader(_url, (src) =>
                {
                    if (string.IsNullOrEmpty(_password) == false)
                    {
                        return(UFile.RemKeystore(src, _password));
                    }
                    return(src);
                },
                                                           (isOk) =>
                {
                    if (outInfo.Request.IsSuccess)
                    {
                        outInfo.State      = EDownloadState.Success;
                        outInfo.LastUpdate = DateTime.Now;
                    }
                    else
                    {
                        outInfo.State = EDownloadState.Fail;
                    }
                    outInfo.Completed?.Invoke(outInfo.Request);
                    outInfo.Completed = null;
                });
                outInfo.Completed = _completed;
            }
            else
            {
                outInfo.Completed += _completed;
            }

            return(outInfo.Request);
        }