private void pastFileToolStripMenuItem_Click_1(object sender, EventArgs e) { OS_Simulation.FileFunction copyfile = new OS_Simulation.FileFunction(); cpathname2 = copyfile.GetPathname(treeView1.SelectedNode.FullPath); string[] names1 = cpathname1.Split(new char[] { '\\', '.' }); string[] names2 = cpathname2.Split(new char[] { '\\', '.' }); string harddisk1 = ""; string harddisk2 = ""; if (names1[0] == "c:" || names1[0] == "C:") { harddisk1 = "disk1.txt"; } if (names1[0] == "d:" || names1[0] == "D:") { harddisk1 = "disk2.txt"; } if (string.Equals(names1[0], names2[0])) { harddisk2 = harddisk1; } else { if (harddisk1 == "disk1.txt") { harddisk2 = "disk2.txt"; } else { harddisk2 = "disk1.txt"; } } if (flag == 1) { copyfile.DeepCopyFile(cpathname1, cpathname2, harddisk1, harddisk2); } if (flag == 2 && string.Equals(names1[0], names2[0])) //盘内剪切 { copyfile.CutFile(cpathname1, cpathname2, harddisk1); } if (flag == 2 && !string.Equals(names1[0], names2[0])) //磁盘间的剪切 { copyfile.DeepCopyFile(cpathname1, cpathname2, harddisk1, harddisk2); copyfile.DeleteFile(cpathname1, harddisk1); } copyfile.ReadFile(treeView1, contextMenuStrip1, imageList1); copyfile.DrawDisk(groupBox2, "disk1.txt"); copyfile.DrawDisk(groupBox3, "disk2.txt"); }
private void button_execute_Click(object sender, EventArgs e) { if (textBox_command.Text == "") { MessageBox.Show("请输入命令和文件路径", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //分割路径 string[] command_pathname = textBox_command.Text.Split(new char[] { ' ' }); string command = command_pathname[0]; string pathname = command_pathname[1]; string[] names = pathname.Split(new char[] { '\\', '.' }); OS_Simulation.FileFunction newfile = new OS_Simulation.FileFunction(); string harddisk = ""; if (names[0] == "c:" || names[0] == "C:") { harddisk = "disk1.txt"; } if (names[0] == "d:" || names[0] == "D:") { harddisk = "disk2.txt"; } if (command == "create") { int[] disknum = newfile.SearchFAT(1, harddisk); //查找一个空盘块分配给文件 byte attribute = new byte(); if (names[names.Length - 1].Length == 1 && Convert.ToChar(names[names.Length - 1]) == 'e') { attribute = 2; } else if (names[names.Length - 1].Length == 1 && Convert.ToChar(names[names.Length - 1]) == 't') { attribute = 4; } else { attribute = 8; } switch (attribute) { case 2: case 4: if (newfile.Search(pathname, harddisk) != 2) { newfile.CreateFile(pathname, attribute, Convert.ToByte(disknum[0]), Convert.ToChar(1), harddisk); //建立exe文件或txt文件 newfile.RecordFileFAT(disknum, harddisk); //记录FAT表 } else { MessageBox.Show("文件存在!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } break; case 8: newfile.CreateMenu(pathname, harddisk); //建立目录 break; } } else if (command == "delete") { if (names[names.Length - 1].Length == 1) { newfile.DeleteFile(pathname, harddisk); } else { newfile.DeleteMenu(pathname, harddisk); } } else if (command == "edit") { found: if (names[0] == "c:" || names[0] == "C:") { harddisk = "disk1.txt"; } if (names[0] == "d:" || names[0] == "D:") { harddisk = "disk2.txt"; } if (pathname.Length == 2) //在本地C盘和D盘上编辑 { return; } string halfpathname = pathname.Remove(pathname.Length - 6); char attribute = Convert.ToChar(names[names.Length - 1]); int disknum; UTF8Encoding utf = new UTF8Encoding(); byte[] name = utf.GetBytes(names[names.Length - 2]); if (names.Length == 3) //例c:\aaa.t { disknum = 3; } else { disknum = newfile.Search(halfpathname, harddisk); } int item = newfile.FindItem(disknum, name, attribute, harddisk)[0]; int address = newfile.FindItem(disknum, name, attribute, harddisk)[1]; buffer = newfile.ReadFCB(disknum, item, harddisk); //获取文件的FCB信息 int[] dnums = newfile.FindDiskNumber(buffer.Address, harddisk); //找到文件占用的盘块返回整型数组 FileStream Disk = new FileStream(harddisk, FileMode.Open); byte[] content = new byte[64 * dnums.Length]; for (int i = 0; i < dnums.Length; i++) { Disk.Seek(64 * (dnums[i] - 1), SeekOrigin.Begin); Disk.Read(content, 64 * i, 64); } Disk.Close(); filecontent = utf.GetString(content); Form_EFile formfile = new Form_EFile(filecontent, buffer.Attribute, buffer.Name); DialogResult result = formfile.ShowDialog(); if (result == DialogResult.OK && formfile.flag == 1) { //修改FCB信息 buffer.Name = formfile.buffer.Name; buffer.Type = formfile.buffer.Type; buffer.Attribute = formfile.buffer.Attribute; buffer.Length = Convert.ToChar(formfile.number); string newname = ""; if (buffer.Attribute == 2 || buffer.Attribute == 3) { newname = utf.GetString(buffer.Name) + ".exe"; } else { newname = utf.GetString(buffer.Name) + ".txt"; } if (newfile.SearchPreNode(treeView1.SelectedNode, newname) == 1 || newfile.SearchNextNode(treeView1.SelectedNode, newname) == 1) { return; } newfile.DeleteFile(pathname, harddisk); //删除原文件 int[] newdnums = new int[formfile.number]; newdnums = newfile.SearchFAT(formfile.number, harddisk); //寻找空盘块 newfile.RecordFileFAT(newdnums, harddisk); //记录FAT newfile.WriteFile(disknum, item, buffer, harddisk); //把新的FCB信息写入目录项 newfile.WriteContent(newdnums, formfile.filecontent, harddisk); //文件内容写入磁盘 newfile.ReadFile(treeView1, contextMenuStrip1, imageList1); newfile.DrawDisk(groupBox2, "disk1.txt"); newfile.DrawDisk(groupBox3, "disk2.txt"); } if (result == DialogResult.OK && formfile.flag == 0) { goto found; } if (result == DialogResult.Cancel) { } } else if (command == "copy") { string cpathname1 = command_pathname[1]; string cpathname2 = command_pathname[3]; string[] names1 = cpathname1.Split(new char[] { '\\', '.' }); string[] names2 = cpathname2.Split(new char[] { '\\', '.' }); string harddisk1 = ""; string harddisk2 = ""; if (names1[0] == "c:" || names1[0] == "C:") { harddisk1 = "disk1.txt"; } if (names1[0] == "d:" || names1[0] == "D:") { harddisk1 = "disk2.txt"; } if (string.Equals(names1[0], names2[0])) { harddisk2 = harddisk1; } else { if (harddisk1 == "disk1.txt") { harddisk2 = "disk2.txt"; } else { harddisk2 = "disk1.txt"; } } newfile.DeepCopyFile(command_pathname[1], command_pathname[3], harddisk1, harddisk2); } else if (command == "cut") { #region rubbish /* * string cpathname1 = command_pathname[1]; * string cpathname2 = command_pathname[3]; * string[] names1 = cpathname1.Split(new char[] { '\\', '.' }); * string[] names2 = cpathname2.Split(new char[] { '\\', '.' }); * string harddisk1 = ""; * string harddisk2 = ""; * int flag = 0; * if (names1[0] == "c:" || names1[0] == "C:") * { * harddisk1 = "disk1.txt"; * } * * if (names1[0] == "d:" || names1[0] == "D:") * { * harddisk1 = "disk2.txt"; * } * * if (string.Equals(names1[0], names2[0])) * { * harddisk2 = harddisk1; * flag = 1; //盘内剪切 * } * else * { * flag = 2; //盘间剪切 * if (harddisk1 == "disk1.txt") * { * harddisk2 = "disk2.txt"; * } * else * { * harddisk2 = "disk1.txt"; * } * } * if (flag == 1) * { * newfile.CutFile(command_pathname[1], command_pathname[3], harddisk1); * } * if (flag == 2) * { * newfile.DeepCopyFile(command_pathname[1], command_pathname[3], harddisk1, harddisk2); * newfile.DeleteFile(command_pathname[1], harddisk1); * } */ #endregion } else { MessageBox.Show("无法识别的命令!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } newfile.ReadFile(treeView1, contextMenuStrip1, imageList1); newfile.DrawDisk(groupBox2, "disk1.txt"); newfile.DrawDisk(groupBox3, "disk2.txt"); textBox_command.Focus(); }