示例#1
0
        ///<summary>
        ///Operating System
        ///</summary>
        protected override void Run()
        {
            Utilities();

            Console.Write(current_directory + "> ");
            string userinput = Console.ReadLine();

            string[] args = userinput.Split(' ');

            switch (args[0].ToLower())
            {
            case "restart":
                Sys.Power.Reboot();
                break;

            case "shutdown":
                throw new Exception("Shuting Down...");
#pragma warning disable CS0162 // Unreachable code detected
                break;

#pragma warning restore CS0162 // Unreachable code detected
            case "help":
                Console.WriteLine("Found 13 in the directory: \n HELP: Shows a list of commands \n RESTART: Restarts client \n SHUTDOWN: Shuts down client \n CLEAR: Clears the console \n ECHO: Echoes a line of text into the console \n COLOR: Changes the console color based on the user prefrences \n SYSINFO: Gives the system infomation \n DIR: Lists the volume directories \n CSPAD: csOS Text Editor. Can write to files \n DEL: Deletes the specified file \n LSDIR: Lists the files in a directory \n PRINT: Displays the text of the file \n MKDIR: Makes the directory of the users choice \n CD: Goes to the user-specified directory");
                break;

            case "clear":
                Console.Clear();
                break;

            case "echo":
                Console.Write("Line to echo:");
                string input1 = Console.ReadLine();
                Console.WriteLine(input1);
                break;

            case "color":
                Console.WriteLine("Valid colors: ROYGBIV, Black, and White");
                Console.Write("Color:");
                string input2 = Console.ReadLine();
                switch (input2)
                {
                case "red":
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Color changed");
                    break;

                case "orange":
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    break;

                case "yellow":
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;

                case "green":
                    Console.ForegroundColor = ConsoleColor.Green;
                    break;

                case "blue":
                    Console.ForegroundColor = ConsoleColor.DarkBlue;
                    break;

                case "indigo":
                    Console.ForegroundColor = ConsoleColor.Blue;
                    break;

                case "violet":
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    break;

                case "black":
                    Console.ForegroundColor = ConsoleColor.Black;
                    break;

                case "white":
                    Console.ForegroundColor = ConsoleColor.White;
                    break;

                case "reset":
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Color reset.");
                    break;

                default:
                    Console.WriteLine("The color you have inputed is not a valid color. Please use ROYGBIV and Black and White.");
                    break;
                }
                break;

            case "cspad":
                Console.WriteLine("Entering CSPad...");
                Console.WriteLine("Press enter to enter CSPad");
                Console.ReadLine();
                Console.Clear();
                Console.BackgroundColor = ConsoleColor.White;
                Console.ForegroundColor = ConsoleColor.Black;
                Console.Write("File to save as:");
                string fileName = Console.ReadLine();
                fs.CreateFile(current_directory + fileName);
                Console.Write("Text to save:");
                string input = Console.ReadLine();
                File.WriteAllText(current_directory + fileName, input);
                Console.WriteLine("File Saved!");
                break;

            case "del":
                Console.WriteLine("***WARNING*** \\ This cannot be undone!");
                Console.Write("File to Delete:");
                string del = Console.ReadLine();
                File.Delete(del);
                break;

            case "print":
                Console.WriteLine("Entering print mode...");
                Console.Write("File to read:");
                string file = Console.ReadLine();
                if (File.Exists(file))
                {
                    Console.WriteLine(File.ReadAllText(file));
                }
                else
                {
                    if (File.Exists(file) == false)
                    {
                        Console.WriteLine("The file you have inputed does not exist. Please try again");
                    }
                }
                break;

            case "sysinfo":
                Console.WriteLine("csOS (C-Sharp Operating System) \n CREATOR: Lskywalker48 \n VERSION: 1.0.1");
                break;

            case "dir":
                var vols = fs.GetVolumes();
                Console.WriteLine("NAME\tSIZE");
                foreach (var vol in vols)
                {
                    Console.WriteLine(vol.mName + "\t" + vol.mSize.ToString());
                }
                break;

            case "mkdir":
                Console.Write("Name of Directory:");
                string dirAdd = Console.ReadLine();
                fs.CreateDirectory(current_directory + dirAdd);
                Console.WriteLine("Directory Created!");
                break;

            case "cd":
                Console.Write("DIR to go to:");
                string dirtogo = Console.ReadLine();

                if (fs.GetDirectory(current_directory + dirtogo) != null)
                {
                    current_directory = current_directory + dirtogo + "\\";
                }
                else
                {
                    if (dirtogo == "goback")
                    {
                        if (current_directory.Length > 3)
                        {
                            var dirGet = fs.GetDirectory(Directory.GetCurrentDirectory());
                        }
                    }
                }
                break;

            case "lsdir":
                Console.WriteLine("TYPE\tNAME");
                foreach (var dir in Directory.GetDirectories(Directory.GetCurrentDirectory()))
                {
                    Console.WriteLine("<DIR>\t" + dir);
                }
                foreach (var dir in Directory.GetFiles(Directory.GetCurrentDirectory()))
                {
                    Console.WriteLine(Directory.GetFiles(Directory.GetCurrentDirectory()).ToString() + "\t" + dir);
                }
                break;

            case "":
                break;

            default:
                Console.WriteLine("The entered command: '" + userinput + "' does not exist. Please try again.");
                break;
            }
        }
示例#2
0
        public void InterpretCMD(string input)
        {
            string lower = input.ToLower(); //so commands are not case-sensitive use this

            if (lower.StartsWith("shutdown"))
            {
                Console.Clear();
                Console.WriteLine("It is safe to shut down your system.");
                running = false;
            }
            else if (lower.StartsWith("mousetest"))
            {
                var m = new Mouse();
            }
            else if (lower.StartsWith("conf-gen"))
            {
                StartApplicationLoop(new Apps.ConfigurationGenerator(), new[] { "" });
            }
            else if (lower.StartsWith("win_test"))
            {
                var w = new TUI.BlankWindow("Jonathan Ladouceur", 22, 10, 2, 2);
                Console.CursorLeft      = 0;
                Console.CursorTop       = 0;
                Console.BackgroundColor = ConsoleColor.Black;
                var b1 = new TUI.Button("He's awesome.", 2, 2, 10, 1, w);
                var b2 = new TUI.Button("NEIN", 2, 4, 10, 1, w);
                var w2 = new TUI.BlankWindow("Another Window", 32, 20, w.X + w.Width + 3, w.Y);
            }
            else if (lower.StartsWith("sharppad"))
            {
                string fname = "";
                try
                {
                    fname = current_directory + input.Remove(0, 9);
                }
                catch
                {
                }
                StartApplicationLoop(new Apps.SharpPad(), new[] { fname });
            }
            else if (lower.StartsWith("fileskimmer"))
            {
                StartApplicationLoop(new Apps.FileSkimmer(), new[] { " " });
            }
            else if (lower.StartsWith("pkg_install "))
            {
                string p = input.Remove(0, 12);
                if (Directory.Exists(p))
                {
                    KernelUtils.HandlePackageInstall(p);
                }
            }
            else if (lower.StartsWith("write "))
            {
                string fname = lower.Remove(0, 6);
                if (string.IsNullOrEmpty(fname))
                {
                    throw new Exception("write - Trying to write to nothing, I see?");
                }
                Console.WriteLine("Single-Line Writer - Writing to file " + fname);
                Console.WriteLine("You can use C#-like escape sequences like '\\n' for new-lines and '\\t' for tabs. If you want to actually write a visible escape string - i.e 'This sequence, \\n, will print a newline', you can type in '\\\\' to escape the backslash.");
                Console.Write("> ");
                string text = Console.ReadLine();
                //escape sequence parser
                text = text.Replace("\\\\", "===");
                text = text.Replace("\\n", "\n");
                text = text.Replace("\\t", "\t");
                text = text.Replace("===", "\\"); //so that the above 2 methods don't get confused
                if (!File.Exists(current_directory + fname))
                {
                    var f = File.Create(current_directory + fname);
                    f.Close();
                }
                File.WriteAllText(current_directory + fname, text);
            }
            else if (lower.StartsWith("help "))
            {
                string topic = lower.Remove(0, 5);
                StartApplicationLoop(new Apps.HelpViewer(), new[] { "0:\\help.db", topic });
            }
            else if (lower.StartsWith("help"))
            {
                StartApplicationLoop(new Apps.HelpViewer(), new[] { "0:\\help.db" });
            }
            else if (lower.StartsWith("$"))
            {
                Console.WriteLine(GetVar(input.Remove(0, 1)));
            }
            else if (lower.StartsWith("test_crash"))
            {
                throw new Exception("Test crash.");
            }
            else if (lower.StartsWith("reboot"))
            {
                Sys.Power.Reboot();
            }
            else if (lower.StartsWith("clear"))
            {
                Console.Clear();
            }
            else if (lower.StartsWith("echo "))
            {
                try
                {
                    Console.WriteLine(input.Remove(0, 5));
                }
                catch (Exception ex)
                {
                    Console.WriteLine("echo: " + ex.Message);
                }
            }
            else if (lower.StartsWith("dir"))
            {
                Console.WriteLine("Type\tName");
                foreach (var dir in Directory.GetDirectories(current_directory))
                {
                    try
                    {
                        Console.WriteLine("<DIR>\t" + dir);
                    }
                    catch
                    {
                    }
                }
                foreach (var dir in Directory.GetFiles(current_directory))
                {
                    try
                    {
                        string[] sp = dir.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                        Console.WriteLine(sp[sp.Length - 1] + "\t" + dir);
                    }
                    catch
                    {
                    }
                }
            }
            else if (lower.StartsWith("test_write"))
            {
                var f = File.Create(current_directory + "TestFile.txt");
                f.Close();
                File.WriteAllText(current_directory + "TestFile.txt", "Test\nAnother Test");
                Console.WriteLine("Created file!");
            }
            else if (lower.StartsWith("mkdir "))
            {
                string dir = input.Remove(0, 6);
                if (!dir_exists(current_directory + dir))
                {
                    Directory.CreateDirectory(current_directory + dir);
                }
                else
                {
                    Console.WriteLine("mkdir: Directory exists.");
                }
            }
            else if (lower.StartsWith("cd "))
            {
                var newdir = input.Remove(0, 3);
                if (dir_exists(newdir))
                {
                    Directory.SetCurrentDirectory(current_directory);
                    current_directory = current_directory + newdir + "\\";
                }
                else
                {
                    if (newdir == "..")
                    {
                        var    dir = FS.GetDirectory(current_directory);
                        string p   = dir.mParent.mName;
                        if (!string.IsNullOrEmpty(p))
                        {
                            current_directory = p;
                        }
                    }
                }
            }
            else if (lower.StartsWith("print "))
            {
                string file = input.Remove(0, 6);
                if (File.Exists(current_directory + file))
                {
                    Console.WriteLine(File.ReadAllText(current_directory + file));
                }
                else
                {
                    Console.WriteLine("print: File doesn't exist.");
                }
            }
            else if (lower.StartsWith("lsvol"))
            {
                var vols = FS.GetVolumes();
                Console.WriteLine("Name\tSize\tParent");
                foreach (var vol in vols)
                {
                    Console.WriteLine(vol.mName + "\t" + vol.mSize + "\t" + vol.mParent);
                }
            }
            else if (lower.StartsWith("msg"))
            {
                Console.Write("Title: ");
                string title = Console.ReadLine();
                Console.Write("Message Text: ");
                string text = Console.ReadLine();
                Curse.ShowMessagebox(title, text);
            }
            else if (lower.StartsWith("scr "))
            {
                string p = input.Remove(0, 4);
                Interpret_Script(current_directory + p);
            }
            else
            {
                Console.WriteLine("Invalid Command.");
            }
        }