public override void Execute(string line, string[] args) { bool success = false; string realFile = ""; if (line.Length > 4) { string path = line.Substring(4, line.Length - 4); realFile = TryParseFile(path); if (realFile != "*ERROR") { PMFAT.DeleteFile(realFile); success = true; } else { CLI.WriteLine("Could not locate file \"" + realFile + "\"", Color.Red); success = false; } } else { CLI.WriteLine("Invalid argument! File expected.", Color.Red); } if (success) { CLI.WriteLine("Successfully deleted file \"" + realFile + "\"", Color.Green); } }
private static void Save() { // save file string document = ""; try { for (int i = 0; i < Lines.Count; i++) { document += Lines[i] + "\n"; } PMFAT.WriteAllText(CurrentFile, document); TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Successfully saved \"" + CurrentFile + "\"", Color.Green, Color.Black); } catch (Exception ex) { TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Unable to save file \"" + CurrentFile + "\"", Color.Red, Color.Black); } // finish Kernel.Delay(500); Draw(); }
public override void Execute(string line, string[] args) { CLI.Write("[WARNING] ", Color.DarkYellow); CLI.WriteLine("This command is a WIP and may corrupt data, continue? Y = YES, N = NO", Color.White); string input = CLI.ReadLine(); if (input.ToLower() == "yes" || input.ToLower() == "y") { bool success = false; string realPath; if (args.Length > 1) { string path = line.Substring(7, line.Length - 7); if (path.EndsWith('\\')) { path = path.Remove(path.Length - 1, 1); } //path += "\\"; realPath = TryParseFolder(path, true); if (realPath != "*ERROR") { success = true; } else { success = false; } if (success) { if (PMFAT.DeleteFolder(realPath)) { CLI.WriteLine("Successfully deleted directory \"" + realPath + "\"", Color.Green); if (realPath == PMFAT.CurrentDirectory) { PMFAT.CurrentDirectory = @"0:\"; } } else { CLI.WriteLine("Could not delete directory \"" + realPath + "\"", Color.Red); } } else { CLI.WriteLine("Error attempting to delete directory \"" + realPath + "\"", Color.Red); } } else { CLI.WriteLine("Argument expected!", Color.Red); } } else { CLI.WriteLine("Operation aborted."); } }
private static string TryParseFolder(string path, bool exists) { string realPath = path; if (path.StartsWith(PMFAT.CurrentDirectory)) { realPath = path; } else if (path.StartsWith(@"0:\")) { realPath = path; } else if (!path.StartsWith(PMFAT.CurrentDirectory) && !path.StartsWith(@"0:\")) { realPath = PMFAT.CurrentDirectory + path; } if (exists) { if (PMFAT.FolderExists(realPath)) { return(realPath); } else { return("*ERROR"); } } else { return(realPath); } }
private static string TryParseFile(string file, bool exists) { string realFile = file; if (file.StartsWith(PMFAT.CurrentDirectory)) { realFile = file; } else if (file.StartsWith(@"0:\")) { realFile = file; } else if (!file.StartsWith(PMFAT.CurrentDirectory) && !file.StartsWith(@"0:\")) { realFile = PMFAT.CurrentDirectory + file; } if (exists) { if (PMFAT.FileExists(realFile)) { return(realFile); } else { return("*ERROR"); } } else { return(realFile); } }
public static void INIT() { if (!PMFAT.Initialize()) { CLI_lite.InitializeLite(); } }
public override void Execute(string line, string[] args) { bool success = false; string src = "", dest = ""; if (args.Length == 3) { src = TryParseFile(args[1], true); dest = TryParseFile(args[2], false); if (src != "*ERROR" && dest != "*ERROR") { success = true; } else { success = false; } } else { CLI.WriteLine("Invalid argument! Path expected.", Color.Red); } if (success) { PMFAT.CopyFile(src, dest); CLI.WriteLine("Successfully copied file \"" + src + "\" to \"" + dest + "\"", Color.Green); } else { CLI.WriteLine("Error copying file \"" + src + "\" to \"" + dest + "\"", Color.Red); } }
public static List <CLICommand> Commands = new List <CLICommand>(); // Создание листа с командами public static void Initialize() { try { WriteLine("Initializing command library...", ConsoleColor.Green); // Инициализация команд!!!! Commands.Add(new CLI_CLEAR()); Commands.Add(new CLI_ABOUT()); Commands.Add(new CLI_SHUTDOWN()); Commands.Add(new CLI_REBOOT()); Commands.Add(new CLI_HELP_1()); Commands.Add(new CLI_HELP_2()); Commands.Add(new CLI_HELP_3()); Commands.Add(new CLI_AUTHORS()); Commands.Add(new CLI_CTIME()); Commands.Add(new CLI_DISK_INFO()); Commands.Add(new CLI_LS()); Commands.Add(new CLI_LS_A()); Commands.Add(new CLI_READ_FILE()); Commands.Add(new CLI_EDIT_FILE()); Commands.Add(new CLI_CREATE_FILE()); Commands.Add(new CLI_CLEAR_FILE()); Commands.Add(new CLI_DELETE_FILE()); Commands.Add(new CLI_PWD()); Commands.Add(new CLI_DELETE_DIRECTORY()); Commands.Add(new OKAY()); Console.Clear(); PMFAT.Initialize(); if (!PMFAT.Initialize()) { Console.WriteLine("[FATAL ERROR] could not initialize fat driver!"); CLI_lite.InitializeLite(); } WriteLine("Welcome to doos CLI!", ConsoleColor.Blue); WriteLine("Enter 'help-1' to display the first page of commands."); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.White; Console.BackgroundColor = ConsoleColor.DarkRed; Console.Clear(); Console.WriteLine("\n========================================================================"); Console.WriteLine("\nStatus: Kernel panic! "); Console.WriteLine("\n================================ "); Console.WriteLine(" Possible causes: "); Console.WriteLine(" - An Kernel Error in Doos "); Console.WriteLine(" - FileSystem Error "); Console.WriteLine(" - Unknown Error "); Console.WriteLine("================================ "); Console.WriteLine($"\nInfo: {e}"); Console.WriteLine("\n========================================================================"); Console.WriteLine("\n Press any key to restart and attempts to correct the error..."); Console.ReadKey(true); Console.WriteLine("\nRestarting..."); Cosmos.System.Power.Reboot(); throw; } }
protected override void BeforeRun() { // initialize fat driver PMFAT.Initialize(); // init shell Shell.Initialize(); // init vm Runner.Initialize(); }
public override void Execute(string line, string[] args) { // show contents of active directory if (args.Length == 1) { ListContents(PMFAT.CurrentDirectory); } // show contents of specified directory else if (line.Length > 4) { // parse path string path = line.Substring(4, line.Length - 4).ToLower(); if (path.EndsWith('\\')) { path = path.Remove(path.Length - 1, 1); } path += "\\"; if (PMFAT.FolderExists(path)) { if (path.StartsWith(PMFAT.CurrentDirectory)) { ListContents(path); } else if (path.StartsWith(@"0:\")) { ListContents(path); } else if (!path.StartsWith(PMFAT.CurrentDirectory) && !path.StartsWith(@"0:\")) { if (PMFAT.FolderExists(PMFAT.CurrentDirectory + path)) { ListContents(PMFAT.CurrentDirectory + path); } else { CLI.WriteLine("Could not locate directory \"" + path + "\"", Color.Red); } } else { CLI.WriteLine("Could not locate directory \"" + path + "\"", Color.Red); } } else { CLI.WriteLine("Could not locate directory!", Color.Red); } } else { CLI.WriteLine("Invalid argument! Path expected.", Color.Red); } }
public override void Execute(string line, string[] args) { if (line.Length > 4) { string file = "", realFile = "*ERROR"; if (args[1] == "-d") { if (line.Length > 7) { CPU.DebugVisible = true; file = line.Substring(7, line.Length - 7); realFile = TryParseFile(file, true); } else { CLI.WriteLine("Invalid arguments!", Color.Red); } } else { CPU.DebugVisible = false; file = line.Substring(4, line.Length - 4); realFile = TryParseFile(file, true); } if (realFile != "*ERROR") { if (realFile.ToUpper().EndsWith(".BIN") || realFile.ToUpper().EndsWith(".PRG")) { try { byte[] data = PMFAT.ReadBytes(realFile); Runner.Reset(true); Memory.WriteArray(0, data, data.Length); Runner.Start(); } catch (Exception ex) { CLI.WriteLine("Error occurred attempting to execute \"" + realFile + "\"", Color.Red); CLI.Write("[INTERNAL] ", Color.Red); CLI.WriteLine(ex.Message, Color.White); } } else { CLI.WriteLine("File is not marked as executable", Color.Red); CLI.WriteLine("Expected file extension .BIN or .PRG", Color.White); } } else { CLI.WriteLine("Error occurred attempting to execute \"" + file + "\"", Color.Red); } } }
public override void Execute(string line, string[] args) { if (args.Length == 1) { PMFAT.CurrentDirectory = @"0:\"; } else { if (line.Length > 3) { string path = line.Substring(3, line.Length - 3).ToLower(); if (path.EndsWith('\\')) { path = path.Remove(path.Length - 1, 1); } path += "\\"; if (PMFAT.FolderExists(path)) { if (path.StartsWith(PMFAT.CurrentDirectory)) { PMFAT.CurrentDirectory = path; } else if (path.StartsWith(@"0:\")) { PMFAT.CurrentDirectory = path; } else if (!path.StartsWith(PMFAT.CurrentDirectory) && !path.StartsWith(@"0:\")) { if (PMFAT.FolderExists(PMFAT.CurrentDirectory + path)) { PMFAT.CurrentDirectory = PMFAT.CurrentDirectory + path; } else { CLI.WriteLine("Could not locate directory \"" + path + "\"", Color.Red); } } } else { CLI.WriteLine("Could not locate directory!", Color.Red); } } else { CLI.WriteLine("Invalid argument! Path expected.", Color.Red); } } }
protected override void BeforeRun() { CLI.Initialize(); if (!SVGA.Initialize()) { CLI.WriteLine("[FATAL ERROR] could not initialize graphics mode!", ConsoleColor.Red); } if (!PMFAT.Initialize()) { Console.WriteLine("[FATAL ERROR] could not initialize fat driver!", ConsoleColor.Red); } }
public static void LoadFile(string file) { // format filename if (!file.StartsWith(@"0:\")) { file = @"0:\" + file; } // load file bool error = false; if (PMFAT.FileExists(file)) { try { string[] lines = PMFAT.ReadLines(file); Clear(false); for (int i = 0; i < lines.Length; i++) { Lines.Add(lines[i]); } TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Successfully loaded \"" + file + "\"", Color.Green, Color.Black); error = false; } catch (Exception ex) { error = true; } } else { error = true; } if (error) { TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Unable to load file \"" + file + "\"", Color.Red, Color.Black); } if (!error) { CurrentFile = file; } Kernel.Delay(500); Draw(); ReadInput(); }
public Logon() : base("logon") { this.priority = ProcessPriority.high; this.topMost = true; this.onTaskbar = false; // init control manager ctrlMgr = new ControlManager(); // get login data if (PMFAT.FileExists(@"0:\config.pmc")) { string fileData = PMFAT.ReadText(@"0:\config.pmc"); string[] lines = fileData.Split('\n'); for (int i = 0; i < lines.Length; i++) { string[] data = lines[i].Split(','); if (data[0] == "user") { if (data.Length > 1) { username = data[1]; } } if (data[0] == "pass") { if (data.Length > 1) { password = data[1]; } } } } username = username.Remove(username.Length - 1, 1); // init login window logonWindow = new LogonWindow(); ProcessManager.AddWindow(logonWindow); logonWindow.txtUser.kbReader.output = username; // init invalid dialog invalidDialog.name = "InvalidLogin"; }
// save assembled code to file public static bool AssembleFile(string fileIn, string fileOut) { try { if (PMFAT.FileExists(fileIn)) { // read file Input = DataUtils.StringArrayToList(PMFAT.ReadLines(fileIn)); // store variables, then labels // store labels StoreVariables(); if (!StoreLabels()) { CLI.Write("[ERROR] ", Color.Red); CLI.WriteLine("Problem occured while storing labels."); return(false); } if (!ReplaceLabels()) { CLI.Write("[ERROR] ", Color.Red); CLI.WriteLine("Problem occured while replacing labels with jumps."); return(false); } if (!AssembleCode(fileOut)) { CLI.Write("[ERROR] ", Color.Red); CLI.WriteLine("Problem occured while converting assmebler to bytecode."); return(false); } return(true); } else { CLI.WriteLine("File system error!", Color.Red); CLI.WriteLine("Input: " + fileIn, Color.White); CLI.WriteLine("Output: " + fileOut, Color.White); return(false); } } catch (Exception ex) { CLI.WriteLine("Unknown error has occured while assembling!", Color.Red); CLI.Write("[INTERNAL] ", Color.Red); CLI.WriteLine(ex.Message, Color.White); } return(false); }
public override void Execute(string line, string[] args) { bool success = false; string path = ""; if (line.Length > 6) { path = line.Substring(6, line.Length - 6); if (path.EndsWith('\\')) { path = path.Remove(path.Length - 1, 1); } path += "\\"; if (path.StartsWith(PMFAT.CurrentDirectory)) { PMFAT.CreateFolder(path); success = true; } else if (path.StartsWith(@"0:\")) { PMFAT.CreateFolder(path); success = true; } else if (!path.StartsWith(PMFAT.CurrentDirectory) && !path.StartsWith(@"0:\")) { PMFAT.CreateFolder(PMFAT.CurrentDirectory + path); success = true; } else { CLI.WriteLine("Could not locate directory!", Color.Red); } } else { CLI.WriteLine("Invalid argument! Path expected.", Color.Red); } if (success) { CLI.WriteLine("Successfully created directory \"" + path + "\"", Color.Green); } }
private static void SaveAs() { // draw Draw(); TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "FILENAME: ", Color.White, Color.Black); CLI.SetCursorPos(10, StartY); // get file string file = Console.ReadLine(); // format filename if (!file.StartsWith(@"0:\")) { file = @"0:\" + file; } // save file string document = ""; try { for (int i = 0; i < Lines.Count; i++) { document += Lines[i] + "\n"; } PMFAT.WriteAllText(file, document); TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Successfully saved \"" + file + "\"", Color.Green, Color.Black); } catch (Exception ex) { TextGraphics.DrawLineH(0, StartY, Width, ' ', Color.White, Color.Black); TextGraphics.DrawString(0, StartY, "Unable to save file \"" + file + "\"", Color.Red, Color.Black); } // finish CurrentFile = file; Kernel.Delay(500); Draw(); }
public static void SaveConfig(string file) { string[] lines = new string[6]; // write attributes lines[0] = "back_col," + ((int)(CLI.BackColor)).ToString(); lines[1] = "text_col," + ((int)(CLI.ForeColor)).ToString(); lines[2] = "titlebar_col," + ((int)(Shell.TitleBarColor)).ToString(); lines[3] = "title_col," + ((int)(Shell.TitleColor)).ToString(); lines[4] = "time_col," + ((int)(Shell.DateTimeColor)).ToString(); lines[5] = "titlebar_show," + (Shell.TitleBarVisible ? "1" : "0"); // attempt save try { PMFAT.WriteAllLines(file, lines); } // unexpected error catch (Exception ex) { CLI.WriteLine("Error occured while trying to save system configuration!", Color.Red); CLI.Write("[INTERNAL] ", Color.Red); CLI.WriteLine(ex.Message); } }
private void ListContents(string path) { try { string[] folders = PMFAT.GetFolders(path); string[] files = PMFAT.GetFiles(path); CLI.WriteLine("Showing contents of directory \"" + path + "\""); // draw folders for (int i = 0; i < folders.Length; i++) { CLI.WriteLine(folders[i], Color.Yellow); } // draw files for (int i = 0; i < files.Length; i++) { Cosmos.System.FileSystem.Listing.DirectoryEntry attr = PMFAT.GetFileInfo(path + files[i]); if (attr != null) { CLI.Write(files[i], Color.White); CLI.SetCursorPos(30, CLI.CursorY); CLI.WriteLine(attr.mSize.ToString() + " BYTES", Color.Gray); } else { CLI.WriteLine("Error retrieiving file info", Color.Red); } } CLI.WriteLine(""); CLI.Write("Total folders: " + folders.Length.ToString()); CLI.WriteLine(" Total files: " + files.Length.ToString()); } catch (Exception ex) { } }
private static void ReadInputMenu() { // draw document Draw(); // draw menu TextGraphics.FillRect(0, 1, 20, 5, ' ', Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 1, "New", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 2, "Open...", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 3, "Save", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 4, "Save As...", Color.White, Shell.TitleBarColor); TextGraphics.DrawString(1, 5, "Exit", Color.White, Shell.TitleBarColor); TextGraphics.DrawChar(0, StartY + MenuIndex, '>', Color.Yellow, Shell.TitleBarColor); CLI.SetCursorPos(0, StartY + MenuIndex); try { ConsoleKeyInfo key = CLI.ReadKey(true); // return to document if (key.Key == ConsoleKey.Escape) { Draw(); ReadInput(); } // move up else if (key.Key == ConsoleKey.UpArrow) { if (MenuIndex > 0) { MenuIndex--; } } // move down else if (key.Key == ConsoleKey.DownArrow) { if (MenuIndex < 4) { MenuIndex++; } } // select option else if (key.Key == ConsoleKey.Enter) { // new document if (MenuIndex == 0) { Clear(true); } // load document if (MenuIndex == 1) { Load(); } // save document if (MenuIndex == 2) { if (PMFAT.FileExists(CurrentFile)) { Save(); } else { SaveAs(); } } // save document as if (MenuIndex == 3) { SaveAs(); } // exit if (MenuIndex == 4) { Exit(); } Draw(); ReadInput(); } ReadInputMenu(); } catch (Exception ex) { Clear(false); CLI.Write("[FATAL] ", Color.Red); CLI.WriteLine(ex.Message, Color.White); } }
// load system configuration file public static void LoadConfig(string file, bool clear) { if (!PMFAT.FileExists(file)) { CLI.WriteLine("Could not locate configuration file!", Color.Red); } else { try { string[] lines = PMFAT.ReadLines(file); foreach (string line in lines) { string[] args = line.Split(','); // load config attributes if (args[0] == "back_col") { CLI.BackColor = (Color)int.Parse(args[1]); } if (args[0] == "text_col") { CLI.ForeColor = (Color)int.Parse(args[1]); } if (args[0] == "titlebar_col") { Shell.TitleBarColor = (Color)int.Parse(args[1]); } if (args[0] == "title_col") { Shell.TitleColor = (Color)int.Parse(args[1]); } if (args[0] == "time_col") { Shell.DateTimeColor = (Color)int.Parse(args[1]); } if (args[0] == "titlebar_show") { Shell.TitleBarVisible = DataUtils.IntToBool(int.Parse(args[1])); } } // reset screen if (clear) { Shell.DrawFresh(); } else { Shell.DrawTitleBar(); } } // unexpected error! catch (Exception ex) { CLI.WriteLine("Error loading system configuration file!", Color.Red); CLI.Write("[INTERNAL] ", Color.Red); CLI.WriteLine(ex.Message); } } }
// convert assembly code to bytecode private static bool AssembleCode(string file) { Output.Clear(); // parse lines for (int i = 0; i < LabelOutput.Count; i++) { // get current line LabelOutput[i] = LabelOutput[i].Replace(",", ""); string line = LabelOutput[i]; // get arguments List <string> args = StringArrayToList(line.Split(' ')); // remove blank arguments for (int j = 0; j < args.Count; j++) { args[j] = StringRemoveBlanks(args[j].ToCharArray()); if (IsBlank(args[j])) { args.RemoveAt(j); j--; } } if (LabelOutput[i].Length > 1 && args[0] != "SHORT" && args[0] != "BYTE" && args[0] != "CHAR" && args[0] != "WORD") { for (int j = 0; j < Instructions.List.Count; j++) { // is instruction valid? if (args[0] == Instructions.List[j].Name) { // add instruction Output.Add(Instructions.List[j].OpCode); string format = Instructions.List[j].Format; if (Instructions.List[j].Arguments == 0) { break; } if (format == "b") { byte b = (byte)ParseArgument(args[1]); Output.Add(b); } else if (format == "s") { ushort addr = (ushort)ParseArgument(args[1]); byte left = (byte)((addr & 0xFF00) >> 8); byte right = (byte)(addr & 0x00FF); Output.Add(left); Output.Add(right); } else if (format == "bb") { byte b1 = (byte)(ParseArgument(args[1])); byte b2 = (byte)(ParseArgument(args[2])); Output.Add(b1); Output.Add(b2); } else if (format == "bs") { bool ignore = false; for (int n = 0; n < Variables.Count; n++) { if (args[1] == Variables[n].Name) { ignore = true; break; } else { ignore = false; } } if (!ignore) { byte b = (byte)(ParseArgument(args[1])); ushort addr = (ushort)ParseArgument(args[2]); byte left = (byte)((addr & 0xFF00) >> 8); byte right = (byte)(addr & 0x00FF); Output.Add(b); Output.Add(left); Output.Add(right); } } else if (format == "bbb") { byte b1 = (byte)(ParseArgument(args[1])); byte b2 = (byte)(ParseArgument(args[2])); byte b3 = (byte)(ParseArgument(args[3])); Output.Add(b1); Output.Add(b2); Output.Add(b3); } else { CLI.Write("[ERROR] ", Color.Red); CLI.WriteLine("Invalid arguments at line " + i.ToString()); } break; } } } } // write output CLI.WriteLine("Displaying binary output: ", Color.Gray); int l = CLI.CursorY; for (int j = 0; j < Output.Count; j++) { if (l >= CLI.Height) { Console.ReadLine(); Console.Clear(); l = 0; } CLI.Write(IntToHex(Output[j], "X2"), Color.Magenta); if (CLI.CursorX < 77) { CLI.Write(" "); } else { CLI.WriteLine(""); l++; } } CLI.WriteLine(""); // save file PMFAT.WriteAllBytes(file, Output.ToArray()); return(true); }