diff --git a/DATFromDir/DATFromDir.cs b/DATFromDir/DATFromDir.cs index 255a8e16..90cb386e 100644 --- a/DATFromDir/DATFromDir.cs +++ b/DATFromDir/DATFromDir.cs @@ -55,7 +55,6 @@ namespace SabreTools public static void Main(string[] args) { Console.Clear(); - Console.Title = "DATFromDir " + Build.Version; // Credits take precidence over all if ((new List(args)).Contains("--credits")) @@ -150,6 +149,9 @@ namespace SabreTools return; } + // Output the title + Build.Start("DATFromDir"); + // If any of the inputs are not valid, show the help foreach (string input in inputs) { diff --git a/DATabase/DATabase.cs b/DATabase/DATabase.cs index b39a15b8..5686df98 100644 --- a/DATabase/DATabase.cs +++ b/DATabase/DATabase.cs @@ -35,10 +35,7 @@ namespace SabreTools logger.Start(); DBTools.EnsureDatabase(_dbName, _connectionString); Remapping.CreateRemappings(); - Console.Clear(); - Console.SetBufferSize(Console.BufferWidth, 999); - Console.Title = "DATabase " + Build.Version; // Credits take precidence over all if ((new List(args)).Contains("--credits")) @@ -199,20 +196,6 @@ namespace SabreTools return; } - /// - /// Print the program header - /// - private static void PrintHeader() - { - ConsoleColor formertext = Console.ForegroundColor; - ConsoleColor formerback = Console.BackgroundColor; - Console.ForegroundColor = ConsoleColor.Yellow; - Console.BackgroundColor = ConsoleColor.Blue; - Console.WriteLine(_header); - Console.ForegroundColor = formertext; - Console.BackgroundColor = formerback; - } - /// /// Show the text-based main menu /// @@ -223,7 +206,7 @@ namespace SabreTools while (selection.ToLowerInvariant() != "x") { Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); Console.WriteLine(@"MAIN MENU =========================== Make a selection: @@ -266,14 +249,14 @@ Make a selection: break; case "7": Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); ListSources(); Console.Write("\nPress any key to continue..."); Console.ReadKey(); break; case "8": Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); ListSystems(); Console.Write("\nPress any key to continue..."); Console.ReadKey(); @@ -305,7 +288,7 @@ Make a selection: while (selection.ToLowerInvariant() != "b") { Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); Console.WriteLine( @"IMPORT MENU =========================== Enter the name of a DAT file or folder containing DAT files @@ -366,7 +349,7 @@ or 'b' to go back to the previous menu:"); while (selection.ToLowerInvariant() != "b") { Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); Console.WriteLine(@"GENERATE MENU =========================== Make a selection: @@ -441,7 +424,7 @@ Make a selection: while (selection.ToLowerInvariant() != "b") { Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); Console.WriteLine(@"GENERATE ALL MENU =========================== Make a selection: @@ -603,7 +586,7 @@ Make a selection: while (selection.ToLowerInvariant() != "b") { Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); Console.WriteLine(@"XML -> RV CONVERT MENU =========================== Enter the name of a DAT file to convert from XML to RV @@ -663,7 +646,7 @@ or 'b' to go back to the previous menu: while (selection.ToLowerInvariant() != "b") { Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); Console.WriteLine(@"RV -> XML CONVERT MENU =========================== Enter the name of a DAT file to convert from RV to XML @@ -786,7 +769,7 @@ ORDER BY systems.manufacturer, systems.system"; while (selection.ToLowerInvariant() != "b") { Console.Clear(); - PrintHeader(); + Build.Start("DATabase"); Console.WriteLine(@"ADD AND REMOVE MENU =========================== Make a selection: diff --git a/DatSplit/DatSplit.cs b/DatSplit/DatSplit.cs index dd3e169b..d267a3d6 100644 --- a/DatSplit/DatSplit.cs +++ b/DatSplit/DatSplit.cs @@ -16,7 +16,7 @@ namespace DatSplit public static void Main(string[] args) { - Console.Title = "DatSplit " + Build.Version; + Console.Clear(); // Credits take precidence over all if ((new List(args)).Contains("--credits")) @@ -32,6 +32,9 @@ namespace DatSplit return; } + // Output the title + Build.Start("DatSplit"); + // Set needed strings _filename = args[0]; _extA = (args[1].StartsWith(".") ? args[1] : "." + args[1]).ToUpperInvariant(); diff --git a/Deheader/Headerer.cs b/Deheader/Headerer.cs index dc189acc..2d57cad8 100644 --- a/Deheader/Headerer.cs +++ b/Deheader/Headerer.cs @@ -26,13 +26,12 @@ namespace SabreTools static void Main(string[] args) { // Perform initial setup and verification + Console.Clear(); logger = new Logger(false, "database.log"); logger.Start(); DBTools.EnsureDatabase(_dbName, _connectionString); Remapping.CreateHeaderSkips(); - Console.Title = "Headerer " + Build.Version; - // Credits take precidence over all if ((new List(args)).Contains("--credits")) { @@ -47,6 +46,9 @@ namespace SabreTools return; } + // Output the title + Build.Start("Headerer"); + // Get the filename (or foldername) string file = ""; bool deheader = true; diff --git a/SabreHelper/Build.cs b/SabreHelper/Build.cs index c0b17519..b0f637f7 100644 --- a/SabreHelper/Build.cs +++ b/SabreHelper/Build.cs @@ -23,6 +23,37 @@ namespace SabreTools.Helper get { return (Type.GetType("Mono.Runtime") != null); } } + /// + /// Readies the console and outputs the header + /// + /// The name to be displayed as the program + /// Adapted from http://stackoverflow.com/questions/8200661/how-to-align-string-in-fixed-length-string + public static void Start(string name) + { + // Dynamically create the header string + string border = "+-----------------------------------------------------------------------------+"; + string mid = name + " " + Build.Version; + mid = "|" + mid.PadLeft(((77 - mid.Length) / 2) + mid.Length).PadRight(77) + "|"; + + // Set the console to ready state + Console.SetBufferSize(Console.BufferWidth, 999); + Console.Title = name + " " + Build.Version; + ConsoleColor formertext = Console.ForegroundColor; + ConsoleColor formerback = Console.BackgroundColor; + Console.ForegroundColor = ConsoleColor.Yellow; + Console.BackgroundColor = ConsoleColor.Blue; + + // Output the header + Console.WriteLine(border); + Console.WriteLine(mid); + Console.WriteLine(border); + Console.WriteLine(); + + // Return the console to the original text and background colors + Console.ForegroundColor = formertext; + Console.BackgroundColor = formerback; + } + /// /// Show the help dialog for a given class /// diff --git a/SingleGame/SingleGame.cs b/SingleGame/SingleGame.cs index b0099c3e..61ca03eb 100644 --- a/SingleGame/SingleGame.cs +++ b/SingleGame/SingleGame.cs @@ -15,7 +15,7 @@ namespace SabreTools public static void Main(string[] args) { - Console.Title = "SingleGame " + Build.Version; + Console.Clear(); // Credits take precidence over all if ((new List(args)).Contains("--credits")) @@ -30,6 +30,9 @@ namespace SabreTools return; } + // Output the title + Build.Start("SingleGame"); + _filename = args[0]; if (args.Length > 1)