public FileEditor(ref BitMap bitMap, ref File file) { InitializeComponent(); bitmap = bitMap; textFile = file; showContent(); }
//清空文件块 public void setEmpty(ref BitMap bitmap) { for (int i = 0; i < fcb.blocklist.Count(); i += 1) { bitmap.setFree(bitmap.findFreeBlock()); //置该块为空闲 } fcb.blocklist.Clear(); //清空块链表 fcb.fileSize = 0; //文件大小置为0 }
//写文件 public void write(String data, ref BitMap bitmap) { setEmpty(ref bitmap); while (data.Count() > 512) { bitmap.blocks[bitmap.findFreeBlock()] = new Block(); bitmap.blocks[bitmap.findFreeBlock()].setData(data.Substring(0, 512)); //每次截取512个字符加入寻找到的块中 fcb.blocklist.Add(bitmap.blocks[bitmap.findFreeBlock()]); //将块加入块链表 bitmap.setOccupy(bitmap.findFreeBlock()); //置此块为占用状态 fcb.fileSize += 512; data = data.Remove(0, 512); } bitmap.blocks[bitmap.findFreeBlock()] = new Block(); bitmap.blocks[bitmap.findFreeBlock()].setData(data); fcb.blocklist.Add(bitmap.blocks[bitmap.findFreeBlock()]); //将块加入块链表 bitmap.setOccupy(bitmap.findFreeBlock()); fcb.fileSize += data.Length; fcb.updatedTime = DateTime.Now; }
//反序列化 private void BinaryDeserialize() { FileStream fileStream2, fileStream3; BinaryFormatter bf = new BinaryFormatter(); //fileStream1 = new FileStream(System.IO.Path.Combine(dir, "root_node.dat"), FileMode.Open, FileAccess.Read, FileShare.Read); //root_node = bf.Deserialize(fileStream1) as Node; //fileStream1.Close(); bool rootb = System.IO.File.Exists(System.IO.Path.Combine(dir, "root_catalog.dat")); if (System.IO.File.Exists(System.IO.Path.Combine(dir, "root_catalog.dat")) && System.IO.File.Exists(System.IO.Path.Combine(dir, "bitmap.dat"))) { fileStream2 = new FileStream(System.IO.Path.Combine(dir, "root_catalog.dat"), FileMode.Open, FileAccess.Read, FileShare.Read); root_catalog = bf.Deserialize(fileStream2) as Catalog; fileStream2.Close(); fileStream3 = new FileStream(System.IO.Path.Combine(dir, "bitmap.dat"), FileMode.Open, FileAccess.Read, FileShare.Read); bitmap = bf.Deserialize(fileStream3) as BitMap; fileStream3.Close(); } }