From 9f124ee3c967b3c19859d3fc552ca74046d085da Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 20:29:57 +0100 Subject: [PATCH] [Backport] #245 to rel/2.2.x (#246) * Try another resolution * Fix it again * Optimize a little --------- Co-authored-by: Sella-GH <147769367+Sella-GH@users.noreply.github.com> --- src/AzzyBot.Core/Utilities/SoftwareStats.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/AzzyBot.Core/Utilities/SoftwareStats.cs b/src/AzzyBot.Core/Utilities/SoftwareStats.cs index 8a1bf41f..e00364ea 100644 --- a/src/AzzyBot.Core/Utilities/SoftwareStats.cs +++ b/src/AzzyBot.Core/Utilities/SoftwareStats.cs @@ -7,8 +7,10 @@ namespace AzzyBot.Core.Utilities; public static class SoftwareStats { + private static readonly string AppFilePath = $"{Path.Combine(AppContext.BaseDirectory, AppDomain.CurrentDomain.FriendlyName)}.dll"; + public static string GetAppAuthors - => FileVersionInfo.GetVersionInfo(GetAppFilePath()).CompanyName ?? "Bot authors not found"; + => FileVersionInfo.GetVersionInfo(AppFilePath).CompanyName ?? "Bot authors not found"; public static string GetAppDotNetVersion => Environment.Version.ToString() ?? ".NET version not found"; @@ -17,10 +19,10 @@ public static string GetAppEnvironment => (GetAppName.EndsWith("Dev", StringComparison.OrdinalIgnoreCase)) ? Environments.Development : Environments.Production; public static string GetAppName - => FileVersionInfo.GetVersionInfo(GetAppFilePath()).ProductName?.Split('.')[0] ?? "Bot name not found"; + => FileVersionInfo.GetVersionInfo(AppFilePath).ProductName?.Split('.')[0] ?? "Bot name not found"; public static string GetAppVersion - => FileVersionInfo.GetVersionInfo(GetAppFilePath()).ProductVersion ?? "Bot version not found"; + => FileVersionInfo.GetVersionInfo(AppFilePath).ProductVersion ?? "Bot version not found"; public static double GetAppMemoryUsage() { @@ -35,15 +37,4 @@ public static DateTimeOffset GetAppUptime() return app.StartTime; } - - private static string GetAppFilePath() - { - string fileName = Path.Combine(AppContext.BaseDirectory, AppDomain.CurrentDomain.FriendlyName); - if (!HardwareStats.CheckIfLinuxOs) - fileName += ".exe"; - - return (!string.IsNullOrEmpty(fileName)) - ? Path.Combine(AppContext.BaseDirectory, fileName) - : throw new InvalidOperationException("Bot file path not found"); - } }