From e997b9769f82c7e95b279ca23c3febf08f5d0f31 Mon Sep 17 00:00:00 2001 From: Lewis Kirkaldie Date: Wed, 24 Aug 2022 15:34:37 +0100 Subject: [PATCH] -automate name/ver/builddate to console --- Helpers/Product.cs | 57 ++++++++++++++++++++++++++++++++++++++++++++++ Program.cs | 6 ++--- 2 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 Helpers/Product.cs diff --git a/Helpers/Product.cs b/Helpers/Product.cs new file mode 100644 index 0000000..05c8a97 --- /dev/null +++ b/Helpers/Product.cs @@ -0,0 +1,57 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Reflection; +using static System.Char; + +namespace StreamGoo.Helpers; + +public static class Product +{ + private static string _tracingName; + + #region Constructors + + static Product() + { + var assembly = Assembly.GetExecutingAssembly(); + + var appFile = Path.Combine(AppContext.BaseDirectory, "streamgoo"); + + if (File.Exists(appFile)) + { + var versionInfo = FileVersionInfo.GetVersionInfo(appFile); + + Version = versionInfo.FileVersion; + BuildTime = File.GetCreationTime(appFile); + } + else if (File.Exists($"{appFile}.exe")) + { + var versionInfo = FileVersionInfo.GetVersionInfo($"{appFile}.exe"); + + Version = versionInfo.FileVersion; + BuildTime = File.GetCreationTime(appFile); + } + + Name = "StreamGoo"; + } + + #endregion + + #region Static members + + public static string Name { get; } + + public static string TracingName + { + get + { + return _tracingName ??= string.Concat(Name.Where(c => !IsWhiteSpace(c))).ToLowerInvariant(); + } + } + public static string Version { get; } = "0.0"; + public static DateTime BuildTime { get; } = DateTime.MinValue; + + #endregion +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index cee4c7e..d3800cf 100644 --- a/Program.cs +++ b/Program.cs @@ -20,6 +20,7 @@ limitations under the License. using System.Net.Sockets; using System.Threading; using CommandLine; +using StreamGoo.Helpers; namespace StreamGoo { @@ -76,9 +77,8 @@ private static int Run(Options opts) _options = opts; _suppressOutput = _options.Quiet; - PrintToConsole("Cinegy StreamGoo TS Testing Tool"); - PrintToConsole( - $"Corrupting your Transport Streams since 2015 (v1.0.0 - {File.GetCreationTime(AppContext.BaseDirectory)})\n"); + PrintToConsole($"{Product.Name}: {Product.Version} (Built: {Product.BuildTime})"); + PrintToConsole($"Corrupting your Transport Streams since 2015...\n"); _gooDurationTicks = new TimeSpan(0, 0, 0, 0, _options.GooDuration).Ticks; _gooType = _options.GooType > -1 ? _options.GooType : Random.Next(0, 5);