2021-04-24 02:59:39 +02:00
|
|
|
|
/******************************************************************************/
|
|
|
|
|
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
|
|
|
|
|
/* This work has been released under the CC0 1.0 Universal license! */
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace com.muldersoft.slunkcrypt.gui.utils
|
|
|
|
|
{
|
|
|
|
|
static class VersionInfo
|
|
|
|
|
{
|
2022-09-29 00:57:03 +02:00
|
|
|
|
private static readonly Lazy<Version> m_version = new Lazy<Version> (InitializeVersion);
|
|
|
|
|
private static readonly Lazy<DateTime> m_buildDateTime = new Lazy<DateTime>(InitializeBuildDateTime);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// Properties
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
2022-09-29 00:57:03 +02:00
|
|
|
|
public static Version Version { get { return m_version.Value; } }
|
|
|
|
|
|
|
|
|
|
public static DateTime BuildDate { get { return m_buildDateTime.Value; } }
|
2021-04-24 02:59:39 +02:00
|
|
|
|
|
2022-09-29 00:57:03 +02:00
|
|
|
|
public static new string ToString()
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
2024-11-17 23:27:19 +01:00
|
|
|
|
Version value = Version;
|
|
|
|
|
string versionString = string.Format(
|
|
|
|
|
((value.Revision > 0) || (value.Build > 0)) ? ((value.Build > 0) ? "{0:D}.{1:D}.{2:D}.{3:D}" : "{0:D}.{1:D}.{3:D}") : "{0:D}.{1:D}",
|
|
|
|
|
value.Major, value.Minor, value.Build, value.Revision);
|
|
|
|
|
return string.Format("Version {0}, built on {1}", versionString, BuildDate.ToString("yyyy-MM-dd"));
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
|
// Internal methods
|
|
|
|
|
// =============================================================================
|
|
|
|
|
|
2022-09-29 00:57:03 +02:00
|
|
|
|
private static Version InitializeVersion()
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-09-29 00:57:03 +02:00
|
|
|
|
AssemblyFileVersionAttribute fileVersionAttribute = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyFileVersionAttribute), false) as AssemblyFileVersionAttribute;
|
|
|
|
|
Version fileVersion;
|
|
|
|
|
if (Version.TryParse(fileVersionAttribute?.Version, out fileVersion))
|
|
|
|
|
{
|
|
|
|
|
return fileVersion;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return Assembly.GetExecutingAssembly().GetName().Version;
|
|
|
|
|
}
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2022-09-29 00:57:03 +02:00
|
|
|
|
return new Version(0, 0, 0, 0);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-29 00:57:03 +02:00
|
|
|
|
private static DateTime InitializeBuildDateTime()
|
2021-04-24 02:59:39 +02:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2022-09-29 00:57:03 +02:00
|
|
|
|
Version version = Assembly.GetExecutingAssembly().GetName().Version;
|
|
|
|
|
return new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
2022-09-29 00:57:03 +02:00
|
|
|
|
return new DateTime(1928, 6, 14, 0, 0, 0, DateTimeKind.Utc);
|
2021-04-24 02:59:39 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|