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); } } }
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(); } }