public static bool IsVersionCached(string url, int version) { CustomCaching.CacheItem cacheItem; string text; return(CustomCaching._IsVersionCached(url, version, out cacheItem, out text)); }
public static WWW LoadFromCacheOrDownload(string url, int version, long fileSize, bool forceUseCustomCache, WWWItem wItem) { if (TsCaching.useCustomCacheOnly || forceUseCustomCache) { return(CustomCaching.LoadFromCacheOrDownload(url, version, fileSize, wItem)); } return(WWW.LoadFromCacheOrDownload(url, version)); }
private static void _RemoveCacheItem(string url) { string key = CustomCaching._UrlToKey(url); if (CustomCaching._cacheList.ContainsKey(key)) { CustomCaching._cacheList.Remove(key); } }
public static bool CleanCache() { TsCaching.SaveLastSpaceOccupied(0L); if (TsCaching.useCustomCacheOnly) { return(CustomCaching.CleanCache()); } return(Caching.CleanCache()); }
private static CustomCaching.CacheItem _GetCacheItem(string url) { CustomCaching.CacheItem cacheItem = null; CustomCaching._cacheList.TryGetValue(CustomCaching._UrlToKey(url), out cacheItem); if (cacheItem == null) { TsLog.Log("CustomCaching._GetCacheItem is null = " + CustomCaching._UrlToKey(url), new object[0]); } return(cacheItem); }
private static bool _IsVersionCached(string url, int version, out CustomCaching.CacheItem cItem, out string localPath) { cItem = CustomCaching._GetCacheItem(url); if (cItem == null || cItem.version < version) { localPath = null; return(false); } localPath = string.Format("{0}{1}", CustomCaching._locRoot, cItem.url); if (!cItem.isExistLocalFile) { cItem.isExistLocalFile = CustomCaching._IsExistLocalFile(localPath); } return(cItem.isExistLocalFile); }
public static void InitiailzeCustomCaching(string url, string local) { if (string.IsNullOrEmpty(url)) { TsLog.LogError("CustomCaching. Fail initialization. web url is null", new object[0]); return; } if (string.IsNullOrEmpty(local)) { TsLog.LogError("CustomCaching. Fail initialization. local path is null", new object[0]); return; } TsLog.LogWarning("$$$SysConfig:InitializeCustomCaching.........", new object[0]); CustomCaching.InitiailzeCustumCaching(url, local); }
public static WWW LoadFromCacheOrDownload(string url, int version, long fileSize, WWWItem wItem) { CustomCaching.CacheItem cacheItem; string arg; bool flag = CustomCaching._IsVersionCached(url, version, out cacheItem, out arg); WWW wWW; if (flag) { if (cacheItem.wref != null && cacheItem.wref.Target != null) { TsLog.Assert(cacheItem.wref.IsAlive, "CustomCaching: Duplicated request! but WWW reference is removed! (url=\"{0}\")", new object[] { cacheItem.url }); wWW = cacheItem.wref.CastedTarget; } else { string url2 = string.Format("file://{0}", arg); wWW = new WWW(url2); } } else { wWW = new WWW(url); if (cacheItem == null) { if (CustomCaching._cacheList.TryGetValue(wItem.assetPath, out cacheItem)) { TsLog.LogWarning("CustomCaching. Duplicated cache list item (path=\"{0}\")", new object[] { wItem.assetPath }); } cacheItem = new CustomCaching.CacheItem(); cacheItem.url = wItem.assetPath; } cacheItem.wref = wWW; cacheItem.version = version; cacheItem.size = fileSize; wItem.SetCallback(new PostProcPerItem(CustomCaching.CallbackSaveAssetBundle), cacheItem); } return(wWW); }
public static void InitiailzeCustumCaching(string url, string local) { CustomCaching._webRoot = url.ToLower(); if (local.Contains(":///")) { CustomCaching._locRoot = local.Substring(8); } else if (local.Contains("://")) { CustomCaching._locRoot = local.Substring(7); } else { CustomCaching._locRoot = local; } CustomCaching._cacheList = new Dictionary <string, CustomCaching.CacheItem>(); CustomCaching._ReadCacheList(); }
private static void CallbackSaveAssetBundle(IDownloadedItem wItem, object obj) { try { CustomCaching.CacheItem cacheItem = obj as CustomCaching.CacheItem; if (cacheItem == null) { TsLog.LogWarning("CacheItem not found. (assetPath=\"{0}\")", new object[] { wItem.assetPath }); } else if (!wItem.isCanceled && string.IsNullOrEmpty(wItem.errorString)) { string text = string.Format("{0}{1}", CustomCaching._locRoot, wItem.assetPath); string[] array = text.Split(new char[] { '/' }); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < array.Length - 1; i++) { stringBuilder.AppendFormat("{0}{1}", array[i], '/'); string path = stringBuilder.ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } } try { if (wItem.rawBytes == null) { throw new NullReferenceException(string.Format("[CustomCache] wItem.rawBytes is null. (path=\"{0}\")\n", wItem.assetPath)); } cacheItem.isExistLocalFile = false; if (File.Exists(text)) { File.Delete(text); } using (FileStream fileStream = File.Create(text)) { using (BinaryWriter binaryWriter = new BinaryWriter(fileStream, Encoding.UTF8)) { byte[] rawBytes = wItem.rawBytes; binaryWriter.Write(rawBytes, 0, rawBytes.Length); long num = (long)rawBytes.Length; CustomCaching._spaceOccupied += cacheItem.size; if (num != cacheItem.size) { TsLog.LogError("Not Match File={0} OrgSize={1} DownSize={2}", new object[] { wItem.assetPath, cacheItem.size, num }); if (CustomCaching._cacheList.ContainsKey(cacheItem.url)) { CustomCaching._cacheList.Remove(cacheItem.url); } if (File.Exists(text)) { File.Delete(text); } } else if (!CustomCaching._cacheList.ContainsKey(cacheItem.url)) { CustomCaching._cacheList.Add(wItem.assetPath, cacheItem); } else { CustomCaching._cacheList.Remove(cacheItem.url); CustomCaching._cacheList.Add(wItem.assetPath, cacheItem); } } } } catch (Exception ex) { CustomCaching._RemoveCacheItem(cacheItem.url); TsLog.Assert(false, "Cache file save error! (Path=\"{1}\") : {0}", new object[] { ex, text }); } cacheItem.wref = null; } else { CustomCaching._RemoveCacheItem(cacheItem.url); TsLog.LogError("CustomCaching. Error file saving (url=\"{0}\", error={1}, canceled={2})", new object[] { cacheItem.url, wItem.errorString, wItem.isCanceled }); } TsCaching.SaveCacheList(); } catch (Exception obj2) { TsLog.LogWarning(obj2); } }
public static void SaveCacheList() { CustomCaching.SaveCacheList(); }
public static bool IsVersionCached(string url, int version, bool forceUseCustomCache) { bool flag = (!TsCaching.useCustomCacheOnly && !forceUseCustomCache) ? Caching.IsVersionCached(url, version) : CustomCaching.IsVersionCached(url, version); if (Option.EnableTrace) { TsLog.Log("[TsBundle] IsVersionCached( url=\"{0}\", version={1} ) => {2}", new object[] { url, version, flag }); } return(flag); }