Skip to content

Commit

Permalink
[Backport] #245 to rel/2.2.x (#246)
Browse files Browse the repository at this point in the history
* Try another resolution

* Fix it again

* Optimize a little

---------

Co-authored-by: Sella-GH <147769367+Sella-GH@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and Sella-GH authored Dec 23, 2024
1 parent 4ae4dd0 commit 9f124ee
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/AzzyBot.Core/Utilities/SoftwareStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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()
{
Expand All @@ -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");
}
}

0 comments on commit 9f124ee

Please sign in to comment.