Skip to content

Commit 81e70b7

Browse files
committed
fix(Core): use Windows DisplayVersion Registry value
1 parent 83bb720 commit 81e70b7

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

SnapX.Core/Utils/Helpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public static Version NormalizeVersion(string version, bool ignoreRevision = fal
285285

286286
public static bool IsWindows11OrGreater(int build = -1)
287287
{
288-
build = System.Math.Max(22000, build);
288+
build = Math.Max(22000, build);
289289
return OSVersion.Major >= 10 && OSVersion.Build >= build;
290290
}
291291
public static string ProperTimeSpan(TimeSpan ts)

SnapX.Core/Utils/OsInfo.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,19 @@ static string GetWindowsVersion()
7474
if (key == null)
7575
return $"Windows {Environment.OSVersion.Version}";
7676

77-
var productName = key.GetValue("ProductName")?.ToString() ?? "Unknown Windows";
77+
var productName = key.GetValue("ProductName")?.ToString() ?? "Windows";
7878
var currentBuild = key.GetValue("CurrentBuild")?.ToString() ?? "Unknown Version";
79-
79+
var displayVersion = key.GetValue("DisplayVersion")?.ToString();
8080
if (Helpers.IsWindows11OrGreater())
8181
productName = productName.Replace("10", "11");
82-
if (BuildToFriendlyName.TryGetValue(currentBuild, out string friendlyName))
83-
{
84-
return $"{productName} {friendlyName}";
85-
}
8682

87-
if (int.TryParse(currentBuild, out int currentBuildNumber))
83+
if (int.TryParse(currentBuild, out var currentBuildNumber) && displayVersion is null)
8884
{
85+
if (BuildToFriendlyName.TryGetValue(currentBuild, out var friendlyName))
86+
{
87+
return $"{productName} {friendlyName}";
88+
}
8989
var closestMatch = BuildToFriendlyName
90-
.Where(kvp => int.TryParse(kvp.Key, out int buildNumber))
9190
.Select(kvp => new { BuildNumber = int.Parse(kvp.Key), FriendlyName = kvp.Value })
9291
.OrderBy(match => Math.Abs(currentBuildNumber - match.BuildNumber))
9392
.FirstOrDefault();
@@ -98,7 +97,7 @@ static string GetWindowsVersion()
9897
}
9998
}
10099

101-
return $"{productName} {currentBuild}";
100+
return displayVersion is not null ? $"{productName} {displayVersion}" : $"{productName} {currentBuild}";
102101
}
103102
catch (Exception ex)
104103
{

0 commit comments

Comments
 (0)