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 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; } } }
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); }
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); } }
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; } } }
public static string GetSoundBankPathInResources(string bankName) { string str = string.Empty; str = "Sound/Android/"; return(CFileManager.CombinePath(str, bankName)); }
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); }
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); } } } }
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(); } } }
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(); } } }
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(); } } }
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); }
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); }
public bool CheckCachedResource(string fullPathInResources) { string key = CFileManager.EraseExtension(fullPathInResources).ToLower(); CResource resource = null; return(this.m_cachedResourceMap.TryGetValue(key, out resource)); }
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); }
//-------------------------------------------------- /// 构造函数 //-------------------------------------------------- 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); }
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); }
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; } } }
//-------------------------------------------------------------- /// 加密文件 /// @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); }
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); }
//-------------------------------------------------- /// 文件是否存在于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)); }
public void AddRefPrefab(string prefabName, bool isParticle) { prefabName = CFileManager.EraseExtension(prefabName); if (!this.prefabDict.ContainsKey(prefabName)) { this.prefabDict.Add(prefabName, isParticle); } }