From c618b6cbb4ea1585f7401c1e050e18a968d5f99d Mon Sep 17 00:00:00 2001 From: Pieter Viljoen Date: Wed, 21 Jun 2023 15:45:11 -0700 Subject: [PATCH] Version line only --- PlexCleaner/Program.cs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/PlexCleaner/Program.cs b/PlexCleaner/Program.cs index 21e7848a..107b7f62 100644 --- a/PlexCleaner/Program.cs +++ b/PlexCleaner/Program.cs @@ -73,13 +73,29 @@ private static int Main() return exitCode; } + public static string GetVersion(bool versionOnly) + { + var assembly = Assembly.GetEntryAssembly(); + assembly ??= Assembly.GetExecutingAssembly(); + + var versionAttribute = assembly.GetCustomAttribute(); + + string version = versionAttribute?.InformationalVersion; + version ??= assembly.GetName()?.Version?.ToString(); + version ??= "?"; + + string name = assembly.GetName()?.Name; + name ??= "?"; + + return versionOnly ? version : $"{name} : {version}"; + } + private static bool ShowVersionInformation() { // Use the raw commandline and look for --version if (Environment.CommandLine.Contains("--version")) { - string appVersion = Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion; - Console.WriteLine(appVersion); + Console.WriteLine(GetVersion(false)); return true; } return false; @@ -496,9 +512,7 @@ private static Program Create(CommandLineOptions options, bool verifyTools) #else const bool debugBuild = false; #endif - string appVersion = Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion; - string runtimeVersion = Environment.Version.ToString(); - Log.Logger.Information("Application Version : {AppVersion}, Runtime Version : {RuntimeVersion}, Debug Build: {DebugBuild}", appVersion, runtimeVersion, debugBuild); + Log.Logger.Information("Application Version : {AppVersion}, Runtime Version : {RuntimeVersion}, Debug Build: {DebugBuild}", GetVersion(true), Environment.Version.ToString(), debugBuild); // Parallel processing config if (Options.Parallel)