Combine Prepare into Globals, fix build

This commit is contained in:
Matt Nadareski
2024-03-13 00:09:20 -04:00
parent eb05df7b5e
commit 7ffa73669b
7 changed files with 44 additions and 54 deletions

View File

@@ -27,7 +27,7 @@ namespace RombaSharp.Features
if (!base.ProcessFeatures(features))
return false;
logger.User($"RombaSharp version: {Prepare.Version}");
logger.User($"RombaSharp version: {Globals.Version}");
return true;
}
}

View File

@@ -104,7 +104,7 @@ namespace RombaSharp
if (!Console.IsOutputRedirected && feature.ScriptMode)
{
Console.Clear();
Prepare.SetConsoleHeader("SabreTools");
Globals.SetConsoleHeader("SabreTools");
}
// Now process the current feature

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace SabreTools.Core
{
/// <summary>
/// Globally-accessible objects for the library
/// Globally-accessible functionality
/// </summary>
public class Globals
{
@@ -30,5 +30,42 @@ namespace SabreTools.Core
MaxDegreeOfParallelism = MaxThreads
};
#endif
/// <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
}
}
}

View File

@@ -1,47 +0,0 @@
using System;
namespace SabreTools.Core
{
/// <summary>
/// Generic console preparation for program output
/// </summary>
public static class Prepare
{
/// <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
}
}
}

View File

@@ -131,10 +131,10 @@ namespace SabreTools.Features
Header.SetFieldValue<string?>(Models.Metadata.Header.CategoryKey, "DiffDAT");
if (string.IsNullOrWhiteSpace(Header.GetStringFieldValue(Models.Metadata.Header.AuthorKey)))
Header.SetFieldValue<string?>(Models.Metadata.Header.AuthorKey, $"SabreTools {Prepare.Version}");
Header.SetFieldValue<string?>(Models.Metadata.Header.AuthorKey, $"SabreTools {Globals.Version}");
if (string.IsNullOrWhiteSpace(Header.GetStringFieldValue(Models.Metadata.Header.CommentKey)))
Header.SetFieldValue<string?>(Models.Metadata.Header.CommentKey, $"Generated by SabreTools {Prepare.Version}");
Header.SetFieldValue<string?>(Models.Metadata.Header.CommentKey, $"Generated by SabreTools {Globals.Version}");
}
// If no update fields are set, default to Names

View File

@@ -27,7 +27,7 @@ namespace SabreTools.Features
if (!base.ProcessFeatures(features))
return false;
logger.User($"SabreTools version: {Prepare.Version}");
logger.User($"SabreTools version: {Globals.Version}");
return true;
}
}

View File

@@ -104,7 +104,7 @@ namespace SabreTools
if (!Console.IsOutputRedirected && feature.ScriptMode)
{
Console.Clear();
Prepare.SetConsoleHeader("SabreTools");
Globals.SetConsoleHeader("SabreTools");
}
// Now process the current feature