using System.Reflection; using System.Runtime.InteropServices; using CursorLang.Core.Interop; using Windows.ApplicationModel; namespace CursorLang.Core.Services; /// /// The version of the running application. /// /// /// 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. /// 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); } }