From 043509b6b0235b70291483549e24a4077c0fdc07 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Sun, 11 Apr 2021 18:50:58 +0200 Subject: [PATCH] feat: add Util.GetGitHash() --- Dalamud/Util.cs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Dalamud/Util.cs b/Dalamud/Util.cs index 14f96080b..9df4e5a53 100644 --- a/Dalamud/Util.cs +++ b/Dalamud/Util.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; @@ -13,11 +14,31 @@ namespace Dalamud /// public static class Util { + private static string gitHashInternal; + /// /// Gets the assembly version of Dalamud. /// public static string AssemblyVersion { get; } = Assembly.GetAssembly(typeof(ChatHandlers)).GetName().Version.ToString(); + /// + /// Gets the git hash value from the assembly + /// or null if it cannot be found. + /// + /// The git hash of the assembly. + public static string GetGitHash() + { + if (gitHashInternal != null) + return gitHashInternal; + + var asm = typeof(Util).Assembly; + var attrs = asm.GetCustomAttributes(); + + gitHashInternal = attrs.FirstOrDefault(a => a.Key == "GitHash")?.Value; + + return gitHashInternal; + } + /// /// Read memory from an offset and hexdump them via Serilog. ///