Пример #1
0
        private void DownloadNext()
        {
            if (_md5File.DownloadQueue.Count == 0)
            {
                if (_failList.Count > 0)
                {
                    Error(new SDownloadEventResult(DownloadEventType.Error, "下载失败"));
                    for (int i = 0; i < _failList.Count; i++)
                    {
                        Debug.LogError("失败的文件:" + _failList[i].download_url);
                    }
                }
                else
                {
                    AllComplete(new SDownloadEventResult(DownloadEventType.AllComplete));
                }
                return;
            }

            _currentConfig = _md5File.DownloadQueue.Dequeue();
            //将这个文件记录到下载中
            _md5File.PushTmpFile(_currentConfig.key);

            _webDownload.DownloadFile(_currentConfig.download_url, _currentConfig.localPath_url, TIMEOUT, OnProgress, OnComplete);
        }
Пример #2
0
 public SDownloadEventResult(DownloadEventType eventType, SDownloadFileResult fileResult, SDownloadModuleConfig info, string error)
 {
     Error      = error;
     Info       = info;
     FileResult = fileResult;
     EventType  = eventType;
 }
Пример #3
0
        private void OnComplete(int code)
        {
            if (code == 206)
            {
                DownloadSuccess();
            }
            else if (code == 416)
            {
                ///在使用暂停下载的时候有几率会出现此问题
                ///因为是线程下载,在下载完成的瞬间暂停后 会把当前文件重新加入下载队列导致重复下载, 实际上暂停之后的同时或者下一帧这个文件已经下载完毕
                /// 所以临时文件 aaa.mp4.tmp 和 远程 aaa.mp4 的大小一样 只不过没有被移动 在续传的时候会返回一次416
                /// 所以这里判断如果临时文件的md5和远程md5相等 直接判定下载成功 不走下面下载失败流程 否则会删除重新下载
                /// 这里跳过了manifest文件 因为这个文件没有对应的md5字符串,也没有必要做对比,一般都是1k大小 重新下载没毛病
                if (_currentConfig.key.EndsWith(".manifest") == false)
                {
                    string fileMd5   = Util.Md5File(_currentConfig.localPath_url + ".tmp");
                    string remoteMd5 = _md5File.GetRemoteMd5(_currentConfig.key);
                    if (fileMd5.Trim() == remoteMd5.Trim())
                    {
                        Debug.LogWarning(_currentConfig.key + " 返回了416 但是文件已经下载完毕 不需要重新下载" + fileMd5 + "==" + remoteMd5);
                        DownloadSuccess();
                    }
                    else
                    {
                        Debug.LogWarning(_currentConfig.key + " 返回了416 文件不一样 重新下载" + fileMd5 + "!=" + remoteMd5);
                        DownloadFail(code);
                    }
                }
            }
            else
            {
                DownloadFail(code);
            }

            _currentConfig = new SDownloadModuleConfig();
            DownloadNext();
            //if (_currentConfig.key != "Modules" && _currentConfig.key != "Modules.manifest")
            //{
            //    Destroy(gameObject);
            //}
        }
Пример #4
0
        private void GetNext(Md5File md5File)
        {
            if (_tempQueue.Count == 0)
            {
                if (_complete != null)
                {
                    _complete(md5File, _size);
                }
                return;
            }
            SDownloadModuleConfig download = _tempQueue.Dequeue();

            _webDownload.DownloadFileSize(download.download_url, TIMEOUT, (bool ok, int code, int size) =>
            {
                if (ok)
                {
                    _size += size;
                }
                //Debug.Log(download.download_url + "  ok:" + ok + " code:" + code + " size:" + size+"         "+ _downloadQueue.Count);
                GetNext(md5File);
            });
        }
Пример #5
0
        private void PushUpdateFile(string file)
        {
            SDownloadModuleConfig fileConfig = new SDownloadModuleConfig();

            fileConfig.key                 = file;
            fileConfig.download_url        = string.Format("{0}/{1}/{2}", _version.res_download_url, GameConfig.module_name, file);
            fileConfig.localPath_url       = string.Format("{0}/{1}", Util.DeviceResPath, file);
            fileConfig.download_fail_retry = _version.download_fail_retry;
            _downloadQueue.Enqueue(fileConfig);

            //添加manifest文件
            string manifestFile = string.Empty;

            //跳过lua脚本
            if (!file.EndsWith(".txt"))
            {
                SDownloadModuleConfig manifestConfig = new SDownloadModuleConfig();
                manifestConfig.key                 = string.Format("{0}.manifest", file);
                manifestConfig.download_url        = string.Format("{0}.manifest", fileConfig.download_url);
                manifestConfig.localPath_url       = string.Format("{0}.manifest", fileConfig.localPath_url);
                manifestConfig.download_fail_retry = _version.download_fail_retry;
                _downloadQueue.Enqueue(manifestConfig);
            }
        }
Пример #6
0
 public SDownloadEventResult(DownloadEventType eventType, SDownloadModuleConfig info)
     : this(eventType, new SDownloadFileResult(), info, string.Empty)
 {
 }