예제 #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);
        }
예제 #2
0
    public void LoadFromCache(string iconPath)
    {
        string cachePath = s_3dIconTextureCacher.GetCachedFilePath(GetCacheKey(iconPath, m_width, m_height), 100);

        if (!string.IsNullOrEmpty(cachePath))
        {
            //m_iconPath = iconPath;
            for (int i = 0; i < transform.childCount; i++)
            {
                transform.GetChild(i).gameObject.SetActive(false);
            }

            byte[] data = CFileManager.ReadFile(cachePath);
            if (data != null && data.Length > 0)
            {
                if (m_2dShotTextre == null)
                {
                    m_2dShotTextre = new Texture2D(m_width, m_height, TextureFormat.ARGB32, false);
                }
                // m_shotStep = enTakeShotStep.NotActived;
                m_2dShotTextre.LoadImage(data);
                m_2dShotTextre.Apply();
                Image shot2DImage = GetShot2DImage();
                shot2DImage.enabled = true;
                shot2DImage.gameObject.SetActive(true);

                shot2DImage.sprite = Sprite.Create(m_2dShotTextre, new Rect(0, 0, m_width, m_height), new Vector2(0.5f, 0.5f));
                return;
            }
        }
    }
예제 #3
0
    public static byte[] ReadFile(string path)
    {
        FileStream stream = null;

        if (CFileManager.IsFileExist(path))
        {
            try
            {
                stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
                int    length = (int)stream.Length;
                byte[] array  = new byte[length];
                stream.Read(array, 0, length);
                stream.Close();
                stream.Dispose();
                return(array);
            }
            catch (Exception)
            {
                if (stream != null)
                {
                    stream.Close();
                    stream.Dispose();
                }
            }
        }
        return(null);
    }
예제 #4
0
    public static bool WriteFile(string path, byte[] bytes)
    {
        FileStream stream = null;

        try
        {
            if (!CFileManager.IsFileExist(path))
            {
                stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
            }
            else
            {
                stream = new FileStream(path, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);
            }
            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();
            stream.Close();
            stream.Dispose();
            return(true);
        }
        catch (Exception)
        {
            if (stream != null)
            {
                stream.Close();
                stream.Dispose();
            }
            return(false);
        }
    }
예제 #5
0
 public void LoadFromAssetBundle(CResourcePackerInfo resourcePackerInfo)
 {
     if (this.m_isAbandon)
     {
         this.m_state = enResourceState.Unload;
     }
     else
     {
         string name   = this.m_name;
         string rename = resourcePackerInfo.GetRename(this.m_fullPathInResourcesWithoutExtension);
         if (!string.IsNullOrEmpty(rename))
         {
             name = CFileManager.GetFullName(rename);
         }
         if (this.m_contentType == null)
         {
             this.m_content = resourcePackerInfo.m_assetBundle.Load(name);
         }
         else
         {
             this.m_content = resourcePackerInfo.m_assetBundle.Load(name, this.m_contentType);
         }
         this.m_state = enResourceState.Loaded;
         if ((this.m_content != null) && (this.m_content.GetType() == typeof(TextAsset)))
         {
             CBinaryObject obj2 = ScriptableObject.CreateInstance <CBinaryObject>();
             obj2.m_data    = (this.m_content as TextAsset).bytes;
             this.m_content = obj2;
         }
     }
 }
예제 #6
0
    public static string GetSoundBankPathInResources(string bankName)
    {
        string str = string.Empty;

        str = "Sound/Android/";
        return(CFileManager.CombinePath(str, bankName));
    }
예제 #7
0
    protected void Init(string fileName)
    {
        CFileManager file = CFileManager.GetInstance;
        Stream       ms   = file.LoadFile(fileName);

        if (ms == null)
        {
            return;
        }
        StreamReader sr = new StreamReader(ms);

        while (!sr.EndOfStream)
        {
            sr.ReadLine();
            m_LineMaxNum++;
        }
        ms.Seek(0, SeekOrigin.Begin);
        m_Line = new string[m_LineMaxNum];
        for (int i = 0; i < m_LineMaxNum; i++)
        {
            m_Line[i] = sr.ReadLine();
        }

        m_CurrentLine = m_Line[m_LineIndex++].Split(m_DivValue, System.StringSplitOptions.None);
        m_ValueMaxNum = (uint)m_CurrentLine.GetLength(0);
    }
예제 #8
0
    public void PrepareGameObject(string prefabFullPath, enResourceType resourceType, int amount)
    {
        string key = CFileManager.EraseExtension(prefabFullPath).ToLower();
        Queue <CPooledGameObjectScript> queue = null;

        if (!this.m_pooledGameObjectMap.TryGetValue(key, out queue))
        {
            queue = new Queue <CPooledGameObjectScript>();
            this.m_pooledGameObjectMap.Add(key, queue);
        }
        if (queue.Count < amount)
        {
            amount -= queue.Count;
            for (int i = 0; i < amount; i++)
            {
                CPooledGameObjectScript item = this.CreateGameObject(prefabFullPath, Vector3.zero, Quaternion.identity, false, resourceType, key);
                DebugHelper.Assert(item != null);
                if (item != null)
                {
                    queue.Enqueue(item);
                    item.gameObject.transform.SetParent(this.m_poolRoot.transform, true);
                    item.gameObject.SetActive(false);
                }
            }
        }
    }
예제 #9
0
        private void WriteInvitedFriendDicToBinFile()
        {
            string     cachePath  = CFileManager.GetCachePath("invited_friend_02_" + Singleton <CRoleInfoManager> .GetInstance().GetMasterRoleInfo().playerUllUID);
            FileStream fileStream = null;

            try
            {
                if (!CFileManager.IsFileExist(cachePath))
                {
                    fileStream = new FileStream(cachePath, 2, 2, 3);
                }
                else
                {
                    fileStream = new FileStream(cachePath, 5, 2, 3);
                }
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(fileStream, this.m_InvitedFriendDic);
                fileStream.Flush();
                fileStream.Close();
                fileStream.Dispose();
            }
            catch (Exception var_3_74)
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                    fileStream.Dispose();
                }
            }
        }
예제 #10
0
        private void ReadInvitedFriendDicFromBinFile()
        {
            string     cachePath  = CFileManager.GetCachePath("invited_friend_02_" + Singleton <CRoleInfoManager> .GetInstance().GetMasterRoleInfo().playerUllUID);
            FileStream fileStream = null;

            if (!CFileManager.IsFileExist(cachePath))
            {
                return;
            }
            try
            {
                fileStream = new FileStream(cachePath, 3, 1, 0);
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                this.m_InvitedFriendDic = (Dictionary <ulong, stInvitedFriend>)binaryFormatter.Deserialize(fileStream);
                fileStream.Close();
                fileStream.Dispose();
            }
            catch (Exception var_3_65)
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                    fileStream.Dispose();
                }
            }
        }
예제 #11
0
        private void WriteInvitedFriendDicToBinFile()
        {
            string     cachePath           = CFileManager.GetCachePath("invited_friend_02_" + Singleton <CRoleInfoManager> .GetInstance().GetMasterRoleInfo().playerUllUID);
            FileStream serializationStream = null;

            try
            {
                if (!CFileManager.IsFileExist(cachePath))
                {
                    serializationStream = new FileStream(cachePath, FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                }
                else
                {
                    serializationStream = new FileStream(cachePath, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);
                }
                new BinaryFormatter().Serialize(serializationStream, this.m_InvitedFriendDic);
                serializationStream.Flush();
                serializationStream.Close();
                serializationStream.Dispose();
            }
            catch (Exception)
            {
                if (serializationStream != null)
                {
                    serializationStream.Close();
                    serializationStream.Dispose();
                }
            }
        }
    public static bool DeleteFile(string filePath)
    {
        if (!CFileManager.IsFileExist(filePath))
        {
            return(true);
        }
        int  num = 0;
        bool result;

        while (true)
        {
            try
            {
                File.Delete(filePath);
                result = true;
                break;
            }
            catch (Exception ex)
            {
                num++;
                if (num >= 3)
                {
                    Debug.Log("Delete File " + filePath + " Error! Exception = " + ex.ToString());
                    CFileManager.s_delegateOnOperateFileFail(filePath, enFileOperation.DeleteFile, ex);
                    result = false;
                    break;
                }
            }
        }
        return(result);
    }
    public void PrepareGameObject(string prefabFullPath, enResourceType resourceType, int amount, bool assertNull = true)
    {
        string text = CFileManager.EraseExtension(prefabFullPath);
        Queue <CPooledGameObjectScript> queue = null;

        if (!this.m_pooledGameObjectMap.TryGetValue(text.JavaHashCodeIgnoreCase(), out queue))
        {
            queue = new Queue <CPooledGameObjectScript>();
            this.m_pooledGameObjectMap.Add(text.JavaHashCodeIgnoreCase(), queue);
        }
        if (queue.get_Count() >= amount)
        {
            return;
        }
        amount -= queue.get_Count();
        for (int i = 0; i < amount; i++)
        {
            CPooledGameObjectScript cPooledGameObjectScript = this.CreateGameObject(prefabFullPath, Vector3.zero, Quaternion.identity, false, resourceType, text);
            if (assertNull)
            {
                DebugHelper.Assert(cPooledGameObjectScript != null, "Failed Create Game object from \"{0}\"", new object[]
                {
                    prefabFullPath
                });
            }
            if (cPooledGameObjectScript != null)
            {
                queue.Enqueue(cPooledGameObjectScript);
                cPooledGameObjectScript.gameObject.transform.SetParent(this.m_poolRoot.transform, true);
                cPooledGameObjectScript.OnPrepare();
            }
        }
    }
예제 #14
0
    public CResource GetResource(string fullPathInResources, System.Type resourceContentType, enResourceType resourceType, bool needCached = false, bool unloadBelongedAssetBundleAfterLoaded = false)
    {
        if (string.IsNullOrEmpty(fullPathInResources))
        {
            return(new CResource(string.Empty, string.Empty, null, resourceType, unloadBelongedAssetBundleAfterLoaded));
        }
        string    key      = CFileManager.EraseExtension(fullPathInResources).ToLower();
        CResource resource = null;

        if (this.m_cachedResourceMap.TryGetValue(key, out resource))
        {
            if (resource.m_resourceType != resourceType)
            {
                resource.m_resourceType = resourceType;
            }
            return(resource);
        }
        resource = new CResource(key, fullPathInResources, resourceContentType, resourceType, unloadBelongedAssetBundleAfterLoaded);
        this.LoadResource(resource);
        if (needCached)
        {
            this.m_cachedResourceMap.Add(key, resource);
        }
        return(resource);
    }
예제 #15
0
파일: Utility.cs 프로젝트: PenpenLi/Hifior
    public static byte[] ReadFile(string path)
    {
        FileStream fileStream = null;

        if (!CFileManager.IsFileExist(path))
        {
            return(null);
        }
        try
        {
            fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
            int    num   = (int)fileStream.Length;
            byte[] array = new byte[num];
            fileStream.Read(array, 0, num);
            fileStream.Close();
            fileStream.Dispose();
            return(array);
        }
        catch (Exception)
        {
            if (fileStream != null)
            {
                fileStream.Close();
                fileStream.Dispose();
            }
        }
        return(null);
    }
예제 #16
0
    public bool CheckCachedResource(string fullPathInResources)
    {
        string    key      = CFileManager.EraseExtension(fullPathInResources).ToLower();
        CResource resource = null;

        return(this.m_cachedResourceMap.TryGetValue(key, out resource));
    }
예제 #17
0
 public void LoadAssetBundle(CResourcePackerInfo resourcePackerInfo)
 {
     if (((resourcePackerInfo != null) && resourcePackerInfo.m_isAssetBundle) && !resourcePackerInfo.IsAssetBundleLoaded())
     {
         resourcePackerInfo.LoadAssetBundle(CFileManager.GetIFSExtractPath());
     }
 }
    public static int GetFileLength(string filePath)
    {
        if (!CFileManager.IsFileExist(filePath))
        {
            return(0);
        }
        int num = 0;
        int result;

        while (true)
        {
            try
            {
                FileInfo fileInfo = new FileInfo(filePath);
                result = (int)fileInfo.get_Length();
                break;
            }
            catch (Exception ex)
            {
                num++;
                if (num >= 3)
                {
                    Debug.Log("Get FileLength of " + filePath + " Error! Exception = " + ex.ToString());
                    result = 0;
                    break;
                }
            }
        }
        return(result);
    }
예제 #19
0
    //--------------------------------------------------
    /// 构造函数
    //--------------------------------------------------
    public CHttpFileCacher(int max, string folderName, string fileExtension)
    {
        m_maxCnt        = max;
        m_dir           = GetCacheDirectory(folderName.ToLower());
        m_metaFilePath  = CFileManager.CombinePath(m_dir, folderName.ToLower() + ".bytes");
        m_fileExtension = fileExtension;

        m_cachedFileInfoSet = new CCachedFileInfoSet();

        MakeDirReady();

        if (CFileManager.IsFileExist(m_metaFilePath))
        {
            byte[] buffer = CFileManager.LockFileBuffer();

            try
            {
                uint fileLength = CFileManager.ReadFile(m_metaFilePath, buffer, (uint)buffer.Length);
                int  offset     = 0;

                int ret = m_cachedFileInfoSet.Read(buffer, offset, fileLength);

                if (ret < 0)    //读取出错时,删除所有文件
                {
                    Debug.LogError("读取出错,删除所有文件");
                    CFileManager.ClearDirectory(m_dir);
                }
            }
            finally
            {
                CFileManager.UnLockFileBuffer();
            }
        }
    }
    public static bool DeleteDirectory(string directory)
    {
        if (!CFileManager.IsDirectoryExist(directory))
        {
            return(true);
        }
        int  num = 0;
        bool result;

        while (true)
        {
            try
            {
                Directory.Delete(directory, true);
                result = true;
                break;
            }
            catch (Exception ex)
            {
                num++;
                if (num >= 3)
                {
                    Debug.Log("Delete Directory " + directory + " Error! Exception = " + ex.ToString());
                    CFileManager.s_delegateOnOperateFileFail(directory, enFileOperation.DeleteDirectory, ex);
                    result = false;
                    break;
                }
            }
        }
        return(result);
    }
예제 #21
0
        private void ReadInvitedFriendDicFromBinFile()
        {
            string     cachePath           = CFileManager.GetCachePath("invited_friend_02_" + Singleton <CRoleInfoManager> .GetInstance().GetMasterRoleInfo().playerUllUID);
            FileStream serializationStream = null;

            if (CFileManager.IsFileExist(cachePath))
            {
                try
                {
                    serializationStream = new FileStream(cachePath, FileMode.Open, FileAccess.Read, FileShare.None);
                    BinaryFormatter formatter = new BinaryFormatter();
                    this.m_InvitedFriendDic = (Dictionary <ulong, stInvitedFriend>)formatter.Deserialize(serializationStream);
                    serializationStream.Close();
                    serializationStream.Dispose();
                }
                catch (Exception)
                {
                    if (serializationStream != null)
                    {
                        serializationStream.Close();
                        serializationStream.Dispose();
                    }
                }
            }
        }
    public static bool WriteFile(string filePath, byte[] data, int offset, int length)
    {
        FileStream fileStream = null;
        int        num        = 0;
        bool       result;

        while (true)
        {
            try
            {
                fileStream = new FileStream(filePath, 4, 2, 3);
                fileStream.Write(data, offset, length);
                fileStream.Close();
                result = true;
                break;
            }
            catch (Exception ex)
            {
                if (fileStream != null)
                {
                    fileStream.Close();
                }
                num++;
                if (num >= 3)
                {
                    Debug.Log("Write File " + filePath + " Error! Exception = " + ex.ToString());
                    CFileManager.DeleteFile(filePath);
                    CFileManager.s_delegateOnOperateFileFail(filePath, enFileOperation.WriteFile, ex);
                    result = false;
                    break;
                }
            }
        }
        return(result);
    }
    public static bool WriteFile(string filePath, byte[] data)
    {
        int  num = 0;
        bool result;

        while (true)
        {
            try
            {
                File.WriteAllBytes(filePath, data);
                result = true;
                break;
            }
            catch (Exception ex)
            {
                num++;
                if (num >= 3)
                {
                    Debug.Log("Write File " + filePath + " Error! Exception = " + ex.ToString());
                    CFileManager.DeleteFile(filePath);
                    CFileManager.s_delegateOnOperateFileFail(filePath, enFileOperation.WriteFile, ex);
                    result = false;
                    break;
                }
            }
        }
        return(result);
    }
예제 #24
0
 public void Load()
 {
     if (this.m_isAbandon)
     {
         this.m_state = enResourceState.Unload;
     }
     else
     {
         if (this.m_contentType == null)
         {
             this.m_content = Resources.Load(CFileManager.EraseExtension(this.m_fullPathInResources));
         }
         else
         {
             this.m_content = Resources.Load(CFileManager.EraseExtension(this.m_fullPathInResources), this.m_contentType);
         }
         this.m_state = enResourceState.Loaded;
         if ((this.m_content != null) && (this.m_content.GetType() == typeof(TextAsset)))
         {
             CBinaryObject obj2 = ScriptableObject.CreateInstance <CBinaryObject>();
             obj2.m_data    = (this.m_content as TextAsset).bytes;
             this.m_content = obj2;
         }
     }
 }
예제 #25
0
    //--------------------------------------------------------------
    /// 加密文件
    /// @srcFileFullPath
    /// @dstFileFullPath
    /// @encryption
    /// @buffer
    /// @bufferLength
    //--------------------------------------------------------------
    public static void EncryptFile(string srcFileFullPath, string dstFileFullPath, string publicKey, string privateKey, byte[] buffer, uint bufferLength)
    {
        if (string.IsNullOrEmpty(publicKey) || string.IsNullOrEmpty(privateKey))
        {
            CopyFile(srcFileFullPath, dstFileFullPath);
            return;
        }

        uint dataLength = ReadFile(srcFileFullPath, buffer, bufferLength);

        int publicKeyOffset  = ((int)dataLength & 0xFF);
        int privateKeyOffset = (((int)dataLength >> 1) & 0xFF);

        byte[] publicKeyData   = System.Text.Encoding.UTF8.GetBytes(publicKey);
        int    publicKeyLength = publicKeyData.Length;

        byte[] privateKeyData   = System.Text.Encoding.UTF8.GetBytes(privateKey);
        int    privateKeyLength = privateKeyData.Length;

        for (int i = 0; i < dataLength; i++)
        {
            buffer[i] ^= publicKeyData[(i + publicKeyOffset) % publicKeyLength];
            buffer[i] ^= privateKeyData[(i + privateKeyOffset) % privateKeyLength];
        }

        CFileManager.WriteFile(dstFileFullPath, buffer, 0, (int)dataLength);
    }
예제 #26
0
 public CResourcePackerInfo GetResourceBelongedPackerInfo(string fullPathInResources)
 {
     if (!string.IsNullOrEmpty(fullPathInResources) && (this.m_resourcePackerInfoSet != null))
     {
         return(this.m_resourcePackerInfoSet.GetResourceBelongedPackerInfo(CFileManager.EraseExtension(fullPathInResources).ToLower()));
     }
     return(null);
 }
 public static string GetIFSExtractPath()
 {
     if (CFileManager.s_ifsExtractPath == null)
     {
         CFileManager.s_ifsExtractPath = CFileManager.CombinePath(CFileManager.GetCachePath(), CFileManager.s_ifsExtractFolder);
     }
     return(CFileManager.s_ifsExtractPath);
 }
예제 #28
0
    //--------------------------------------------------
    /// 文件是否存在于StreamingAssets目录下
    /// @fileName
    //--------------------------------------------------
    public static bool IsFileExistInStreamingAssets(string fileName)
    {
#if UNITY_ANDROID && !UNITY_EDITOR
        return(AndroidJavaUtility.Android_IsFileExistInStreamingAssets(fileName));
#else
        return(IsFileExist(CFileManager.CombinePath(Application.streamingAssetsPath, fileName)));
#endif
    }
 public static string GetFileMd5(string filePath)
 {
     if (!CFileManager.IsFileExist(filePath))
     {
         return(string.Empty);
     }
     return(BitConverter.ToString(CFileManager.s_md5Provider.ComputeHash(CFileManager.ReadFile(filePath))).Replace("-", string.Empty));
 }
예제 #30
0
 public void AddRefPrefab(string prefabName, bool isParticle)
 {
     prefabName = CFileManager.EraseExtension(prefabName);
     if (!this.prefabDict.ContainsKey(prefabName))
     {
         this.prefabDict.Add(prefabName, isParticle);
     }
 }