コード例 #1
0
 public void Execute(IGuiConsole g, string cmdline)
 {
     if (CommandParaser.IsGUI)
     {
         Display.Disable();
     }
     MIV.MIV.file = cmdline.Replace("edit", "");
     MIV.MIV.StartMIV(g);
 }
コード例 #2
0
ファイル: LsCommand.cs プロジェクト: MishaTY/Misha-OS
        public void Execute(IGuiConsole g, string cmdline)
        {
            var fs = g.CurrentDIR;

            g.WriteLine("Volume Label is " + Kernel.FS.GetFileSystemLabel(Path.GetPathRoot(fs)));
            g.WriteLine("Directory of " + fs);
            g.WriteLine();
            foreach (DirectoryEntry r in Kernel.FS.GetDirectoryListing(fs))
            {
                g.WriteLine(r.mName);
            }
        }
コード例 #3
0
        public static void StartMIV(IGuiConsole g)
        {
            Console.WriteLine("Enter file's filename to open:");
            Console.WriteLine("If the specified file does not exist, it will be created.");

            file = Console.ReadLine();
            try
            {
                if (File.Exists(@"0:\" + file))
                {
                    Console.WriteLine("Found file!");
                }
                else if (!File.Exists(@"0:\" + file))
                {
                    Console.WriteLine("Creating file!");
                    File.Create(@"0:\" + file);
                }
                Console.Clear();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            string text;

            Console.WriteLine("Do you want to open " + file + " content? (Yes/No)");
            if (Console.ReadLine().ToLower() == "yes" || Console.ReadLine().ToLower() == "y")
            {
                text = miv(File.ReadAllText(@"0:\" + file));
            }
            else
            {
                text = miv(null);
            }

            Console.Clear();

            if (text != null)
            {
                File.WriteAllText(@"0:\" + file, text);
                Console.WriteLine("Content has been saved to " + file);
            }
            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
            if (g.term is Window)
            {
                MishaOS.Gui.DesktopManager.CloseWindow((g.term as Window));
            }

            BootManager.Boot();
        }
コード例 #4
0
 public void Execute(IGuiConsole g, string cmdline)
 {
     g.WriteLine("MishaOS Help");
     g.WriteLine("=====================");
     g.WriteLine("---General Commands--");
     g.WriteLine("help - Show Help");
     g.WriteLine("about - Kernel Info");
     g.WriteLine("clear - Clear Screen");
     g.WriteLine("setup - Open Setup");
     g.WriteLine("shutdown - Shutdown");
     g.WriteLine("reboot - Reboots");
     g.WriteLine("cat - Shows File Contents");
     g.WriteLine("beep - Beeps");
     g.WriteLine("exit - Exit Terminal");
     g.WriteLine();
     g.WriteLine("-FileSystem Commands-");
     g.WriteLine("cd - Change Dir");
     g.WriteLine("ls - List Files and Dirs");
     g.WriteLine("mkdir - Creates Dir");
 }
コード例 #5
0
ファイル: cat.cs プロジェクト: MishaTY/Misha-OS
        public void Execute(IGuiConsole g, string cmdline)
        {
            string newcmdlane = cmdline.Replace("cat", "");

            string[] args = newcmdlane.Split();
            if (args.Length == 1)
            {
                g.WriteLine("Bad Syntax. Use cat /? for help.");
            }
            else if (args.Length == 2)
            {
                if (args[1] == "/?")
                {
                    g.WriteLine("CAT Help:");
                    g.WriteLine("=============");
                    g.WriteLine("Syntax: cat <Filename>");
                }
                else
                {
                    if (!File.Exists(args[1]))
                    {
                        g.WriteLine("Error: File " + args[1] + " does not exist!");
                        return;
                    }
                    try
                    {
                        foreach (var item in File.ReadAllLines(args[1]))
                        {
                            g.WriteLine(item);
                        }
                    }
                    catch (Exception ex)
                    {
                        g.WriteLine("ERROR: " + ex.Message);
                    }
                }
            }
        }
コード例 #6
0
ファイル: mkdir.cs プロジェクト: MishaTY/Misha-OS
        public void Execute(IGuiConsole g, string cmdline)
        {
            string newdirname = cmdline.Replace("mkdir ", "");

            string[] paramss = newdirname.Split();
            // Arguments CommandLine = new Arguments(paramss);
            bool quiet = false;

            if (paramss.Length == 0)
            {
                g.WriteLine("The syntax of the command is incorrect. Use /? for help."); return;
            }
            if (paramss[0] == "/?")
            {
                g.WriteLine("mkdir help");
                g.WriteLine("Syntax: mkdir <options> <FolderName>");
                g.WriteLine("====================");
                g.WriteLine("Options:");
                g.WriteLine("-q     Disable Output");
                g.WriteLine("====================");
                g.WriteLine("Example: mkdir -q lalala");
                g.WriteLine("Example: mkdir lalala");
                g.WriteLine("These examples will create a dirrectory names lalala.");
                return;
            }
            else if (paramss[0] == "-q")
            {
                quiet = true;
            }

            if (!string.IsNullOrWhiteSpace(paramss[paramss.Length - 1]) && paramss[paramss.Length - 1] != "mkdir")
            {
                string dirName = paramss[paramss.Length - 1];
                if (quiet)
                {
                    try
                    {
                        Directory.CreateDirectory(g.CurrentDIR + @"\" + dirName);
                    }
                    catch { }
                }
                else
                {
                    bool sucess = true;
                    try
                    {
                        Directory.CreateDirectory(g.CurrentDIR + @"\" + dirName);
                    }
                    catch (Exception ex)
                    {
                        sucess = false;
                        g.WriteLine("Error: " + ex.Message);
                    }
                    if (sucess)
                    {
                        g.WriteLine("Created Dirrectory: " + dirName);
                    }
                }
            }
            else
            {
                g.WriteLine("The syntax of the command is incorrect. Use /? for help.");
            }


            //if (paramss.Length == 0)
            //{
            //    g.WriteLine("The syntax of the command is incorrect. Use mkdir /? for help");
            //    return;
            //}
            //else if (paramss.Length == 1)
            //{
            //    g.WriteLine("Comming Soon: dir name is: " + newdirname);
            //    //return;
            //}
            //else if (paramss.Length == 2)
            //{
            //    g.WriteLine("<QUIET MODE> Comming Soon: dir name is: " + newdirname);
            //   // return;
            //}

            //if (paramss[0] == "/?")
            //{

            //}
            //else
            //{
            //    g.WriteLine("The syntax of the command is incorrect. Use mkdir /? for help");
            //    return;
            //}
        }
コード例 #7
0
        /// <summary>
        /// Process a command
        /// </summary>
        /// <param name="g">The Console.</param>
        /// <param name="cmd">The Command</param>
        public static void ProcessCommand(IGuiConsole g, string cmd)
        {
            if (cmd.ToLower().StartsWith("help"))
            {
                new Help().Execute(g, cmd);
            }
            else if (cmd.ToLower().StartsWith("clear"))
            {
                g.Clear();
            }
            else if (cmd.ToLower().StartsWith("about"))
            {
                g.WriteLine(Kernel.KernelVersion);
            }
            else if (cmd.ToLower().StartsWith("ls"))
            {
                new LsCommand().Execute(g, cmd);
            }
            else if (cmd.ToLower().StartsWith("dir"))
            {
                new LsCommand().Execute(g, cmd);
            }
            else if (cmd.ToLower().StartsWith("cd"))
            {
                string NewName = cmd.Replace("cd ", "");
                var    fs      = g.CurrentDIR;
                if (Directory.Exists(fs + @"\" + NewName))
                {
                    g.CurrentDIR = fs + NewName + @"\";
                }
                else if (NewName == "..")
                {
                    g.CurrentDIR = Directory.GetParent(fs).FullName;
                }
                else if (NewName == "/" | NewName == @"\")
                {
                    g.CurrentDIR = Directory.GetDirectoryRoot(fs);
                }
                else if (NewName.Length == 2)
                {
                    if (NewName[1] == ':')
                    {
                        if (Directory.Exists(NewName + @"\"))
                        {
                            g.CurrentDIR = NewName + @"\";
                        }
                        else
                        {
                            g.WriteLine("ERROR: Dirrectory " + NewName + @"\" + " Does not exist.");
                        }
                    }
                    else
                    {
                        g.WriteLine("ERROR: Dirrectory " + fs + @"\" + NewName + " Does not exist.");
                    }
                }
                else
                {
                    g.WriteLine("ERROR: Dirrectory " + fs + @"\" + NewName + " Does not exist.");
                }
            }
            else if (cmd.ToLower().StartsWith("shutdown"))
            {
                Cosmos.System.Power.Shutdown();
            }
            else if (cmd.ToLower().StartsWith("reboot"))
            {
                Cosmos.System.Power.Reboot();
            }
            else if (cmd.ToLower().StartsWith("mkdir"))
            {
                new mkdir().Execute(g, cmd);
            }
            else if (cmd.ToLower().StartsWith("cat"))
            {
                new cat().Execute(g, cmd);
            }
            else if (cmd.ToLower().StartsWith("beep"))
            {
                System.Console.Beep();
            }
            else if (cmd.ToLower().StartsWith("edit"))
            {
                new edit().Execute(g, cmd);
            }
            else if (cmd.ToLower().StartsWith("crash"))
            {
                throw new System.Exception("Crash command executed.");
            }
            else if (cmd.ToLower().StartsWith("mode"))
            {
                var args = cmd.ToLower().Split();

                if (args.Length == 1 | args.Length == 0)
                {
                    g.WriteLine("Invaild Usage. Use mode help for help.");
                }
                else if (args.Length == 2)
                {
                    if (args[1] == "text")
                    {
                        if (IsGUI == true)
                        {
                            if (g.term is Window window)
                            {
                                DesktopManager.CloseWindow(window);
                            }
                            IsGUI = false;
                            //Switch over to text terminal.
                            g = new TextTerm
                            {
                                term = new TextTerm()
                            };
                            Display.Disable();
                            VGADriverII.SetMode(VGAMode.Text80x25);
                            g.WriteLine("Now in text mode!");
                            g.Write(g.CurrentDIR);
                            while (IsGUI == false)
                            {
                                var input = g.ReadLine();
                                ProcessCommand(g, input);
                                g.Write(g.CurrentDIR);
                            }
                        }
                        else
                        {
                            g.WriteLine("ERROR: Already in text mode");
                        }
                    }
                    else if (args[1] == "gui")
                    {
                        if (!IsGUI)
                        {
                            IsGUI = true;
                            Display.Init();
                            UiMouse.Init();
                            g.term = new GuiConsole(new Terminal(), 80);
                            DesktopManager.OpenWindow(new Taskbar());
                        }
                        else
                        {
                            g.WriteLine("ERROR: Already in GUI mode");
                        }
                    }
                    else if (args[1] == "help")
                    {
                        g.WriteLine("Mode command line usage");
                        g.WriteLine("======================");
                        g.WriteLine("mode <DisplayMode>");
                        g.WriteLine("Display Modes: ");
                        g.WriteLine("GUI - Switches over to GUI mode");
                        g.WriteLine("TEXT - Switches over to Text mode");
                    }
                    else
                    {
                        g.WriteLine("Invaild Usage. Use \"mode help\" for help.");
                    }
                }
                g.WriteLine("[DEBUG] args length: " + args.Length);
                foreach (var item in args)
                {
                    g.WriteLine(item);
                }
            }
            else if (cmd.ToLower().StartsWith("exit"))
            {
                if (IsGUI)
                {
                    if (g.term is Window window)
                    {
                        DesktopManager.CloseWindow(window);
                    }
                }
                else
                {
                    g.WriteLine("Exit cannot be used on a text session. Please use gui mode to use exit command.");
                }
            }
            else if (cmd.ToLower().StartsWith("setup"))
            {
                if (IsGUI)
                {
                    DesktopManager.OpenWindow(new SetupWindow());
                }
                else
                {
                    IsGUI = true;

                    Display.Init();
                    UiMouse.Init();
                    DesktopManager.OpenWindow(new SetupWindow());
                    Display.Render();
                }
            }
            else if (string.IsNullOrEmpty(cmd))
            {
            }
            else
            {
                g.WriteLine($"\"{cmd}\" is not recognized as an internal command,operable program.");
            }
        }