示例#1
0
 public SDownloadEventResult(DownloadEventType eventType, SDownloadFileResult fileResult, SGameUpdaterDownloadConfig info, string error)
 {
     this.error      = error;
     this.info       = info;
     this.fileResult = fileResult;
     this.eventType  = eventType;
 }
示例#2
0
 private void DownloadNext()
 {
     if (m_downloadConfigQueue.Count == 0)
     {
         if (m_downloadFailConfigList.Count > 0)
         {
             //有资源下载失败
             for (int i = 0; i < m_downloadFailConfigList.Count; i++)
             {
                 if (m_downloadCallback.Error != null)
                 {
                     m_downloadCallback.Error(m_downloadFailConfigList[i].fileName);
                 }
                 Debug.LogError("下载失败的资源文件: " + m_downloadFailConfigList[i].fileName);
             }
         }
         else
         {
             //资源全部下载成功
             if (m_downloadCallback.AllComplete != null)
             {
                 m_downloadCallback.AllComplete();       //=========================================================================================== AllComplete回调
             }
         }
         return;
     }
     m_currentConfig = m_downloadConfigQueue.Dequeue();
     m_md5File.PushTempFile(m_currentConfig.fileName);
     m_downloader.DownloadFile(m_currentConfig.downloadUrl, m_currentConfig.localUrl,
                               m_currentConfig.downloadTimeout,
                               OnProgress,  //资源下载过程中会一直调用这个Progress
                               OnComplete); //资源下载完成后调用OnComplete
 }
示例#3
0
        private void DownloadSizeNext()
        {
            if (m_downloadConfigQueue.Count <= 0)
            {
                Download();     //开始逐个下载资源内容
                return;
            }
            SGameUpdaterDownloadConfig config = m_downloadConfigQueue.Dequeue();

            m_downloader.DownloadFileSize(config.downloadUrl, config.downloadTimeout, (status, code, size) =>
            {
                if (status)
                {
                    m_downloadTotalSize += size;
                }
                else
                {
                    if (m_downloadCallback.Error != null)
                    {
                        m_downloadCallback.Error(config.fileName); //======================================================================================== Error回调
                    }
                    Debug.LogError(config.fileName + "资源, 在获取该资源文件内容大小的时候, 网络请求失败.");
                }
                DownloadSizeNext();
            });
        }
示例#4
0
        public void EnqueueNeedDownloadConfigQuque(string fileName)
        {
            //资源本身
            SGameUpdaterDownloadConfig config = new SGameUpdaterDownloadConfig();

            config.fileName          = fileName;
            config.downloadUrl       = AppConfig.ResourcesDownloadUrl + fileName;
            config.localUrl          = string.Format("{0}{1}", Util.DeviceResPath() + fileName);
            config.downloadTimeout   = AppConfig.DownloadFileTimeout;
            config.downloadFailRetry = AppConfig.DownloadFileFailedTryCount;
            m_needDownloadConfigQueue.Enqueue(config);
            //资源manifest文件
            SGameUpdaterDownloadConfig manifestConfig = new SGameUpdaterDownloadConfig();

            manifestConfig.fileName          = string.Format("{0}.manifest", fileName);
            manifestConfig.localUrl          = string.Format("{0}{1}", Util.DeviceResPath() + manifestConfig.fileName);
            manifestConfig.downloadUrl       = string.Format("{0}.manifest", config.downloadUrl);
            manifestConfig.downloadTimeout   = AppConfig.DownloadFileTimeout;
            manifestConfig.downloadFailRetry = AppConfig.DownloadFileFailedTryCount;
            m_needDownloadConfigQueue.Enqueue(manifestConfig);
        }
示例#5
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 (m_currentConfig.fileName.EndsWith(".manifest") == false)
         {
             string fileMd5   = Md5Helper.Md5File(m_currentConfig.localUrl + ".tmp");
             string remoteMd5 = m_md5File.GetRemoteMd5(m_currentConfig.fileName);
             if (fileMd5.Trim() == remoteMd5.Trim())
             {
                 Debug.LogWarning(m_currentConfig.fileName + " 返回了416 但是文件已经下载完毕 不需要重新下载" + fileMd5 + "==" + remoteMd5);
                 DownloadSuccess();
             }
             else
             {
                 Debug.LogWarning(m_currentConfig.fileName + " 返回了416 文件不一样 重新下载" + fileMd5 + "!=" + remoteMd5);
                 DownloadFail(code);
             }
         }
     }
     else
     {
         DownloadFail(code);
     }
     m_currentConfig = new SGameUpdaterDownloadConfig();
     DownloadNext();
 }
示例#6
0
 public SDownloadEventResult(DownloadEventType eventType, SGameUpdaterDownloadConfig info)
     : this(eventType, new SDownloadFileResult(), info, string.Empty)
 {
 }