public void Read(byte[] data, ref int offset) { this.m_cachedTextureInfos.Clear(); this.m_cachedTextureInfoMap.Clear(); if (data != null) { int num = data.Length - offset; if (num >= 6) { int num2 = CMemoryManager.ReadInt(data, ref offset); if (((num2 >= 6) && (num2 <= num)) && (CMemoryManager.ReadShort(data, ref offset) == 0x2713)) { int num4 = CMemoryManager.ReadShort(data, ref offset); for (int i = 0; i < num4; i++) { CCachedTextureInfo info = new CCachedTextureInfo { m_key = CMemoryManager.ReadString(data, ref offset), m_width = CMemoryManager.ReadShort(data, ref offset), m_height = CMemoryManager.ReadShort(data, ref offset), m_lastModifyTime = CMemoryManager.ReadDateTime(data, ref offset), m_isGif = CMemoryManager.ReadByte(data, ref offset) > 0 }; if (!this.m_cachedTextureInfoMap.ContainsKey(info.m_key)) { this.m_cachedTextureInfoMap.Add(info.m_key, info); this.m_cachedTextureInfos.Add(info); } } this.m_cachedTextureInfos.Sort(); } } } }
public Texture2D GetCachedTexture(string url) { string key = CFileManager.GetMd5(url.ToLower()); CCachedTextureInfo cachedTextureInfo = this.m_cachedTextureInfoSet.GetCachedTextureInfo(key); if (cachedTextureInfo != null) { TimeSpan span = (TimeSpan)(DateTime.Now - cachedTextureInfo.m_lastModifyTime); if (span.TotalDays < 2.0) { string filePath = CFileManager.CombinePath(s_cachedTextureDirectory, key + ".bytes"); if (!CFileManager.IsFileExist(filePath)) { return(null); } byte[] buffer = CFileManager.ReadFile(filePath); if ((buffer == null) || (buffer.Length <= 0)) { return(null); } Texture2D textured = null; if (cachedTextureInfo.m_isGif) { using (MemoryStream stream = new MemoryStream(buffer)) { return(GifHelper.GifToTexture(stream, 0)); } } textured = new Texture2D(cachedTextureInfo.m_width, cachedTextureInfo.m_height, TextureFormat.ARGB32, false); textured.LoadImage(buffer); return(textured); } } return(null); }
public void AddTextureInfo(string key, CCachedTextureInfo cachedTextureInfo) { if (!this.m_cachedTextureInfoMap.ContainsKey(key)) { this.m_cachedTextureInfoMap.Add(key, cachedTextureInfo); this.m_cachedTextureInfos.Add(cachedTextureInfo); } }
public CCachedTextureInfo GetCachedTextureInfo(string key) { if (this.m_cachedTextureInfoMap.ContainsKey(key)) { CCachedTextureInfo result = null; this.m_cachedTextureInfoMap.TryGetValue(key, ref result); return(result); } return(null); }
public CCachedTextureInfo GetCachedTextureInfo(string key) { if (this.m_cachedTextureInfoMap.ContainsKey(key)) { CCachedTextureInfo info = null; this.m_cachedTextureInfoMap.TryGetValue(key, out info); return(info); } return(null); }
public void AddCachedTexture(string url, int width, int height, bool isGif, byte[] data) { string key = CFileManager.GetMd5(url.ToLower()); if (this.m_cachedTextureInfoSet.m_cachedTextureInfoMap.ContainsKey(key)) { CCachedTextureInfo info = null; this.m_cachedTextureInfoSet.m_cachedTextureInfoMap.TryGetValue(key, out info); DebugHelper.Assert(this.m_cachedTextureInfoSet.m_cachedTextureInfos.Contains(info), "zen me ke neng?"); info.m_width = width; info.m_height = height; info.m_lastModifyTime = DateTime.Now; info.m_isGif = isGif; } else { if (this.m_cachedTextureInfoSet.m_cachedTextureInfos.Count >= 100) { string str2 = this.m_cachedTextureInfoSet.RemoveEarliestTextureInfo(); if (!string.IsNullOrEmpty(str2)) { string str3 = CFileManager.CombinePath(s_cachedTextureDirectory, str2 + ".bytes"); if (CFileManager.IsFileExist(str3)) { CFileManager.DeleteFile(str3); } } } CCachedTextureInfo cachedTextureInfo = new CCachedTextureInfo { m_key = key, m_width = width, m_height = height, m_lastModifyTime = DateTime.Now, m_isGif = isGif }; this.m_cachedTextureInfoSet.AddTextureInfo(key, cachedTextureInfo); } this.m_cachedTextureInfoSet.SortTextureInfo(); int offset = 0; this.m_cachedTextureInfoSet.Write(s_buffer, ref offset); if (CFileManager.IsFileExist(s_cachedTextureInfoSetFileFullPath)) { CFileManager.DeleteFile(s_cachedTextureInfoSetFileFullPath); } CFileManager.WriteFile(s_cachedTextureInfoSetFileFullPath, s_buffer, 0, offset); string filePath = CFileManager.CombinePath(s_cachedTextureDirectory, key + ".bytes"); if (CFileManager.IsFileExist(filePath)) { CFileManager.DeleteFile(filePath); } CFileManager.WriteFile(filePath, data); }
public string RemoveEarliestTextureInfo() { if (this.m_cachedTextureInfos.get_Count() <= 0) { return(null); } CCachedTextureInfo cCachedTextureInfo = this.m_cachedTextureInfos.get_Item(0); this.m_cachedTextureInfos.RemoveAt(0); this.m_cachedTextureInfoMap.Remove(cCachedTextureInfo.m_key); return(cCachedTextureInfo.m_key); }
public void AddCachedTexture(string url, int width, int height, bool isGif, byte[] data) { string md = CFileManager.GetMd5(url.ToLower()); if (this.m_cachedTextureInfoSet.m_cachedTextureInfoMap.ContainsKey(md)) { CCachedTextureInfo cCachedTextureInfo = null; this.m_cachedTextureInfoSet.m_cachedTextureInfoMap.TryGetValue(md, ref cCachedTextureInfo); DebugHelper.Assert(this.m_cachedTextureInfoSet.m_cachedTextureInfos.Contains(cCachedTextureInfo), "zen me ke neng?"); cCachedTextureInfo.m_width = width; cCachedTextureInfo.m_height = height; cCachedTextureInfo.m_lastModifyTime = DateTime.get_Now(); cCachedTextureInfo.m_isGif = isGif; } else { if (this.m_cachedTextureInfoSet.m_cachedTextureInfos.get_Count() >= 100) { string text = this.m_cachedTextureInfoSet.RemoveEarliestTextureInfo(); if (!string.IsNullOrEmpty(text)) { string text2 = CFileManager.CombinePath(CCachedTextureManager.s_cachedTextureDirectory, text + ".bytes"); if (CFileManager.IsFileExist(text2)) { CFileManager.DeleteFile(text2); } } } CCachedTextureInfo cCachedTextureInfo2 = new CCachedTextureInfo(); cCachedTextureInfo2.m_key = md; cCachedTextureInfo2.m_width = width; cCachedTextureInfo2.m_height = height; cCachedTextureInfo2.m_lastModifyTime = DateTime.get_Now(); cCachedTextureInfo2.m_isGif = isGif; this.m_cachedTextureInfoSet.AddTextureInfo(md, cCachedTextureInfo2); } this.m_cachedTextureInfoSet.SortTextureInfo(); int num = 0; this.m_cachedTextureInfoSet.Write(CCachedTextureManager.s_buffer, ref num); if (CFileManager.IsFileExist(CCachedTextureManager.s_cachedTextureInfoSetFileFullPath)) { CFileManager.DeleteFile(CCachedTextureManager.s_cachedTextureInfoSetFileFullPath); } CFileManager.WriteFile(CCachedTextureManager.s_cachedTextureInfoSetFileFullPath, CCachedTextureManager.s_buffer, 0, num); string text3 = CFileManager.CombinePath(CCachedTextureManager.s_cachedTextureDirectory, md + ".bytes"); if (CFileManager.IsFileExist(text3)) { CFileManager.DeleteFile(text3); } CFileManager.WriteFile(text3, data); }
public string RemoveEarliestTextureInfo() { if (this.m_cachedTextureInfos.Count <= 0) { return(null); } CCachedTextureInfo info = this.m_cachedTextureInfos[0]; this.m_cachedTextureInfos.RemoveAt(0); this.m_cachedTextureInfoMap.Remove(info.m_key); return(info.m_key); }
public int CompareTo(object obj) { CCachedTextureInfo info = obj as CCachedTextureInfo; if (this.m_lastModifyTime > info.m_lastModifyTime) { return(1); } if (this.m_lastModifyTime == info.m_lastModifyTime) { return(0); } return(-1); }
public void Read(byte[] data, ref int offset) { this.m_cachedTextureInfos.Clear(); this.m_cachedTextureInfoMap.Clear(); if (data == null) { return; } int num = data.Length - offset; if (num < 6) { return; } int num2 = CMemoryManager.ReadInt(data, ref offset); if (num2 < 6 || num2 > num) { return; } int num3 = CMemoryManager.ReadShort(data, ref offset); if (num3 != 10003) { return; } int num4 = CMemoryManager.ReadShort(data, ref offset); for (int i = 0; i < num4; i++) { CCachedTextureInfo cCachedTextureInfo = new CCachedTextureInfo(); cCachedTextureInfo.m_key = CMemoryManager.ReadString(data, ref offset); cCachedTextureInfo.m_width = CMemoryManager.ReadShort(data, ref offset); cCachedTextureInfo.m_height = CMemoryManager.ReadShort(data, ref offset); cCachedTextureInfo.m_lastModifyTime = CMemoryManager.ReadDateTime(data, ref offset); cCachedTextureInfo.m_isGif = (CMemoryManager.ReadByte(data, ref offset) > 0); if (!this.m_cachedTextureInfoMap.ContainsKey(cCachedTextureInfo.m_key)) { this.m_cachedTextureInfoMap.Add(cCachedTextureInfo.m_key, cCachedTextureInfo); this.m_cachedTextureInfos.Add(cCachedTextureInfo); } } this.m_cachedTextureInfos.Sort(); }
public Texture2D GetCachedTexture(string url, float validDays) { string md = CFileManager.GetMd5(url.ToLower()); CCachedTextureInfo cachedTextureInfo = this.m_cachedTextureInfoSet.GetCachedTextureInfo(md); if (cachedTextureInfo == null || (DateTime.get_Now() - cachedTextureInfo.m_lastModifyTime).get_TotalDays() >= (double)validDays) { return(null); } string text = CFileManager.CombinePath(CCachedTextureManager.s_cachedTextureDirectory, md + ".bytes"); if (!CFileManager.IsFileExist(text)) { return(null); } byte[] array = CFileManager.ReadFile(text); if (array == null || array.Length <= 0) { return(null); } Texture2D texture2D = null; if (cachedTextureInfo.m_isGif) { using (MemoryStream memoryStream = new MemoryStream(array)) { texture2D = GifHelper.GifToTexture(memoryStream, 0); } } else { texture2D = new Texture2D(cachedTextureInfo.m_width, cachedTextureInfo.m_height, TextureFormat.ARGB32, false); texture2D.LoadImage(array); } return(texture2D); }