Windows GUI: Some improvements in detecting the program "patch" version.

This commit is contained in:
LoRd_MuldeR 2022-09-29 00:57:03 +02:00
parent 968a5f7032
commit 270430b9d8
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
6 changed files with 49 additions and 20 deletions

View File

@ -81,13 +81,13 @@ namespace com.muldersoft.slunkcrypt.gui.process
executableFile = new FileStream(Path.Combine(appBaseDirectory, String.Format(FILENAME_FORMAT, suffix)), FileMode.Open, FileAccess.Read, FileShare.Read);
try
{
Version appVersion = VersionInfo.Version;
FileVersionInfo fileVersion = FileVersionInfo.GetVersionInfo(executableFile.Name);
Version appVersion = VersionInfo.Version;
if (string.Equals(fileVersion.FileDescription, "SlunkCrypt", StringComparison.OrdinalIgnoreCase) &&
string.Equals(fileVersion.CompanyName, "Muldersoft", StringComparison.OrdinalIgnoreCase) &&
(fileVersion.FileMajorPart == appVersion.Major) && (fileVersion.FileMinorPart == appVersion.Minor))
{
success = true;
success = (fileVersion.FilePrivatePart >= appVersion.Revision);
}
}
finally

View File

@ -7,6 +7,8 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows;
using static com.muldersoft.slunkcrypt.gui.Properties._Version;
[assembly: AssemblyTitle("SlunkCrypt GUI")]
[assembly: AssemblyDescription("SlunkCrypt GUI")]
[assembly: AssemblyConfiguration("")]
@ -19,5 +21,6 @@ using System.Windows;
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyVersion("1.2.*")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion(VERS_MAJOR + "." + VERS_MINOR + ".*")]
[assembly: AssemblyFileVersion(VERS_MAJOR + "." + VERS_MINOR + ".0." + VERS_PATCH)]
[assembly: AssemblyInformationalVersion(VERS_MAJOR + "." + VERS_MINOR + ".0." + VERS_PATCH)]

View File

@ -0,0 +1,14 @@
/******************************************************************************/
/* SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
namespace com.muldersoft.slunkcrypt.gui.Properties
{
internal static class _Version
{
public const string VERS_MAJOR = "1";
public const string VERS_MINOR = "2";
public const string VERS_PATCH = "1";
}
}

View File

@ -81,6 +81,7 @@
<Compile Include="Controls\PasswordToggleBox.xaml.cs">
<DependentUpon>PasswordToggleBox.xaml</DependentUpon>
</Compile>
<Compile Include="Properties\_Version.cs" />
<Compile Include="Utilities\EnumHelper.cs" />
<Compile Include="Process\ExecutableHelper.cs" />
<Compile Include="Utilities\ApplicationConfig.cs" />

View File

@ -852,7 +852,7 @@ namespace com.muldersoft.slunkcrypt.gui
CPUFeatures cpuFeatures = CPUFeatures.Features;
return new StringBuilder()
.AppendLine("SlunkCrypt, by LoRd_MuldeR <MuldeR2@GMX.de>")
.AppendLine(VersionInfo.VersionStr)
.AppendLine(VersionInfo.ToString())
.AppendLine("This work has been released under the \u201CCC0 1.0\u201D license!")
.AppendLine()
.AppendLine("Official web-site: http://slunkcrypt.osdn.io/")

View File

@ -10,49 +10,60 @@ namespace com.muldersoft.slunkcrypt.gui.utils
{
static class VersionInfo
{
private static readonly Lazy<Version> m_version = new Lazy<Version>(GetAssemblyVersion);
private static readonly Lazy<string> m_versionStr = new Lazy<string>(InitVersionString);
private static readonly Lazy<Version> m_version = new Lazy<Version> (InitializeVersion);
private static readonly Lazy<DateTime> m_buildDateTime = new Lazy<DateTime>(InitializeBuildDateTime);
// =============================================================================
// Properties
// =============================================================================
public static Version Version
{
get { return m_version.Value; }
}
public static Version Version { get { return m_version.Value; } }
public static string VersionStr
public static DateTime BuildDate { get { return m_buildDateTime.Value; } }
public static new string ToString()
{
get { return m_versionStr.Value; }
Version version = m_version.Value;
return string.Format(
(version.Revision > 0) ? "Version {0:D}.{1:D}.{2:D}, built on {3}" : "Version {0:D}.{1:D}, built on {3}",
version.Major, version.Minor, version.Revision, BuildDate.ToString("yyyy-MM-dd"));
}
// =============================================================================
// Internal methods
// =============================================================================
private static Version GetAssemblyVersion()
private static Version InitializeVersion()
{
try
{
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;
}
}
catch
{
return new Version();
return new Version(0, 0, 0, 0);
}
}
private static string InitVersionString()
private static DateTime InitializeBuildDateTime()
{
try
{
DateTime buildDate = new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * Version.Build + TimeSpan.TicksPerSecond * 2 * Version.Revision));
return String.Format("Version {0:D}.{1:D}, built on {2}", Version.Major, Version.Minor, buildDate.ToString("yyyy-MM-dd"));
Version version = Assembly.GetExecutingAssembly().GetName().Version;
return new DateTime(2000, 1, 1).Add(new TimeSpan(TimeSpan.TicksPerDay * version.Build + TimeSpan.TicksPerSecond * 2 * version.Revision));
}
catch
{
return "Unknown version";
return new DateTime(1928, 6, 14, 0, 0, 0, DateTimeKind.Utc);
}
}
}