Skip to content

Commit

Permalink
print build time and date
Browse files Browse the repository at this point in the history
  • Loading branch information
Modulus32 committed Apr 28, 2024
1 parent 4272db0 commit 50ace23
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion TagTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static void Main(string[] args)

if (autoexecCommand == null)
{
Console.WriteLine($"TagTool [{Assembly.GetExecutingAssembly().GetName().Version}]");
Console.WriteLine($"TagTool [{Assembly.GetExecutingAssembly().GetName().Version} (Built {GetLinkerTimestampUtc(Assembly.GetExecutingAssembly())} UTC)]");
Console.WriteLine();
Console.WriteLine("Please report any bugs and/or feature requests:");
Console.WriteLine("https://github.com/TheGuardians-CI/TagTool/issues");
Expand Down Expand Up @@ -212,5 +212,28 @@ public static void ReportElapsed()
WarningCount = 0;
_stopWatch.Reset();
}

public static DateTime GetLinkerTimestampUtc(Assembly assembly)
{
var location = assembly.Location;
return GetLinkerTimestampUtc(location);
}

public static DateTime GetLinkerTimestampUtc(string filePath)
{
const int peHeaderOffset = 60;
const int linkerTimestampOffset = 8;
var bytes = new byte[2048];

using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
file.Read(bytes, 0, bytes.Length);
}

var headerPos = BitConverter.ToInt32(bytes, peHeaderOffset);
var secondsSince1970 = BitConverter.ToInt32(bytes, headerPos + linkerTimestampOffset);
var dt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
return dt.AddSeconds(secondsSince1970);
}
}
}

0 comments on commit 50ace23

Please sign in to comment.