Exemplo n.º 1
0
        private void cutFileToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            OS_Simulation.FileFunction newfile = new OS_Simulation.FileFunction();
            string pathname = newfile.GetPathname(treeView1.SelectedNode.FullPath);

            string[] pnames   = pathname.Split(new char[] { '\\', '.' });
            string   harddisk = "";

            if (pnames[0] == "c:" || pnames[0] == "C:")
            {
                harddisk = "disk1.txt";
            }

            if (pnames[0] == "d:" || pnames[0] == "D:")
            {
                harddisk = "disk2.txt";
            }

            if (pathname.Length == 2)   //在本地C盘和D盘上编辑
            {
                return;
            }

            string       halfpathname = pathname.Remove(pathname.Length - 6);
            char         attribute    = Convert.ToChar(pnames[pnames.Length - 1]);
            int          disknum;
            UTF8Encoding utf = new UTF8Encoding();

            byte[] name = utf.GetBytes(pnames[pnames.Length - 2]);
            if (pnames.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);
            string str = "";
            int    m   = 0;

            while (filecontent[m] != '\0')
            {
                str = str + filecontent[m];
                m++;
            }


            for (int i = 0; i < 8; i++)
            {
                if (instructions[i] == null)
                {
                    instructions[i] = "null";
                }
            }

            int flag = 0;

            for (int i = 0; i < 8; i++)
            {
                if (instructions[i] == "null")
                {
                    instructions[i] = str;
                    //MessageBox.Show("已分配给Process"+(i+1) , "执行成功", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
                    processAllocate.Text = "Process" + (i + 1);
                    flag = 1;
                    break;
                }
            }
            if (flag == 0)
            {
                MessageBox.Show("指令数量达到上限", "执行失败", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 执行命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button_execute_Click_1(object sender, EventArgs e)
        {
            try
            {
                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[] { '\\', '.' });
                FileFunction newfile          = new 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
                    {
                        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文件
                            newfile.RecordFileFAT(disknum, harddisk);                                                         //记录FAT表
                        }
                        else
                        {
                            MessageBox.Show("文件存在!", "注意", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        break;

                    case 8:
                        newfile.CreateMenu(pathname, harddisk);                 //建立目录

                        break;
                    }
                }
                else if (command == "delete")
                {
                    byte attribute = new byte();
                    if (names[names.Length - 1].Length == 1 && Convert.ToChar(names[names.Length - 1]) == 'e')
                    {
                        attribute = 2;
                    }
                    else
                    {
                        attribute = 8;
                    }
                    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) + ".e";
                        }
                        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")
                {
                    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);
                    }
                }

                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();
            }
            catch
            {
                MessageBox.Show("!!");
            }
        }
Exemplo n.º 3
0
        private void editFileToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
found:
            OS_Simulation.FileFunction newfile = new OS_Simulation.FileFunction();
            string pathname = newfile.GetPathname(treeView1.SelectedNode.FullPath);

            string[] pnames   = pathname.Split(new char[] { '\\', '.' });
            string   harddisk = "";

            if (pnames[0] == "c:" || pnames[0] == "C:")
            {
                harddisk = "disk1.txt";
            }

            if (pnames[0] == "d:" || pnames[0] == "D:")
            {
                harddisk = "disk2.txt";
            }

            if (pathname.Length == 2)   //在本地C盘和D盘上编辑
            {
                return;
            }

            string       halfpathname = pathname.Remove(pathname.Length - 6);
            char         attribute    = Convert.ToChar(pnames[pnames.Length - 1]);
            int          disknum;
            UTF8Encoding utf = new UTF8Encoding();

            byte[] name = utf.GetBytes(pnames[pnames.Length - 2]);
            if (pnames.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)
            {
                string newname = "";
                if (buffer.Attribute == 2 || buffer.Attribute == 3)
                {
                    newname = utf.GetString(buffer.Name) + ".e";
                }

                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); //寻找空盘块

                //修改FCB信息
                buffer.Name      = formfile.buffer.Name;
                buffer.Type      = formfile.buffer.Type;
                buffer.Attribute = formfile.buffer.Attribute;
                buffer.Length    = Convert.ToChar(newdnums.Length);

                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)
            {
            }
        }