protected override void BeforeRun() { KernelUtils.Init(this); Curse.kern = this; env_vars += ";VERSION:" + kernel_version + ";KERNEL:" + kernel_flavour; FS = new Sys.FileSystem.CosmosVFS(); Sys.FileSystem.VFS.VFSManager.RegisterVFS(FS); FS.Initialize(); Console.WriteLine("Scanning filesystems..."); if (!Directory.Exists(@"0:\")) { Curse.ShowMessagebox("FAT Driver", "Cosmos could not find a valid FAT filesystem on 0:\\. Some Memphis applications may not function."); } UserManager.LoginScreen(); Console.Clear(); Console.WriteLine(memphis_logo); Console.WriteLine("Welcome to Memphis."); Console.WriteLine($"Version: {GetVar("VERSION")}\t\tKernel flavour: {GetVar("KERNEL")}"); Console.WriteLine($@"System information: - FAT partition count: {Sys.FileSystem.VFS.VFSManager.GetVolumes().Count} - Current user: {UserManager.CurrentUser.Name} - Permission level: {UserManager.CurrentUser.PermissionLevel} - User Directory: {UserManager.CurrentUser.UserDirectory} - Current date and time is: {SystemInfo.Time.ToString()}"); }
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."); } }