mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[Style] Add Date to build title
This commit is contained in:
@@ -40,7 +40,7 @@ namespace SabreTools.Helper.Data
|
||||
Console.BackgroundColor = ConsoleColor.Blue;
|
||||
}
|
||||
|
||||
Console.Title = "SabreTools-" + name + " " + Constants.Version;
|
||||
Console.Title = name + " " + Constants.Version;
|
||||
|
||||
// Output the header
|
||||
Console.WriteLine(border);
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using SabreTools.Helper.Tools;
|
||||
|
||||
namespace SabreTools.Helper.Data
|
||||
{
|
||||
@@ -7,7 +10,7 @@ namespace SabreTools.Helper.Data
|
||||
/// <summary>
|
||||
/// The current toolset version to be used by all child applications
|
||||
/// </summary>
|
||||
public const string Version = "v0.9.3";
|
||||
public static string Version = "v0.9.3-" + Assembly.GetExecutingAssembly().GetLinkerTime().ToString("yyyy-MM-dd HH:mm:ss");
|
||||
public const int HeaderHeight = 3;
|
||||
|
||||
#region 0-byte file constants
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web;
|
||||
@@ -575,6 +576,32 @@ namespace SabreTools.Helper.Tools
|
||||
return Encoding.Default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// http://stackoverflow.com/questions/1600962/displaying-the-build-date
|
||||
/// </summary>
|
||||
public static DateTime GetLinkerTime(this Assembly assembly, TimeZoneInfo target = null)
|
||||
{
|
||||
var filePath = assembly.Location;
|
||||
const int c_PeHeaderOffset = 60;
|
||||
const int c_LinkerTimestampOffset = 8;
|
||||
|
||||
var buffer = new byte[2048];
|
||||
|
||||
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
|
||||
stream.Read(buffer, 0, 2048);
|
||||
|
||||
var offset = BitConverter.ToInt32(buffer, c_PeHeaderOffset);
|
||||
var secondsSince1970 = BitConverter.ToInt32(buffer, offset + c_LinkerTimestampOffset);
|
||||
var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
var linkTimeUtc = epoch.AddSeconds(secondsSince1970);
|
||||
|
||||
var tz = target ?? TimeZoneInfo.Local;
|
||||
var localTime = TimeZoneInfo.ConvertTimeFromUtc(linkTimeUtc, tz);
|
||||
|
||||
return localTime;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user