Beispiel #1
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);
    }