Skip to content

Commit

Permalink
generate build timestamp at compile time for about box (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmriggs authored Sep 3, 2023
1 parent 3fcb327 commit 37031dd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ACViewer/ACViewer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,8 @@
exit 0
</PostBuildEvent>
</PropertyGroup>

<PropertyGroup>
<SourceRevisionId>build$([System.DateTime]::UtcNow.ToString("yyyyMMddHHmmss"))</SourceRevisionId>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion ACViewer/View/About.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Title="About" Height="170" Width="280" ResizeMode="NoResize" Icon="../Icons/Question_16x.png">
<Grid>
<TextBlock HorizontalAlignment="Left" Margin="7.5,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top">
<Run FontWeight="Bold">ACViewer - build 2022.02.18</Run><LineBreak /><LineBreak />
<Run FontWeight="Bold" Text="{Binding RunText, Mode=OneWay}"></Run><LineBreak /><LineBreak />
Much thanks: the emulator teams, Pea, parad0x, OptimShi, and the AC community!<LineBreak />
</TextBlock>
<Button Content="OK" HorizontalAlignment="Center" Margin="0,100,0,0" VerticalAlignment="Top" Width="75" Click="OK_Click" IsCancel="true"/>
Expand Down
30 changes: 29 additions & 1 deletion ACViewer/View/About.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Windows;
using System;
using System.Globalization;
using System.Reflection;
using System.Windows;

namespace ACViewer.View
{
Expand All @@ -7,14 +10,39 @@ namespace ACViewer.View
/// </summary>
public partial class About : Window
{
public string RunText => "ACViewer - build " + GetBuildDate(Assembly.GetExecutingAssembly()).ToString("yyyy.MM.dd");

public About()
{
InitializeComponent();
DataContext = this;
}

private void OK_Click(object sender, RoutedEventArgs e)
{
Close();
}

// https://www.meziantou.net/getting-the-date-of-build-of-a-dotnet-assembly-at-runtime.htm
private static DateTime GetBuildDate(Assembly assembly)
{
const string BuildVersionMetadataPrefix = "+build";

var attribute = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (attribute?.InformationalVersion != null)
{
var value = attribute.InformationalVersion;
var index = value.IndexOf(BuildVersionMetadataPrefix);
if (index > 0)
{
value = value.Substring(index + BuildVersionMetadataPrefix.Length);
if (DateTime.TryParseExact(value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var result))
{
return result;
}
}
}
return default;
}
}
}

0 comments on commit 37031dd

Please sign in to comment.