public int getPre(FCB item) //返回pre的编号(用于txt文件读写) { int pre; if (item.pre != null) { pre = item.pre.filePointer; } else { return(-1); } return(pre); }
public int getNext(FCB item) //返回next的编号(用于txt文件读写) { int next; if (item.next != null) { next = item.next.filePointer; } else { return(-1); } return(next); }
//用PCB创建文件 public File(FCB item, string fatherPath = "") { name = item.fileName; size = "0"; type = item.fileType.ToString(); path = fatherPath + '\\' + name; Fatherpath = fatherPath; filePointer = item.filePointer; indexPointer = new IndexTable(); createTime = DateTime.Now; item.size = size; item.path = path; item.createTime = createTime; }
public void deserialize() { FileStream fileStream1, fileStream2, fileStream3; BinaryFormatter b = new BinaryFormatter(); fileStream1 = new FileStream(System.IO.Path.Combine(dir, "catalogTree.dat"), FileMode.Open, FileAccess.Read, FileShare.Read); root_fcb = b.Deserialize(fileStream1) as FCB; fileStream1.Close(); fileStream2 = new FileStream(System.IO.Path.Combine(dir, "catalogTable.dat"), FileMode.Open, FileAccess.Read, FileShare.Read); catalog = b.Deserialize(fileStream2) as Catalog; fileStream2.Close(); fileStream3 = new FileStream(System.IO.Path.Combine(dir, "bitMap.dat"), FileMode.Open, FileAccess.Read, FileShare.Read); bitMap = b.Deserialize(fileStream3) as BitMap; fileStream3.Close(); }
private void 返回ToolStripMenuItem1_Click(object sender, EventArgs e) { if (current_catalog == root_fcb) { return; } current_catalog = current_catalog.father; if (current_catalog == root_fcb) { textBox1.Text = "root\\"; } else { textBox1.Text = catalog.getFile(current_catalog).path; } UpdateListView(current_catalog); }
private void nodeDFS(TreeNode node, FCB dir)//维护目录 { if (dir.son != null) { FCB son = dir.son; do { if (son.fileType == FCB.FileType.folder) { TreeNode new_node = new TreeNode(son.fileName); nodeDFS(new_node, son); node.Nodes.Add(new_node); } son = son.next; } while(son != null); } }
public void addSonItem(FCB newItem) { if (this.son == null) { this.son = newItem; newItem.father = this; } else { FCB temp = this.son; while (temp.next != null) { temp = temp.next; } temp.next = newItem; newItem.pre = temp; } }
private void button1_Click(object sender, EventArgs e) { //当前在根目录下 if (current_catalog_fcb == root_fcb) { return; } current_catalog_fcb = current_catalog_fcb.father; if (current_catalog_fcb == root_fcb) { textBox1.Text = "root\\"; } else { textBox1.Text = catalog.getFile(current_catalog_fcb).path; } UpdateListView(); }
private void 打开ToolStripMenuItem1_Click(object sender, EventArgs e) { ListViewItem current_item = new ListViewItem(); if (listView1.SelectedItems.Count != 0) { current_item = listView1.SelectedItems[0]; } else { MessageBox.Show("Please select a item"); return; } File current_file = catalog.getFile(getPointer(current_item)); FCB current_fcb = catalog.getFCB(current_file); openClick(current_fcb, current_file); }
private void listView_DoubleClick(object sender, EventArgs e) { ListViewItem current_item = new ListViewItem(); if (listView1.SelectedItems.Count != 0) { current_item = listView1.SelectedItems[0]; } else { MessageBox.Show("Please select a item"); return; } File current_file = directory.getFile(getPointer(current_item)); FCB current_fcb = directory.getFCB(current_file); openClick(current_fcb, current_file); }
private void 文件夹ToolStripMenuItem_Click(object sender, EventArgs e) { string file_name = nameCheck("New folder"); string fatherPath; //Add new FCB FCB new_fcb = new FCB(file_name, FCB.FileType.folder); current_directory.addSonItem(new_fcb); //Add new File //Build new file path File father = directory.getFile(current_directory); fatherPath = (father == null) ? "root" : father.path; File new_file = new File(new_fcb, fatherPath); directory.map(new_fcb, new_file); UpdateView(); }
private void 文件ToolStripMenuItem2_Click(object sender, EventArgs e) { string file_name = nameCheck("New text", ".txt"); string fatherPath; //Add new FCB FCB new_fcb = new FCB(file_name, FCB.FileType.txt); current_catalog.addSonItem(new_fcb); //Add new File //Build new file path File father = catalog.getFile(current_catalog); fatherPath = (father == null) ? "root" : father.path; File new_file = new File(new_fcb, fatherPath); catalog.map(new_fcb, new_file); UpdateListView(current_catalog); }
private void openClick(FCB fcb, File file) { switch (fcb.fileType) { case FCB.FileType.folder: current_catalog = fcb; folderStack.Push(fcb); textBox1.Text = catalog.getFile(current_catalog).path; UpdateListView(fcb); break; case FCB.FileType.txt: FileEditor fileEditor = new FileEditor(file); fileEditor.Show(); fileEditor.CallBack = UpdateView; break; default: break; } }
//增加子类 public void addSonItem(FCB newItem) { //如果没有儿子,则直接添加 if (this.son == null) { this.son = newItem; newItem.father = this; } else { //如果有儿子,添加到最后一个儿子的兄弟后面 FCB temp = this.son; while (temp.next != null) { temp = temp.next; } temp.next = newItem; newItem.pre = temp; newItem.father = this; } }
private void 文件ToolStripMenuItem2_Click(object sender, EventArgs e) { string file_name = nameCheck("New text", ".txt"); string fatherPath; //新建FCB FCB new_fcb = new FCB(file_name, FCB.FileType.txt); current_directory.addSonItem(new_fcb); //建立文件路径 File father = directory.getFile(current_directory); fatherPath = (father == null) ? "root" : father.path; //新建文件 File new_file = new File(new_fcb, fatherPath); directory.map(new_fcb, new_file); UpdateListView(current_directory); }
private void openClick(FCB fcb, File file) { switch (fcb.fileType) { case FCB.FileType.folder: //双击文件夹进入当前文件夹 current_directory = fcb; folderStack.Push(fcb); textBox1.Text = directory.getFile(current_directory).path; UpdateListView(fcb); break; case FCB.FileType.txt: //双击文件弹出FileEditor FileEditor fileEditor = new FileEditor(file); fileEditor.Show(); fileEditor.CallBack = UpdateView; break; default: break; } }
private void 重命名ToolStripMenuItem1_Click(object sender, EventArgs e) { ListViewItem current_item = new ListViewItem(); if (listView1.SelectedItems.Count != 0) { current_item = listView1.SelectedItems[0]; } else { MessageBox.Show("Please select a item"); return; } File current_file = directory.getFile(getPointer(current_item)); FCB current_fcb = directory.getFCB(current_file); InputBox inputBox = new InputBox(current_file, current_fcb); inputBox.Show(); inputBox.CallBack = UpdateView; }
private void 返回ToolStripMenuItem1_Click(object sender, EventArgs e) { if (current_directory == root_fcb) { MessageBox.Show("⚠ Attention:Already at root!"); return; } while (current_directory.father == null) { current_directory = current_directory.pre; } current_directory = current_directory.father; if (current_directory == root_fcb) { textBox1.Text = "root\\"; } else { textBox1.Text = directory.getFile(current_directory).path; } UpdateListView(current_directory); }
//与菜单栏的打开链接 private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { ListViewItem selected_item = new ListViewItem(); //如果选中文件个数不只一个,则选中的文件为第一个,否则提示用户选中一个文件 if (listView1.SelectedItems.Count != 0) { selected_item = listView1.SelectedItems[0]; } else { MessageBox.Show("请选择一个文件"); return; } //通过内存指针找到该文件 File selected_file = catalog.getFile(getPointer(selected_item)); //获得该文件的PCB FCB selected_fcb = catalog.getFCB(selected_file); open(selected_fcb, selected_file); }
private string nameCheck(string s, string ext = "") { FCB current_dir = current_directory.son; int counter = 0; while (current_dir != null) { string[] sArray = current_dir.fileName.Split('('); if (sArray[0] != current_dir.fileName && sArray[0] == s) { counter++; } else if (current_dir.fileName == s + ext) { counter++; } current_dir = current_dir.next; } if (counter > 0) { s += "(" + counter.ToString() + ")"; } return(s + ext); }
public RenameForm(File file, FCB fcb) { InitializeComponent(); renaming_file = file; renaming_fcb = fcb; }
//完成FCB和File的映射 public void map(FCB item, File file) { file_table[item.filePointer] = file; fcb_table[item.filePointer] = item; }
//将txt里的数据加载回文件系统 void readStore() { if (System.IO.File.Exists("txtRecord\\Block.txt") && System.IO.File.Exists("txtRecord\\BitMap.txt") && System.IO.File.Exists("txtRecord\\File.txt") && System.IO.File.Exists("txtRecord\\FCB.txt")) { FileStream BlockStore = new FileStream("txtRecord\\Block.txt", FileMode.Open); //读取Block数据 StreamReader br = new StreamReader(BlockStore, Encoding.Default); //for (int i = 100; i < BitMap.Capcity; i++) for (int i = 0; i < My_BitMap.Capcity; i++) { string readContent = br.ReadLine(); if (readContent == null || Convert.ToString(readContent) == "N") { //这个block没有内容 } else { My_BitMap.blocks[i] = new Block(); My_BitMap.blocks[i].info = readContent; } } br.Close(); BlockStore.Close(); FileStream BitMapStore = new FileStream("txtRecord\\BitMap.txt", FileMode.Open); //读取BitMap数据 StreamReader mr = new StreamReader(BitMapStore); for (int i = 0; i < My_BitMap.Capcity; i++) { My_BitMap.my_inside_bitMap[i] = Convert.ToBoolean(mr.ReadLine()); } mr.Close(); BitMapStore.Close(); FileStream fcbStorage = new FileStream("txtRecord\\FCB.txt", FileMode.Open); //读取FCB数据 StreamReader fcbr = new StreamReader(fcbStorage); string content = fcbr.ReadLine(); Console.WriteLine("读取FCB文件,第一行内容:" + content); int dcount = Convert.ToInt32(content); //FCB的数量 for (int i = 1; i <= dcount; i++) { FCB fcb = new FCB(); fcb.RStore(fcbr); Directory.fcb_table[i] = fcb; //directory.Add(fcb); } fcbr.Close(); fcbStorage.Close(); FileStream FileStore = new FileStream("txtRecord\\File.txt", FileMode.Open); //读取File StreamReader fr = new StreamReader(FileStore); for (int i = 1; i <= dcount; i++) { Directory.file_table[i] = new File(); Directory.file_table[i].RStore(fr); } fr.Close(); FileStore.Close(); } }
//移除该文件 public void removeFile(FCB item) { //将磁盘块中该文件的指针删除 file_table.Remove(item.filePointer); }
//移除文件 public void removeFile(FCB item) { file_table.Remove(item.filePointer); }
public InputBox(File file, FCB fcb) { InitializeComponent(); renaming_file = file; renaming_fcb = fcb; }