|
1 | 1 | using System;
|
| 2 | +using System.Text.RegularExpressions; |
2 | 3 | using Microsoft.Win32;
|
3 | 4 |
|
4 | 5 | namespace WinJump.Core.VirtualDesktopDefinitions;
|
@@ -32,28 +33,24 @@ public interface IVirtualDesktopAPI : IDisposable {
|
32 | 33 | /// <returns>A virtual desktop API for the installed Windows version</returns>
|
33 | 34 | /// <exception cref="Exception">If the particular Windows version is unsupported</exception>
|
34 | 35 | public static IVirtualDesktopAPI Create() {
|
35 |
| - string? releaseId = Registry.LocalMachine.OpenSubKey("SOFTWARE")?.OpenSubKey("Microsoft")? |
36 |
| - .OpenSubKey("Windows NT")?.OpenSubKey("CurrentVersion")?.GetValue("CurrentBuildNumber")?.ToString(); |
37 |
| - |
| 36 | + OperatingSystem osInfo = Environment.OSVersion; |
| 37 | + |
38 | 38 | string? releaseBuild = Registry.LocalMachine.OpenSubKey("SOFTWARE")?.OpenSubKey("Microsoft")?
|
39 | 39 | .OpenSubKey("Windows NT")?.OpenSubKey("CurrentVersion")?.GetValue("UBR")?.ToString();
|
40 | 40 |
|
41 |
| - if(!int.TryParse(releaseId, out int releaseIdNumber)) { |
42 |
| - throw new Exception($"Unrecognized Windows release id version {releaseId}.{releaseBuild}"); |
43 |
| - } |
44 |
| - |
45 | 41 | if(!int.TryParse(releaseBuild, out int releaseBuildNumber)) {
|
46 |
| - throw new Exception($"Unrecognized Windows build version {releaseId}.{releaseBuild}"); |
| 42 | + throw new Exception($"Unrecognized Windows build version {osInfo.Version.Build}.{releaseBuild}"); |
47 | 43 | }
|
48 | 44 |
|
49 |
| - return releaseIdNumber switch { |
| 45 | + return osInfo.Version.Build switch { |
50 | 46 | // Work out the proper desktop wrapper
|
51 | 47 | >= 22621 => releaseBuildNumber >= 2215
|
52 | 48 | ? new Windows11_22621_2215.VirtualDesktopApi()
|
53 | 49 | : new Windows11_22621.VirtualDesktopApi(),
|
54 | 50 | >= 22000 => new Windows11_22000.VirtualDesktopApi(),
|
55 | 51 | >= 17763 => new Windows10_17763.VirtualDesktopApi(),
|
56 |
| - _ => throw new Exception($"Unsupported Windows version {releaseIdNumber}.{releaseBuildNumber}") |
| 52 | + // Just try the most recent as a last ditch effort |
| 53 | + _ => new Windows11_22621_2215.VirtualDesktopApi() |
57 | 54 | };
|
58 | 55 | }
|
59 | 56 | }
|
|
0 commit comments