private void DownloadConfig() { mFValue = 0.5f; UpdateLoadCompressProgress(0f); string streamPath = BundleCommon.StreamAssetVersionPath; string streamUserPath = BundleCommon.StreamUserVersionPath; if (!Directory.Exists(Application.persistentDataPath + "/" + BundleCommon.ResVersion + "/Inner")) { Directory.CreateDirectory(Application.persistentDataPath + "/" + BundleCommon.ResVersion + "/Inner"); } if (!File.Exists(streamUserPath)) { new WWWDownloadTask(streamPath, OnGetStreamABList); } else { try { streamConfigs = XMLTool.LoadAllABConfig(BundleCommon.StreamUserVersionPath, true); GetRemoteVersion(); } catch (Exception e) { LogMgr.UnityLog(e.ToString()); File.Delete(streamUserPath); new WWWDownloadTask(streamPath, OnGetStreamABList); } } }
private void ABProcess() { LogMgr.UnityLog("ABProcess # " + mIdx + " Started .."); while (!isExit) { int count = 0; DownloadedItem item = null; string mSaveFile = null; AssetBundleConfig mConfig = null; lock (HttpDownload.shareObject) { count = HttpDownload.downloadedQueue.Count; if (count > 0) { item = HttpDownload.downloadedQueue[0]; HttpDownload.downloadedQueue.RemoveAt(0); } } LogMgr.UnityLog("ABProcessor mid: " + mIdx); if (null != item) { mSaveFile = item.saveFile; mConfig = item.config; string outFilePath = mSaveFile.Replace("_Compress", ""); if (File.Exists(outFilePath)) { File.Delete(outFilePath); } LZMATool.DecompressFileLZMA(mSaveFile, outFilePath); if (File.Exists(mSaveFile)) { File.Delete(mSaveFile); } if (null != mConfig) { List <AssetBundleConfig> bundleConfigGroup = new List <AssetBundleConfig>(); bundleConfigGroup.Add(mConfig); XMLTool.SaveABConfig(HttpDownloadTask.configPath, bundleConfigGroup); LogMgr.UnityLog("HttpDownLoad SaveABConfig: " + count + "," + mConfig.RelativePath + "," + mConfig.ABName + "," + mConfig.Build + "," + Thread.CurrentThread.ManagedThreadId + ",@" + mIdx ); } } else { LogMgr.UnityLog("ABProcessor continue " + mIdx); Thread.Sleep(10); } } }
private void WriteVersionDataToDB() { List <AssetBundleConfig> bundleConfigGroup = new List <AssetBundleConfig>(); foreach (AssetBundleConfig child in mAllVersionDataDic.Values) { bundleConfigGroup.Add(child); } mAllVersionDataDic.Clear(); mTempDownLoadFileSize = 0; XMLTool.SaveABConfig(BundleCommon.UserVersionPath, bundleConfigGroup); }
public void DoStreamAssetDecompress(AssetUpdateMgr parent, Action finishCallback) { LogMgr.UnityError(Time.realtimeSinceStartup.ToString()); mParent = parent; mFinishCallback = finishCallback; mParent.UpdateProgress("正从本地解压缩资源(此过程不消耗流量)", 0f); mStreamFiles.Clear(); string abtoFile = string.Format("{0}/{1}/Inner/{2}", Application.persistentDataPath, BundleCommon.ResVersion, BundleCommon.AssetBundleManifest); if (!File.Exists(abtoFile)) { mStreamFiles.Add("/" + BundleCommon.AssetBundleManifest); } List <AssetBundleConfig> streamConfigs = XMLTool.LoadAllABConfig(BundleCommon.StreamUserVersionPath, true); if (null != streamConfigs) { for (int i = 0; i < streamConfigs.Count; i++) { string toFilePath = Application.persistentDataPath + "/" + BundleCommon.ResVersion + "/Inner" + streamConfigs[i].RelativePath; string toFileDir = toFilePath.Remove(toFilePath.LastIndexOf("/")); if (!Directory.Exists(toFileDir)) { Directory.CreateDirectory(toFileDir); } if (!File.Exists(toFilePath)) { mStreamFiles.Add(streamConfigs[i].RelativePath); } } } mCurCopyNum = 0; mMaxCopyNum = 5; mFinishCopyNum = 0; mTotalCopyNum = mStreamFiles.Count; if (mTotalCopyNum != 0) { CopyAsset(); } else { mParent.UpdateProgress("正从本地解压缩资源(此过程不消耗流量)", 1f); if (null != mFinishCallback) { mFinishCallback(); } } }
/// <summary> /// Step 4:对比本地和服务器配置数据信息 /// </summary> /// <param name="remoteVersionPath"></param> private void CompareVersion(string remoteVersionPath) { mParent.UpdateProgress("比对更新文件中", 0); string remoteABPath = Application.persistentDataPath + "/" + BundleCommon.ResVersion + "/Out/assetbundle"; AssetBundle remoteAB = null; AssetBundleManifest remoteABM = null; if (File.Exists(remoteABPath)) { remoteAB = AssetBundle.LoadFromFile(remoteABPath); } if (null != remoteAB) { remoteABM = remoteAB.LoadAsset("AssetBundleManifest") as AssetBundleManifest; remoteAB.Unload(false); } remoteConfigs = XMLTool.LoadAllABConfig(remoteVersionPath); localConfigs = XMLTool.LoadAllABConfig(BundleCommon.UserVersionPath); streamConfigs = XMLTool.LoadAllABConfig(BundleCommon.StreamUserVersionPath, true); updateABConfigs = new List <AssetBundleConfig>(); if (null != remoteConfigs) { Dictionary <string, AssetBundleConfig> localConfigDict = new Dictionary <string, AssetBundleConfig>(); Dictionary <string, AssetBundleConfig> remoteConfigDict = new Dictionary <string, AssetBundleConfig>(); Dictionary <string, AssetBundleConfig> streamConfigDict = new Dictionary <string, AssetBundleConfig>(); Dictionary <string, string[]> dps = new Dictionary <string, string[]>(); for (int i = 0; i < remoteConfigs.Count; i++) { remoteConfigDict[remoteConfigs[i].RelativePath] = remoteConfigs[i]; mABFileMgr.AddABFile(remoteConfigs[i]); } for (int i = 0; i < localConfigs.Count; i++) { localConfigDict[localConfigs[i].ABName] = localConfigs[i]; } if (null != streamConfigs) { for (int i = 0; i < streamConfigs.Count; i++) { streamConfigDict[streamConfigs[i].ABName] = streamConfigs[i]; } } int totalSize = remoteConfigs.Count; for (int i = 0; i < totalSize; i++) { AssetBundleConfig localCfg = null; AssetBundleConfig streamCfg = null; bool isNew = false; if (localConfigDict.TryGetValue(remoteConfigs[i].ABName, out localCfg)) { if (localCfg.MD5Value.Equals(remoteConfigs[i].MD5Value)) { isNew = false; mABFileMgr.SetABFileState(remoteConfigs[i].RelativePath, ABFileState.DOWNLOADED); } else { isNew = true; } } else { if (streamConfigDict.TryGetValue(remoteConfigs[i].ABName, out streamCfg)) { if (streamCfg.MD5Value.Equals(remoteConfigs[i].MD5Value)) { isNew = false; mABFileMgr.SetABFileState(remoteConfigs[i].RelativePath, ABFileState.STREAMEXIT); } else { isNew = true; } } else { isNew = true; } } if (isNew) { string relativePath = remoteConfigs[i].RelativePath; string[] dp = remoteABM.GetAllDependencies(relativePath.Substring(1, relativePath.Length - 1)); dps[relativePath] = dp; } } if (dps.Count > 0) { CompareThread.StartCompare(remoteConfigs, remoteConfigDict, localConfigDict, streamConfigDict, dps, updateABConfigs, CompareProgress, CompareFinish); } else { CompareFinish(); } } else { CompareFinish(); } }
private void DownLoadFile() { bool bExit = false; bool bTask = false; bool bPause = false; bool bProcess = false; lock (mLockObject) { bExit = mIsExit; } while (!bExit) { lock (mLockObject) { bTask = mHasTask; bPause = mIsPause; bExit = mIsExit; bProcess = mIsProcess; } if (!bTask || bPause || bProcess) { //LogMgr.UnityLog("DownLoadFile continue: "); Thread.Sleep(10); continue; } try { lock (mLockObject) { bProcess = true; } string localFileDir = mSaveFile.Remove(mSaveFile.LastIndexOf("/")); if (!Directory.Exists(localFileDir)) { Directory.CreateDirectory(localFileDir); } HttpWebRequest request = WebRequest.Create(mUrl + BundleCommon.GetRandomUrl()) as HttpWebRequest; WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); byte[] buffer = new byte[mBufferSize]; FileStream fileStream = new FileStream(mSaveFile, FileMode.OpenOrCreate); int readSize = stream.Read(buffer, 0, mBufferSize); while (readSize > 0 && !bPause && !bExit) { fileStream.Write(buffer, 0, readSize); mDownloadedSize += readSize; readSize = stream.Read(buffer, 0, mBufferSize); lock (mLockObject) { bPause = mIsPause; bExit = mIsExit; } } stream.Close(); fileStream.Close(); response.Close(); DownloadedItem item = new DownloadedItem(); item.saveFile = mSaveFile; item.config = mConfig; lock (shareObject) { downloadedQueue.Add(item); } if (!bPause && !bExit) { string outFilePath = mSaveFile.Replace("_Compress", ""); if (File.Exists(outFilePath)) { File.Delete(outFilePath); } LZMATool.DecompressFileLZMA(mSaveFile, outFilePath); if (File.Exists(mSaveFile)) { File.Delete(mSaveFile); } if (null != mConfig) { List <AssetBundleConfig> bundleConfigGroup = new List <AssetBundleConfig>(); bundleConfigGroup.Add(mConfig); lock (mLockObject) { XMLTool.SaveABConfig(HttpDownloadTask.configPath, bundleConfigGroup); LogMgr.UnityLog("HttpDownLoad SaveABConfig: " + mConfig.RelativePath + "," + mConfig.ABName + "," + mConfig.Build ); } } if (null != mFinishCallback) { mFinishCallback(true); } } } catch (Exception e) { LogMgr.UnityError("download file error:" + e.ToString()); if (null != mFinishCallback && !bPause && !bExit) { mFinishCallback(false); } } lock (mLockObject) { bExit = mIsExit; mIsProcess = false; mHasTask = false; } } }