using System; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using UnityEngine; namespace AssetUpdate { public class AssetCompareAction : IAssetAsyncAction { public readonly List downloadList = new List(); public Dictionary streamingPathInfo { get; private set; } public bool isEnd { get; private set; } public bool UpdateTimeout() { return isEnd; } public void Start(AssetDependencyInfo target) { var streamingText = Resources.Load(AssetConst.assetPathDataPath.Open(AssetConst.pathFile)); var formatter = new BinaryFormatter(); try { using (var ms = new MemoryStream(streamingText.bytes)) streamingPathInfo = formatter.Deserialize(ms) as Dictionary; } catch (Exception e) { Debug.LogError(e); } if (streamingPathInfo == null) throw new NullReferenceException("Failed to load streamingPathInfo, this is not recoverable!"); Dictionary persist = null; var persistTextPath = AssetConst.persistentDataPath.Open(AssetConst.pathFile + AssetConst.bytesExtension); if (File.Exists(persistTextPath)) { try { using (var fs = File.OpenRead(persistTextPath)) persist = formatter.Deserialize(fs) as Dictionary; } catch (Exception e) { Debug.LogError(e); } } foreach (var asset in target.assetList) if (asset.level >= AssetLevel.onInit) { string md5; if (streamingPathInfo.TryGetValue(asset.name, out md5) && md5 == asset.md5) continue; if (persist != null && persist.TryGetValue(asset.name, out md5)) { if (md5 != asset.md5) { #if UNITY_EDITOR Debug.LogWarning(string.Format("Replacing asset {0} with new version!", asset.name)); #endif } else continue; } downloadList.Add(asset); } isEnd = true; } public void Dispose() { } } }