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 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"; }
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(); }
// 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); }
// 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); } } }
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); } }