private void ProcessWriteFile(string name, bool hasFile, int oldBlockIndex, int blockIndex, int length) { BlockData blockData = m_BlockDatas[blockIndex]; if (hasFile) { BlockData oldBlockData = m_BlockDatas[oldBlockIndex]; blockData = new BlockData(oldBlockData.StringIndex, blockData.ClusterIndex, length); m_BlockDatas[blockIndex] = blockData; WriteBlockData(blockIndex); oldBlockData = oldBlockData.Free(); m_BlockDatas[oldBlockIndex] = oldBlockData; m_FreeBlockIndexes.Add(oldBlockData.Length, oldBlockIndex); WriteBlockData(oldBlockIndex); } else { int stringIndex = AllocString(name); blockData = new BlockData(stringIndex, blockData.ClusterIndex, length); m_BlockDatas[blockIndex] = blockData; WriteBlockData(blockIndex); } if (hasFile) { m_FileDatas[name] = blockIndex; } else { m_FileDatas.Add(name, blockIndex); } }
/// <summary> /// 删除指定文件。 /// </summary> /// <param name="name">要删除的文件名称。</param> /// <returns>是否删除指定文件成功。</returns> public bool DeleteFile(string name) { if (m_Access != FileSystemAccess.Write && m_Access != FileSystemAccess.ReadWrite) { throw new GameFrameworkException("File system is not writable."); } if (string.IsNullOrEmpty(name)) { throw new GameFrameworkException("Name is invalid."); } int blockIndex = 0; if (!m_FileDatas.TryGetValue(name, out blockIndex)) { return(false); } m_FileDatas.Remove(name); BlockData blockData = m_BlockDatas[blockIndex]; int stringIndex = blockData.StringIndex; StringData stringData = m_StringDatas[stringIndex].Clear(); m_FreeStringIndexes.Enqueue(stringIndex); m_FreeStringDatas.Enqueue(stringData); m_StringDatas.Remove(stringIndex); WriteStringData(stringIndex, stringData); blockData = blockData.Free(); m_BlockDatas[blockIndex] = blockData; if (!TryCombineFreeBlocks(blockIndex)) { m_FreeBlockIndexes.Add(blockData.Length, blockIndex); WriteBlockData(blockIndex); } m_Stream.Flush(); return(true); }