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.Clear(); 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> public void 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; } m_FileDatas.Remove(name); BlockData blockData = m_BlockDatas[blockIndex]; int stringIndex = blockData.StringIndex; StringData stringData = m_StringDatas[stringIndex].Clear(); m_FreeStringDatas.Enqueue(new KeyValuePair <int, StringData>(stringIndex, stringData)); m_StringDatas.Remove(stringIndex); WriteStringData(stringIndex, stringData); blockData = blockData.Clear(); m_BlockDatas[blockIndex] = blockData; m_FreeBlockIndexes.Add(blockData.Length, blockIndex); WriteBlockData(blockIndex); m_Stream.Flush(); }