Exemplo n.º 1
0
 private void Record(rRes data)
 {
     //檢查紀錄檔是否存在
     if (mRecordMap == null)
     {
         mRecordMap = new Dictionary <string, string>();
         mRecordMap.Add(data.Path + data.FileName, data.MD5Code);
     }
     else
     {
         //檢查BundleKey是否存在
         if (mRecordMap.ContainsKey(data.Path + data.FileName) == true)
         {
             //檢查MD5碼
             if (String.Compare(mRecordMap[data.Path + data.FileName], data.MD5Code, false) != 0)
             {
                 mRecordMap[data.Path + data.FileName] = data.MD5Code;
             }
         }
         else
         {
             mRecordMap.Add(data.Path + data.FileName, data.MD5Code);
         }
     }
     mDownloadCount++;
     mNowSize += data.FileSize;
 }
Exemplo n.º 2
0
        protected override IEnumerator IDownloadBundle(string ip, string hostName, rRes data)
        {
            mLogger.Log("start download -> " + data.FileName);

            //設置下載路徑
            string dPath = GetLocation(ip, hostName) + data.Path + data.FileName;
            string sPath = TinyContext.Instance.DataPath + data.Path + data.FileName;

            //TODO:下載動作
            yield return(null);

            string error  = null;
            bool   isDone = false;

            if ((error == null) && (isDone == true))
            {
            }
            else
            {
                mStatus = eStatus.Error;
                mOnError.InvokeGracefully(string.Format("下載失敗 -> {0}", error));
                mLogger.Log(string.Format("下載失敗 -> {0}", error));
            }
            mLogger.Log("end download -> " + data.FileName);
            Resources.UnloadUnusedAssets();
        }
Exemplo n.º 3
0
        private IEnumerator GetDownloader(rRes data)
        {
            if (data.FileName.EndsWith(".zip"))
            {
                return(IDownloadZip(mIp, mHostName, data));
            }

            return(IDownloadBundle(mIp, mHostName, data));
        }
Exemplo n.º 4
0
        private bool CheckNeedUpdate(rRes data)
        {
            string path = TinyContext.Instance.DataPath + data.Path + data.FileName;

#if UNITY_TVOS && !UNITY_EDITOR
            //檢查檔案是否存在
            if (!File.Exists(path))
            {
                return(true);
            }
#else
            //檢查是否為壓縮檔
            if (!data.FileName.EndsWith(".zip"))
            {
#if !UNITY_ANDROID || UNITY_EDITOR
                //檢查檔案是否存在
                if (!File.Exists(path))
                {
                    return(true);
                }
#endif
            }
#endif

            //檢查紀錄檔是否存在
            if (mRecordMap == null)
            {
                mRecordMap = new Dictionary <string, string>();
                return(true);
            }
            else
            {
                //檢查BundleKey是否存在
                if (!mRecordMap.ContainsKey(data.Path + data.FileName))
                {
                    return(true);
                }

                //檢查BundleKey值是否相符
                if (String.Compare(mRecordMap[data.Path + data.FileName], data.MD5Code, false) != 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        protected override IEnumerator IDownloadBundle(string ip, string hostName, rRes data)
        {
            mLogger.Log("start download -> " + data.FileName);

            //設置下載路徑
            string path = GetLocation(ip, hostName) + data.Path + data.FileName;

            using (WWW bundle = new WWW(path))
            {
                yield return(bundle);

                //檢查下載錯誤訊息
                if (bundle.error != null)
                {
                    mStatus = eStatus.Error;
                    mOnError.InvokeGracefully(bundle.error);
                    mLogger.Log(bundle.error);
                    yield break;
                }

                //檢查是否下載完成
                if (bundle.isDone == true)
                {
                    //設置存檔路徑
                    string sPath = TinyContext.Instance.DataPath + data.Path;
                    string sName = data.FileName;
                    TFile.Save(sPath, sName, bundle.bytes);
                }
                else
                {
                    mStatus = eStatus.Error;
                    mOnError.InvokeGracefully(string.Format("下載失敗 -> {0}", bundle.url));
                    mLogger.Log(string.Format("下載失敗 -> {0}", bundle.url));
                }
            }
            mLogger.Log("end download -> " + data.FileName);
            Resources.UnloadUnusedAssets();
        }
Exemplo n.º 6
0
 protected abstract IEnumerator IDownloadZip(string ip, string hostName, rRes data);
Exemplo n.º 7
0
        protected override IEnumerator IDownloadZip(string ip, string hostName, rRes data)
        {
            mLogger.Log("start download -> " + data.FileName);

            //設置下載路徑
            string dPath = GetLocation(ip, hostName) + data.Path + data.FileName;
            string sPath = TinyContext.Instance.DataPath + data.Path + data.FileName;

            //TODO:下載動作
            yield return(null);

            string error  = null;
            bool   isDone = false;

            if ((error == null) && (isDone == true))
            {
                using (FileStream fileStream = new FileStream(sPath, FileMode.Open, FileAccess.Read))
                {
                    using (ZipInputStream zipInputStream = new ZipInputStream(fileStream))
                    {
                        ZipEntry zipEntry;

                        // 逐一取出壓縮檔內的檔案(解壓縮)
                        while ((zipEntry = zipInputStream.GetNextEntry()) != null)
                        {
                            string zPath = TinyContext.Instance.DataPath + data.Path + zipEntry.Name;

                            //檢查是否存在舊檔案
                            if (File.Exists(zPath) == true)
                            {
                                File.Delete(zPath);
                            }

                            mLogger.Log(zipEntry.Name);

                            using (FileStream fs = File.Create(zPath))
                            {
                                while (true)
                                {
                                    int size = zipInputStream.Read(mBuffer, 0, mBuffer.Length);

                                    if (size > 0)
                                    {
                                        fs.Write(mBuffer, 0, size);
                                    }
                                    else
                                    {
                                        break;
                                    }

                                    yield return(null);
                                }
                                fs.Close();
                            }
                            yield return(null);
                        }
                        zipInputStream.Close();
                    }
                    fileStream.Close();
                }

#if !UNITY_TVOS || UNITY_EDITOR
                File.Delete(sPath);
#endif
            }
            else
            {
                mStatus = eStatus.Error;
                mOnError.InvokeGracefully(string.Format("下載失敗 -> {0}", error));
                mLogger.Log(string.Format("下載失敗 -> {0}", error));
            }
            mLogger.Log("end download -> " + data.FileName);
            Resources.UnloadUnusedAssets();
        }