Files
SabreTools/SabreTools.Helper/Data/Build.cs

127 lines
3.5 KiB
C#
Raw Normal View History

using System;
2016-08-29 17:47:25 -07:00
using System.Collections.Generic;
namespace SabreTools.Helper.Data
{
public static class Build
{
2016-04-12 16:23:17 -07:00
/// <summary>
/// Returns true if running in a Mono environment
/// </summary>
public static bool MonoEnvironment
{
2016-04-12 16:33:15 -07:00
get { return (Type.GetType("Mono.Runtime") != null); }
2016-04-12 16:24:38 -07:00
}
2016-04-18 20:04:38 -07:00
/// <summary>
/// Readies the console and outputs the header
/// </summary>
2017-02-01 00:32:01 -08:00
/// <param name="name">The name to be displayed as the program</param>B
2016-04-18 20:04:38 -07:00
public static void Start(string name)
{
// Dynamically create the header string, adapted from http://stackoverflow.com/questions/8200661/how-to-align-string-in-fixed-length-string
2016-08-28 21:04:00 -07:00
int width = Console.WindowWidth - 3;
string border = "+" + new string('-', width) + "+";
2016-05-22 13:15:13 -07:00
string mid = name + " " + Constants.Version;
2016-08-28 21:04:00 -07:00
mid = "|" + mid.PadLeft(((width - mid.Length) / 2) + mid.Length).PadRight(width) + "|";
2016-04-18 20:04:38 -07:00
// If we're outputting to console, do fancy things
if (!Console.IsOutputRedirected)
2016-04-20 11:50:03 -07:00
{
// Set the console to ready state
ConsoleColor formertext = ConsoleColor.White;
ConsoleColor formerback = ConsoleColor.Black;
if (!MonoEnvironment)
{
Console.SetBufferSize(Console.BufferWidth, 999);
formertext = Console.ForegroundColor;
formerback = Console.BackgroundColor;
Console.ForegroundColor = ConsoleColor.Yellow;
Console.BackgroundColor = ConsoleColor.Blue;
}
2016-04-20 11:50:03 -07:00
2016-10-25 16:47:50 -07:00
Console.Title = name + " " + Constants.Version;
2016-04-18 20:04:38 -07:00
// Output the header
Console.WriteLine(border);
Console.WriteLine(mid);
Console.WriteLine(border);
Console.WriteLine();
2016-04-18 20:04:38 -07:00
// Return the console to the original text and background colors
if (!MonoEnvironment)
{
Console.ForegroundColor = formertext;
Console.BackgroundColor = formerback;
}
2016-04-20 11:50:03 -07:00
}
2016-04-18 20:04:38 -07:00
}
/// <summary>
/// Show the help dialog for a given class
/// </summary>
/// <param name="className">Name of the class to get help for, "Credits" for developer credits</param>
2017-01-31 22:55:31 -08:00
public static void Help(string className, string subset = null)
{
//http://stackoverflow.com/questions/14849367/how-to-determine-calling-method-and-class-name
2016-08-29 17:47:25 -07:00
string barrier = "-----------------------------------------";
List<string> helptext = new List<string>();
2017-01-31 22:55:31 -08:00
// Normalize the subset text
if (subset != null)
{
subset = subset.ToLowerInvariant().TrimStart('-');
}
2016-08-29 17:47:25 -07:00
// Set the help text
switch (className)
{
case "Credits":
helptext.Add(barrier);
helptext.Add("Credits");
helptext.Add(barrier);
helptext.Add("");
helptext.Add("Programmer / Lead: Matt Nadareski (darksabre76)");
helptext.Add("Additional code: emuLOAD, @tractivo, motoschifo");
helptext.Add("Testing: emuLOAD, @tractivo, Kludge, Obiwantje, edc");
helptext.Add("Suggestions: edc, AcidX, Amiga12, EliUmniCk");
helptext.Add("Based on work by: The Wizard of DATz");
break;
default:
2016-08-29 17:47:25 -07:00
helptext.Add(Resources.Resources.Default_Desc);
break;
}
2016-08-29 17:47:25 -07:00
// Now output based on the size of the screen
int i = 0;
foreach (string help in helptext)
{
Console.WriteLine(help);
i++;
// If we're not being redirected and we reached the size of the screen, pause
2017-02-01 11:13:43 -08:00
if (i == Console.WindowHeight - 3)
2016-08-29 17:47:25 -07:00
{
i = 0;
2016-09-12 16:14:23 -07:00
Pause();
2016-08-29 17:47:25 -07:00
}
}
2016-09-12 16:14:23 -07:00
Pause();
}
/// <summary>
/// Pause on console output
/// </summary>
2016-09-12 16:14:23 -07:00
private static void Pause()
{
2016-09-12 16:12:29 -07:00
if (!Console.IsOutputRedirected)
{
2017-02-01 00:32:01 -08:00
Console.WriteLine();
2016-09-12 16:12:29 -07:00
Console.WriteLine("Press enter to continue...");
Console.ReadLine();
}
}
}
}