private void OnCheckerResourceCheckComplete(int removedCount, int updateCount, long updateTotalLength, long updateTotalZipLength) { m_VersionListProcessor.VersionListUpdateSuccess -= OnVersionListProcessorUpdateSuccess; m_VersionListProcessor.VersionListUpdateFailure -= OnVersionListProcessorUpdateFailure; m_VersionListProcessor.Shutdown(); m_VersionListProcessor = null; m_UpdateVersionListCallbacks = null; m_ResourceChecker.ResourceNeedUpdate -= OnCheckerResourceNeedUpdate; m_ResourceChecker.ResourceCheckComplete -= OnCheckerResourceCheckComplete; m_ResourceChecker.Shutdown(); m_ResourceChecker = null; m_ResourceUpdater.CheckResourceComplete(removedCount > 0); if (updateCount <= 0) { m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart; m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged; m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess; m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure; m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete; m_ResourceUpdater.Shutdown(); m_ResourceUpdater = null; m_UpdateFileCache = null; if (m_DecompressCache != null) { m_DecompressCache.Dispose(); m_DecompressCache = null; } } CheckResourcesCompleteCallback(updateCount > 0, removedCount, updateCount, updateTotalLength, updateTotalZipLength); CheckResourcesCompleteCallback = null; }
private void OnDownloadFailure(int serialId, string downloadPath, string downloadUri, string errorMessage, object userData) { VersionListProcessor versionListProcessor = userData as VersionListProcessor; if (versionListProcessor == null || versionListProcessor != this) { return; } if (File.Exists(downloadPath)) { File.Delete(downloadPath); } if (VersionListUpdateFailure != null) { VersionListUpdateFailure(downloadUri, errorMessage); } }
/// <summary> /// 设置资源模式 /// </summary> /// <param name="resourceMode">资源模式</param> public void SetResourceMode(ResourceMode resourceMode) { if (resourceMode == ResourceMode.Unspecified) { throw new Exception("Resource mode is invalid."); } if (m_ResourceMode == ResourceMode.Unspecified) { m_ResourceMode = resourceMode; if (m_ResourceMode == ResourceMode.Package) { m_ResourceIniter = new ResourceIniter(this); m_ResourceIniter.ResourceInitComplete += OnIniterResourceInitComplete; } else if (m_ResourceMode == ResourceMode.Updatable) { m_VersionListProcessor = new VersionListProcessor(this); m_VersionListProcessor.VersionListUpdateSuccess += OnVersionListProcessorUpdateSuccess; m_VersionListProcessor.VersionListUpdateFailure += OnVersionListProcessorUpdateFailure; m_ResourceChecker = new ResourceChecker(this); m_ResourceChecker.ResourceNeedUpdate += OnCheckerResourceNeedUpdate; m_ResourceChecker.ResourceCheckComplete += OnCheckerResourceCheckComplete; m_ResourceUpdater = new ResourceUpdater(this); m_ResourceUpdater.ResourceUpdateStart += OnUpdaterResourceUpdateStart; m_ResourceUpdater.ResourceUpdateChanged += OnUpdaterResourceUpdateChanged; m_ResourceUpdater.ResourceUpdateSuccess += OnUpdaterResourceUpdateSuccess; m_ResourceUpdater.ResourceUpdateFailure += OnUpdaterResourceUpdateFailure; m_ResourceUpdater.ResourceUpdateAllComplete += OnUpdaterResourceUpdateAllComplete; } } else if (m_ResourceMode != resourceMode) { throw new Exception("You can not change resource mode at this time."); } }
public override void Dispose() { if (m_ResourceIniter != null) { m_ResourceIniter.Shutdown(); m_ResourceIniter = null; } if (m_VersionListProcessor != null) { m_VersionListProcessor.VersionListUpdateSuccess -= OnVersionListProcessorUpdateSuccess; m_VersionListProcessor.VersionListUpdateFailure -= OnVersionListProcessorUpdateFailure; m_VersionListProcessor.Shutdown(); m_VersionListProcessor = null; } if (m_ResourceChecker != null) { m_ResourceChecker.ResourceNeedUpdate -= OnCheckerResourceNeedUpdate; m_ResourceChecker.ResourceCheckComplete -= OnCheckerResourceCheckComplete; m_ResourceChecker.Shutdown(); m_ResourceChecker = null; } if (m_ResourceUpdater != null) { m_ResourceUpdater.ResourceUpdateStart -= OnUpdaterResourceUpdateStart; m_ResourceUpdater.ResourceUpdateChanged -= OnUpdaterResourceUpdateChanged; m_ResourceUpdater.ResourceUpdateSuccess -= OnUpdaterResourceUpdateSuccess; m_ResourceUpdater.ResourceUpdateFailure -= OnUpdaterResourceUpdateFailure; m_ResourceUpdater.ResourceUpdateAllComplete -= OnUpdaterResourceUpdateAllComplete; m_ResourceUpdater.Shutdown(); m_ResourceUpdater = null; m_UpdateFileCache = null; if (m_DecompressCache != null) { m_DecompressCache.Dispose(); m_DecompressCache = null; } } m_AssetBundleManifest = null; if (s_ResourceNames != null) { s_ResourceNames.Clear(); s_ResourceNames = null; } if (m_AssetInfos != null) { m_AssetInfos.Clear(); m_AssetInfos = null; } if (m_ResourceInfos != null) { m_ResourceInfos.Clear(); m_ResourceInfos = null; } m_ReadWriteResourceInfos.Clear(); m_TaskPool.Shutdown(); m_AssetPool.Shutdown(); m_AssetBundlePool.Shutdown(); }
private void OnDownloadSuccess(int serialId, string downloadPath, string downloadUri, int currentLength, object userData) { VersionListProcessor versionListProcessor = userData as VersionListProcessor; if (versionListProcessor == null || versionListProcessor != this) { return; } using (FileStream fileStream = new FileStream(downloadPath, FileMode.Open, FileAccess.ReadWrite)) { int length = (int)fileStream.Length; if (length != m_VersionListZipLength) { fileStream.Close(); string errorMessage = TextUtil.Format("Latest version list zip length error, need '{0}', downloaded '{1}'.", m_VersionListZipLength.ToString(), length.ToString()); OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData); return; } if (m_UpdateFileCache == null || m_UpdateFileCache.Length < length) { m_UpdateFileCache = new byte[(length / OneMegaBytes + 1) * OneMegaBytes]; } int offset = 0; int count = length; while (count > 0) { int bytesRead = fileStream.Read(m_UpdateFileCache, offset, count); if (bytesRead <= 0) { throw new Exception(TextUtil.Format("Unknown error when load file '{0}'.", downloadPath)); } offset += bytesRead; count -= bytesRead; } int hashCode = ConverterUtil.GetInt32(VerifierUtil.GetCrc32(m_UpdateFileCache, 0, length)); if (hashCode != m_VersionListZipHashCode) { fileStream.Close(); string errorMessage = TextUtil.Format("Latest version list zip hash code error, need '{0}', downloaded '{1}'.", m_VersionListZipHashCode.ToString("X8"), hashCode.ToString("X8")); OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData); return; } try { if (m_DecompressCache == null) { m_DecompressCache = new MemoryStream(); } m_DecompressCache.Position = 0L; m_DecompressCache.SetLength(0L); if (!ZipUtil.Decompress(m_UpdateFileCache, 0, length, m_DecompressCache)) { fileStream.Close(); string errorMessage = TextUtil.Format("Unable to decompress latest version list '{0}'.", downloadPath); OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData); return; } if (m_DecompressCache.Length != m_VersionListLength) { fileStream.Close(); string errorMessage = TextUtil.Format("Latest version list length error, need '{0}', downloaded '{1}'.", m_VersionListLength.ToString(), m_DecompressCache.Length.ToString()); OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData); return; } fileStream.Position = 0L; fileStream.SetLength(0L); m_DecompressCache.Position = 0L; int bytesRead = 0; while ((bytesRead = m_DecompressCache.Read(m_UpdateFileCache, 0, m_UpdateFileCache.Length)) > 0) { fileStream.Write(m_UpdateFileCache, 0, bytesRead); } } catch (Exception exception) { fileStream.Close(); string errorMessage = TextUtil.Format("Unable to decompress latest version list '{0}' with error message '{1}'.", downloadPath, exception.Message); OnDownloadFailure(serialId, downloadPath, downloadUri, errorMessage, userData); return; } } if (VersionListUpdateSuccess != null) { VersionListUpdateSuccess(downloadPath, downloadUri); } }