//创建文件 private void button4_Click(object sender, EventArgs e) { if (treeView1.SelectedNode == null) { MessageBox.Show("请选择一个节点", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { //创建一个节点对象,并初始化 fileNode tmp; tmp = new fileNode(); if (newFileName == "") { MessageBox.Show("请输入名称", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { tmp.Text = newFileName + ".txt"; tmp.ToolTipText = "1"; //在TreeView组件中加入子节点 tmp.size = 0; //for (int i = 0; i < 32;i++ ) //{ // if(Fat[i].Name==tmp.Text) // { // MessageBox.Show("有重复命名的文件", "提示信息", // MessageBoxButtons.OK, MessageBoxIcon.Information); // return; // } //} //tmp.address = CreateFile(1, tmp.Text); if (!MemManager.CanCreate(tmp.Text)) { MessageBox.Show("有重复命名的文件", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } tmp.address = MemManager.AllocateFile(1, tmp.Text); if (tmp.address >= 0) { treeView1.SelectedNode.Nodes.Add(tmp); treeView1.SelectedNode = tmp; FileStream NewText = File.Create(tmp.Text); NewText.Close(); } else { MessageBox.Show("磁盘空间不足,创建失败", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } textBox2.Text = ""; FileIterater fileIterater = new FileIterater(tmp, treeView1.SelectedNode, true, false); iteraterList.Add(fileIterater); } } }
//static Block[] Fat = new Block[32]; //static int emptyblock;//磁盘空闲块 //初始化fat表 //private void ResumeFat() //{ // string fatbin; // StreamReader srfat = new StreamReader("fat.bin"); // for (int i = 0; i < 32; i++) // { // fatbin = srfat.ReadLine(); // if (fatbin == null) // { // for (int k = 0; k < 32; k++) // { // Fat[i].Name = ""; // Fat[i].busy = false; // Fat[i].next = -1; // Fat[i].isStart = false; // } // emptyblock = 32; // break; // } // if (fatbin == "0 0 -1 -1") // { // Fat[i].Name = ""; // Fat[i].busy = false; // Fat[i].next = -1; // Fat[i].isStart = false; // emptyblock++; // } // else // { // var a = fatbin.Split(' '); // Fat[i].next = Convert.ToInt32(a[2]); // Fat[i].busy = true; // Fat[i].Name = a[1]; // if (a[3] == "0") // Fat[i].isStart = false; // else // Fat[i].isStart = true; // } // } // srfat.Close(); // srfat.Dispose(); // StreamWriter swfat = new StreamWriter("fat.bin"); // swfat.Close(); // swfat.Dispose(); //} //根据保存结果恢复之前创建的目录 private void ResumeDictionary() { DirectoryInfo dir = new DirectoryInfo(Application.StartupPath).Parent.Parent; path = dir.FullName; StreamReader sr = new StreamReader("root.bin"); string parent; string name; string txt; while (true) { if ((txt = sr.ReadLine()) == null) { break; } fileNode tmp = new fileNode(); var b = txt.Split(' '); name = b[0]; if (b[0] == "") { break; } if (b[1] == "0") { tmp.size = 0; tmp.BackColor = Color.Yellow; } else if (b[1] == "1") { FileInfo fi = new FileInfo(name); tmp.size = (Int32)fi.Length; } else { break; } parent = b[2]; //TreeNode tmp; //tmp = new TreeNode(); tmp.Text = name; tmp.ToolTipText = b[1]; FindTreeViewNode(treeView1.Nodes, parent).Nodes.Add(tmp); } treeView1.ExpandAll(); sr.Close(); sr.Dispose(); StreamWriter sw = new StreamWriter("root.bin"); sw.Close(); sw.Dispose(); }
//存储磁盘fat表 //public void SaveFat() //{ // for (int i = 0; i < 32; i++) // { // FileStream fs = new FileStream("fat.bin", FileMode.Append); // StreamWriter sw = new StreamWriter(fs); // string line = ""; // if (Fat[i].busy) // { // line = "1 " + Fat[i].Name + " " + Fat[i].next.ToString() + " "; // if (Fat[i].isStart) // line += "1"; // else // line += "0"; // } // else // line = "0 0 -1 -1"; // sw.WriteLine(line); // sw.Close(); // sw.Dispose(); // fs.Close(); // fs.Dispose(); // } //} //在fat表中找到文件起始块。 //public int FindinFat(string n) //{ // for(int i=0;i<32;i++) // { // if (Fat[i].isStart && Fat[i].Name == n) // return i; // } // return -1; //} //给文件分配块数 //public int CreateFile(int size,string name) //{ // if (emptyblock == 0) // return -1; // int num_block;//所需块数 // if(size%32!=0) // { // num_block = size / 32 + 1; // } // else // { // num_block = size / 32; // } // int prev = -1; // int start = -1; // if (num_block <= emptyblock) // { // for (int i = 0, j = 0; j < num_block; i++) // { // if (Fat[i].busy==false) // { // Fat[i].busy = true; // Fat[i].Name = name; // Fat[i].next = -1; // if (prev != -1) // { // Fat[prev].next = i; // Fat[i].isStart = false; // } // else // { // start = i; // Fat[i].isStart = true; // } // prev = i; // j++; // } // } // emptyblock -= num_block; // } // return start; //} private void button1_Click(object sender, EventArgs e) //添加目录 { if (treeView1.SelectedNode == null) { MessageBox.Show("请选择一个节点", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { //创建一个节点对象,并初始化 fileNode tmp; tmp = new fileNode(); if (newPathName == "") { MessageBox.Show("请输入名称", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { tmp.Text = newPathName; tmp.BackColor = Color.Yellow; tmp.ToolTipText = "0"; //在TreeView组件中加入子节点 tmp.size = 0; tmp.address = -1; if (repeatName(treeView1.SelectedNode.Nodes, tmp.Text)) { MessageBox.Show("有重复命名,创建失败", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } treeView1.SelectedNode.Nodes.Add(tmp); treeView1.SelectedNode = tmp; textBox1.Text = ""; FileIterater fileIterater = new FileIterater(tmp, treeView1.SelectedNode, false, false); iteraterList.Add(fileIterater); } } }