Esempio n. 1
0
        static void HttpDown_FileNotExit(string httpUrl, Action <string> callback, GameObject sender, string localPath)
        {
            #region 本地文件不存在 开始下载
            //    Debug.Log("Local File Not Exit ");
            HttpProtocolHelper httpLoad = new HttpProtocolHelper();
            httpLoad.m_Url                  = httpUrl;
            httpLoad.m_FilePath             = localPath;
            httpLoad.m_HttpFinishDownHandle = (bool isOK, string _FileName, HttpWebResponse resp) =>
            {
                Loom.QueueOnMainThread(() =>
                {
                    HttpDownLoadCallback(isOK, callback, localPath, httpUrl, resp);
                });
            };
            currentTaskCount++;
            httpLoad.GetHttpFileAndWriteLocalReturnFilePath();  //Begin Get File ,return file path

            #endregion
        }
Esempio n. 2
0
        static void HttpDown_FileExit(string httpUrl, Action <string> callback, GameObject sender, string localPath)
        {
            string _fileRelativeNamePath = FileDirHelper.GetFilePathWithOneDir(httpUrl); //getfile path with one dicrionary path and fileName .

            #region   文件存在
            //Debug.Log("File Exit ::" + localPath);
            HttpProtocolHelper httpHead = new HttpProtocolHelper();
            httpHead.m_Url    = httpUrl;
            httpHead.m_Method = "HEAD";
            httpHead.m_HttpFinishDownHandle = (bool isHttpDownLoadOk, string _FileName, HttpWebResponse response) =>
            {
                Loom.QueueOnMainThread(() =>
                {   //Go to Main Thread
                    CheckWhetherNeedToDown(localPath, response, _fileRelativeNamePath, httpUrl, callback);
                }); //main thread
            };      //handle
            currentTaskCount++;
            ////下载头信息
            httpHead.GetHttpResponse();
            #endregion
        }
Esempio n. 3
0
        static void CheckWhetherNeedToDown(string localPath, HttpWebResponse response, string _fileRelativeNamePath, string httpUrl, Action <string> callback)
        {
            #region   DownLoadHeadComplete
            FileInfo oldFileInfor = new FileInfo(localPath); //Get the file information ,which contain the length and create time atc.
                                                             //Debug.Log(response.ContentLength + "   Old File Length::" + oldFileInfor.Length);
            if (oldFileInfor.Length != response.ContentLength)
            {                                                //文件长度不一致就下载新的
                #region Local File Is Need Update
                Debug.Log("File Need Update  ::" + _fileRelativeNamePath);
                HttpProtocolHelper httpFile = new HttpProtocolHelper();
                httpFile.m_Url                  = httpUrl;
                httpFile.m_FilePath             = localPath;
                httpFile.m_HttpFinishDownHandle = (bool isOk, string _flle, HttpWebResponse res) =>
                {
                    Loom.QueueOnMainThread(() =>
                    {
                        HttpDownLoadCallback(isOk, callback, localPath, httpUrl, res);
                    });
                };

                httpFile.GetHttpFileAndWriteLocalReturnFilePath();  //Begin Get File ,return file path

                #endregion
            }//if
            else
            {//读取本地文件
                #region GetLocalFile
                //Debug.Log("  The local File is the newest , Get Local File ");

                //if (CacheHelper.GetInstance().CacheImageDic2.ContainsKey(httpUrl) == false)
                //    CacheHelper.GetInstance().CacheImageDic2.Add(httpUrl, localPath); //Save Record

                if (callback != null)
                {
                    callback(localPath);  //return local filepath
                }
                #endregion
            }
            #endregion
        }
Esempio n. 4
0
        public static void HttpDownLoadHeadOnly(string httpUrl, Action <string> callback, GameObject sender)
        {
            //   Debug.Log("AA " + currentTaskCount);
            if (currentTaskCount >= MaxTaskCount)
            {
                EventCenter.GetInstance().DelayDoEnumerator(0.1f, () =>
                {
                    HttpDownLoadHeadOnly(httpUrl, callback, sender);
                });
                return;
            }

            HttpProtocolHelper httpHead = new HttpProtocolHelper();

            httpHead.m_Url    = httpUrl;
            httpHead.m_Method = "HEAD";
            httpHead.m_HttpFinishDownHandle = (bool isHttpDownLoadOk, string _FileName, HttpWebResponse response) =>
            {
                Loom.QueueOnMainThread(() =>
                {     //Go to Main Thread
                    if (isHttpDownLoadOk)
                    { //Complete DowLoad
                        if (callback != null)
                        {
                            callback(response.ContentLength.ToString());                    //DownLoad Faile
                        }
                    }
                    else
                    {
                        if (callback != null)
                        {
                            callback(null);                    //DownLoad Faile
                        }
                    }
                });
            };
            currentTaskCount++;
            ////下载头信息
            httpHead.GetHttpResponse();
        }