Beispiel #1
0
        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);
        }
Beispiel #2
0
    public void SetFileLastModifyTime(string url, ref DateTime dt)
    {
        string          key           = CFileManager.GetMd5(url.ToLower());
        CCachedFileInfo cacheFileInfo = m_cachedFileInfoSet.GetFileInfo(key);

        if (cacheFileInfo != null)
        {
            cacheFileInfo.m_lastModifyTime = dt;
        }
    }
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
    public DateTime GetFileLastModifyTime(string url)
    {
        string          key           = CFileManager.GetMd5(url.ToLower());
        CCachedFileInfo cacheFileInfo = m_cachedFileInfoSet.GetFileInfo(key);

        if (cacheFileInfo != null)
        {
            return(cacheFileInfo.m_lastModifyTime);
        }
        else
        {
            return(DateTime.MinValue);
        }
    }
Beispiel #6
0
    //--------------------------------------------------
    /// 获取缓存的资源文件路径
    /// @url        : 地址
    /// @validDays  : 有效天数
    //--------------------------------------------------
    public string GetCachedFilePath(string url, float validDays)
    {
        string key = CFileManager.GetMd5(url.ToLower());

        CCachedFileInfo cachedFileInfo = m_cachedFileInfoSet.GetFileInfo(key);

        //不存在
        if (cachedFileInfo == null)
        {
            return(string.Empty);
        }

        //检查是否过期
        if ((DateTime.Now - cachedFileInfo.m_lastModifyTime).TotalDays >= validDays)
        {
            RemoveFile(key);
            return(string.Empty);
        }

        string cachedFileFullPath = CFileManager.CombinePath(m_dir, key + m_fileExtension);

        //检查文件是否存在
        if (CFileManager.IsFileExist(cachedFileFullPath))
        {
            //通过校验文件长度,来判断是否被串改
            if (cachedFileInfo.m_fileLength == (int)CFileManager.GetFileLength(cachedFileFullPath))
            {
                return(cachedFileFullPath);
            }
            else
            {
                RemoveFile(key);
            }
        }

        return(string.Empty);
    }
Beispiel #7
0
        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);
        }
Beispiel #8
0
    //--------------------------------------------------
    /// 添加缓存文件
    /// @url
    /// @cacheType
    /// @width
    /// @height
    /// @isGif
    /// @data
    //--------------------------------------------------
    public void AddFile(string url, byte[] data, int tagInt1 = 0, int tagInt2 = 0, bool tagBool = false)
    {
        string key = CFileManager.GetMd5(url.ToLower());
        List <CCachedFileInfo> cachedFileInfoList = m_cachedFileInfoSet.m_cachedFileInfos;

        if (cachedFileInfoList == null)
        {
            return;
        }

        if (m_cachedFileInfoSet.m_cachedFileInfoMap.ContainsKey(key))
        {
            CCachedFileInfo cachedFileInfo = null;
            m_cachedFileInfoSet.m_cachedFileInfoMap.TryGetValue(key, out cachedFileInfo);

            Debug.Assert(cachedFileInfoList != null && cachedFileInfoList.Contains(cachedFileInfo), "zen me ke neng?");

            //修改信息
            cachedFileInfo.m_fileLength     = data.Length;
            cachedFileInfo.m_lastModifyTime = DateTime.Now;
            cachedFileInfo.m_tagInt1        = tagInt1;
            cachedFileInfo.m_tagInt2        = tagInt2;
            cachedFileInfo.m_tagBool        = tagBool;
        }
        else
        {
            //如果数量达到上限,移除排在最前面的文件
            if (cachedFileInfoList.Count >= m_maxCnt)
            {
                string removeKey = m_cachedFileInfoSet.RemoveEarliestFileInfo();

                //删除缓存文件
                if (!string.IsNullOrEmpty(removeKey))
                {
                    string removeCachedFileFullPath = CFileManager.CombinePath(m_dir, removeKey + m_fileExtension);
                    if (CFileManager.IsFileExist(removeCachedFileFullPath))
                    {
                        CFileManager.DeleteFile(removeCachedFileFullPath);
                    }
                }
            }

            CCachedFileInfo cachedFileInfo = new CCachedFileInfo();
            cachedFileInfo.m_key            = key;
            cachedFileInfo.m_fileLength     = data.Length;
            cachedFileInfo.m_lastModifyTime = DateTime.Now;
            cachedFileInfo.m_tagInt1        = tagInt1;
            cachedFileInfo.m_tagInt2        = tagInt2;
            cachedFileInfo.m_tagBool        = tagBool;

            m_cachedFileInfoSet.AddFileInfo(key, cachedFileInfo);
        }

        //排序
        m_cachedFileInfoSet.m_cachedFileInfos.Sort();

        //写入信息文件
        byte[] buffer = CFileManager.LockFileBuffer();
        try
        {
            MakeDirReady();
            int offset = 0;
            m_cachedFileInfoSet.Write(buffer, ref offset);

            if (CFileManager.IsFileExist(m_metaFilePath))
            {
                CFileManager.DeleteFile(m_metaFilePath);
            }

            CFileManager.WriteFile(m_metaFilePath, buffer, 0, offset);
        }
        finally
        {
            CFileManager.UnLockFileBuffer();
        }

        //写入数据文件
        string cachedFileFullPath = CFileManager.CombinePath(m_dir, key + m_fileExtension);

        if (CFileManager.IsFileExist(cachedFileFullPath))
        {
            CFileManager.DeleteFile(cachedFileFullPath);
        }

        CFileManager.WriteFile(cachedFileFullPath, data);
    }
Beispiel #9
0
    public CCachedFileInfo GetCacheFileInfo(string url)
    {
        string key = CFileManager.GetMd5(url.ToLower());

        return(m_cachedFileInfoSet.GetFileInfo(key));
    }