Skip to content

Commit

Permalink
No need to display timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKert committed Apr 27, 2019
1 parent f78baaf commit 3962260
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 39 deletions.
37 changes: 2 additions & 35 deletions src/BuildVision.Common/AppVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,22 @@
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;

namespace BuildVision.Common
{
public class AppVersionInfo
{
public string AppVersion { get; set; }
public string BuildVersion { get; set; }
public DateTime BuildDateTime { get; set; }

public AppVersionInfo()
{
var assembly = Assembly.GetExecutingAssembly();
var versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);

AppVersion = new Version(versionInfo.ProductVersion).ToString();
AppVersion = versionInfo.ProductVersion.ToString();
BuildVersion = new Version(versionInfo.FileVersion).ToString();
BuildDateTime = RetrieveLinkerTimestamp(assembly);
}

/// <summary>
/// Get last build datetime.
/// </summary>
private static DateTime RetrieveLinkerTimestamp(Assembly assembly)
{
var filePath = assembly.Location;
const int PeHeaderOffset = 60;
const int LinkerTimestampOffset = 8;
var buffer = new byte[2048];
Stream stream = null;

try
{
stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
stream.Read(buffer, 0, 2048);
}
finally
{
if (stream != null)
{
stream.Close();
}
}

var i = BitConverter.ToInt32(buffer, PeHeaderOffset);
var secondsSince1970 = BitConverter.ToInt32(buffer, i + LinkerTimestampOffset);
var dt = new DateTime(1970, 1, 1, 0, 0, 0);
dt = dt.AddSeconds(secondsSince1970);
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
return dt;
}
}
}
5 changes: 3 additions & 2 deletions src/BuildVision.Common/ApplicationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public static FileVersionInfo GetHostVersionInfo()
return Process.GetCurrentProcess().MainModule.FileVersionInfo;
}

public static Version GetPackageVersion(object package)
public static string GetPackageVersion(object package)
{
return package.GetType().Assembly.GetName().Version;
var versionInfo = FileVersionInfo.GetVersionInfo(package.GetType().Assembly.Location);
return versionInfo.ProductVersion;
}
}
}
2 changes: 0 additions & 2 deletions src/BuildVision.UI/Settings/GeneralSettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@
<Run Text="{Binding AppVersion, StringFormat={}{0};}"/>
<Run Text="Build"/>
<Run Text="{Binding BuildVersion}"/>
<Run Text="on"/>
<Run Text="{Binding BuildDateTime, StringFormat=F}"/>
<LineBreak/>
<Run Text="© 2019 by Stefan Kert"/>
<Hyperlink NavigateUri="https://twitter.com/StefanKert"
Expand Down

0 comments on commit 3962260

Please sign in to comment.