feat: new stats embed / api

This commit is contained in:
alyssa 2025-01-05 00:52:45 +00:00
parent e88d6b7e2a
commit 9f8d3d22d2
8 changed files with 215 additions and 100 deletions

View file

@ -57,7 +57,7 @@
</ItemGroup>
<Target Name="SetSourceRevisionId" BeforeTargets="InitializeSourceControlInformation">
<Exec Command="git rev-parse HEAD &gt; ../.version" IgnoreExitCode="False">
<Exec Command="git rev-parse HEAD &gt; ../.version &amp; git show --no-patch --format=%at $(git rev-parse HEAD) &gt;&gt; ../.version &amp; (git diff-index --quiet HEAD -- &amp;&amp; echo 1) &gt;&gt; ../.version" IgnoreExitCode="True">
</Exec>
</Target>

View file

@ -4,20 +4,21 @@ public static class BuildInfoService
{
public static string Version { get; private set; }
public static string FullVersion { get; private set; }
public static string Timestamp { get; private set; }
public static bool IsDev { get; private set; }
public static async Task LoadVersion()
{
using (var stream = typeof(BuildInfoService).Assembly.GetManifestResourceStream("version"))
{
// if this happens, something broke
if (stream == null) FullVersion = "(unknown version) ";
else
using (var reader = new StreamReader(stream))
FullVersion = await reader.ReadToEndAsync();
}
using var stream = typeof(BuildInfoService).Assembly.GetManifestResourceStream("version");
if (stream == null) throw new Exception("missing version information");
// cheap hack to remove newline
FullVersion = FullVersion.Remove(FullVersion.Length - 1);
using var reader = new StreamReader(stream);
var data = (await reader.ReadToEndAsync()).Split("\n");
FullVersion = data[0];
Timestamp = data[1];
IsDev = data[2] == "";
// show only short commit hash to users
Version = FullVersion.Remove(7);