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; }
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(); }
private IEnumerator GetDownloader(rRes data) { if (data.FileName.EndsWith(".zip")) { return(IDownloadZip(mIp, mHostName, data)); } return(IDownloadBundle(mIp, mHostName, data)); }
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); }
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(); }
protected abstract IEnumerator IDownloadZip(string ip, string hostName, rRes data);
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(); }