2017-03-30 23:39:38 -07:00
|
|
|
|
using System;
|
2024-03-13 00:06:17 -04:00
|
|
|
|
using System.Reflection;
|
2024-03-05 03:04:47 -05:00
|
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
2017-03-29 12:49:34 -07:00
|
|
|
|
using System.Threading.Tasks;
|
2024-03-05 03:04:47 -05:00
|
|
|
|
#endif
|
2017-03-29 12:49:34 -07:00
|
|
|
|
|
2020-12-08 13:23:59 -08:00
|
|
|
|
namespace SabreTools.Core
|
2017-03-01 21:26:27 -08:00
|
|
|
|
{
|
2019-02-08 20:32:49 -08:00
|
|
|
|
/// <summary>
|
2024-03-13 00:09:20 -04:00
|
|
|
|
/// Globally-accessible functionality
|
2019-02-08 20:32:49 -08:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Globals
|
|
|
|
|
|
{
|
2024-03-13 00:06:17 -04:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// The current toolset version to be used by all child applications
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public readonly static string? Version = Assembly.GetExecutingAssembly().GetName().Version?.ToString();
|
2017-03-01 21:26:27 -08:00
|
|
|
|
|
2024-10-24 06:00:31 -04:00
|
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
2020-08-02 13:08:33 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Maximum threads to use during parallel operations
|
|
|
|
|
|
/// </summary>
|
2020-07-19 21:59:34 -07:00
|
|
|
|
public static int MaxThreads { get; set; } = Environment.ProcessorCount;
|
2020-04-03 13:19:21 -07:00
|
|
|
|
|
2020-08-02 13:08:33 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ParallelOptions object for use in parallel operations
|
|
|
|
|
|
/// </summary>
|
2023-04-19 16:39:58 -04:00
|
|
|
|
public static ParallelOptions ParallelOptions => new()
|
2019-02-08 20:32:49 -08:00
|
|
|
|
{
|
2020-07-19 21:59:34 -07:00
|
|
|
|
MaxDegreeOfParallelism = MaxThreads
|
|
|
|
|
|
};
|
2024-02-28 19:49:09 -05:00
|
|
|
|
#endif
|
2024-03-13 00:09:20 -04:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Readies the console and outputs the header
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="program">The name to be displayed as the program</param>
|
|
|
|
|
|
public static void SetConsoleHeader(string program)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Dynamically create the header string, adapted from http://stackoverflow.com/questions/8200661/how-to-align-string-in-fixed-length-string
|
|
|
|
|
|
int width = Console.WindowWidth - 3;
|
|
|
|
|
|
string border = $"+{new string('-', width)}+";
|
|
|
|
|
|
string mid = $"{program} {Globals.Version}";
|
|
|
|
|
|
mid = $"|{mid.PadLeft(((width - mid.Length) / 2) + mid.Length).PadRight(width)}|";
|
|
|
|
|
|
|
|
|
|
|
|
// If we're outputting to console, do fancy things
|
|
|
|
|
|
#if NET452_OR_GREATER || NETCOREAPP
|
|
|
|
|
|
if (!Console.IsOutputRedirected)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Set the console to ready state
|
|
|
|
|
|
ConsoleColor formertext = Console.ForegroundColor;
|
|
|
|
|
|
ConsoleColor formerback = Console.BackgroundColor;
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Blue;
|
|
|
|
|
|
|
|
|
|
|
|
Console.Title = $"{program} {Globals.Version}";
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|
2019-02-08 20:32:49 -08:00
|
|
|
|
}
|
2017-03-01 21:26:27 -08:00
|
|
|
|
}
|