Ejemplo n.º 1
0
            public void StartDownloadItem(string remoteResPath, string localTempDir, ResItem resItem)
            {
                mIsFinished  = false;
                mIsFailed    = false;
                mIsSuccess   = false;
                this.ResItem = resItem;

                moduleResDown.StartCoroutine(DownloadFileWebRequest(remoteResPath, localTempDir, resItem, (result, info) =>
                {
                    if (result)
                    {
                        mIsSuccess  = true;
                        mIsFinished = true;
                    }
                    else
                    {
                        if (resItem.retryTimes < 5)
                        {
                            Debug.LogError("retry >>>>>" + Path.Combine(remoteResPath, resItem.path) + "  >>>> " + resItem.retryTimes);
                            resItem.retryTimes++;
                            StartDownloadItem(remoteResPath, localTempDir, resItem);
                        }
                        else
                        {
                            Debug.LogError("下载出错>>>>>:" + Path.Combine(remoteResPath, resItem.path));
                            mIsFailed   = true;
                            mIsFinished = true;
                        }
                    }
                }));
            }
Ejemplo n.º 2
0
 public bool EqualToItem(ResItem item)
 {
     if (item.hash.Equals(hash))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        private void GetUpdateItemList()
        {
            if (mCheckVersion)
            {
                if (mLocalConfig.items != null && int.Parse(mLocalConfig.resversion) >= int.Parse(mServerConfig.resversion))
                {
                    ResUpdateCallback(UpdateStatus.Success, "没有新资源:RES_VERSOIN 一致");

                    return;
                }
            }

            int totalSize = 0;

            foreach (var item in mServerConfig.items)
            {
                ResItem localItem = mLocalConfig.FindItemWithPath(item.path);

                bool needUpdate = localItem == null || !item.EqualToItem(localItem);

                if (mCheckItemExist)
                {
                    var path = mLocalResPath + "/" + item.path;
                    if (File.Exists(path))
                    {
                        needUpdate = false;
                    }
                }

                if (needUpdate)
                {
                    totalSize += item.size;
                    mUpdateItems.Enqueue(item);
                }
            }

            PTDebug.Log(string.Format("{0} items need to be updated >>>>>", mUpdateItems.Count));

            if (mUpdateItems.Count == 0)
            {
                SaveServerConfig();

                ResUpdateCallback(UpdateStatus.Success, "没有新资源");

                return;
            }

            mResUpdateData.totalSize = (totalSize / 1024.0f) / 1024.0f;

            mResUpdateData.totalCount = mUpdateItems.Count;

            ResUpdateCallback(UpdateStatus.ReadyToDown, "准备更新");
        }
Ejemplo n.º 4
0
            private IEnumerator DownloadFileWebRequest(string remoteResPath, string localTempDir, ResItem resItem, Action <bool, string> callback)
            {
                string remoteUrl     = Path.Combine(remoteResPath, resItem.path);
                string localDestPath = Path.Combine(localTempDir, resItem.path);

                PTDebug.Log(string.Format("***********从{0}下载到{1}:", remoteUrl, localDestPath));

                var fileDir = Path.GetDirectoryName(localDestPath);

                if (!Directory.Exists(fileDir))
                {
                    Directory.CreateDirectory(fileDir);
                }

                mHttpRequest = new HTTPRequest(new Uri(remoteUrl),
                                               (req, resp) =>
                {
                    if (resp != null && req.Exception == null)
                    {
                        File.WriteAllBytes(localDestPath, resp.Data);
                        if (mHttpRequest != null)
                        {
                            mHttpRequest.Abort();
                            mHttpRequest.Dispose();
                            mHttpRequest = null;
                        }
                        callback(true, "success");
                    }
                    else
                    {
                        var errorInfo = "错误信息:" + req.Exception;
                        Debug.LogError(errorInfo);
                        if (mHttpRequest != null)
                        {
                            mHttpRequest.Abort();
                            mHttpRequest.Dispose();
                            mHttpRequest = null;
                        }
                        callback(false, errorInfo);
                    }
                })
                {
                    ConnectTimeout = TimeSpan.FromSeconds(5), Timeout = TimeSpan.FromSeconds(10), DisableCache = true
                };

                mHttpRequest.Send();

                yield return(0);
            }