38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using System.Reflection;
|
|
using System.Runtime.InteropServices;
|
|
using CursorLang.Core.Interop;
|
|
using Windows.ApplicationModel;
|
|
|
|
namespace CursorLang.Core.Services;
|
|
|
|
/// <summary>
|
|
/// The version of the running application.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// The same application runs from a package and from a folder, and the two keep
|
|
/// their version in different places. The answer is computed once: it cannot
|
|
/// change while the process lives.
|
|
/// </remarks>
|
|
public static class AppVersion
|
|
{
|
|
public static Version Current { get; } = Detect();
|
|
|
|
private static Version Detect()
|
|
{
|
|
if (PackageIdentityNative.IsPackaged)
|
|
{
|
|
try
|
|
{
|
|
PackageVersion version = Package.Current.Id.Version;
|
|
return new Version(version.Major, version.Minor, version.Build, version.Revision);
|
|
}
|
|
catch (Exception e) when (e is COMException or InvalidOperationException)
|
|
{
|
|
// The package was built without a version in the manifest — the assembly version is left
|
|
}
|
|
}
|
|
|
|
return Assembly.GetEntryAssembly()?.GetName().Version ?? new Version(0, 0, 0, 0);
|
|
}
|
|
}
|