Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing crash on Windows > 22000 #79

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,6 @@ FakesAssemblies/

# Visual Studio 6 workspace options file
*.opt

# Rider settings directory
.idea
6 changes: 1 addition & 5 deletions src/VirtualDesktop/Interop/Build22000/.Provider.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using WindowsDesktop.Interop.Build10240;
using WindowsDesktop.Interop.Build10240;
using WindowsDesktop.Interop.Proxy;
using WindowsDesktop.Properties;

namespace WindowsDesktop.Interop.Build22000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public interface IVirtualDesktopManagerInternal

IVirtualDesktop GetCurrentDesktop(IntPtr hWndOrMon);

IObjectArray GetAllCurrentDesktops();

IObjectArray GetDesktops(IntPtr hWndOrMon);

IVirtualDesktop GetAdjacentDesktop(IVirtualDesktop pDesktopReference, int uDirection);
Expand Down
58 changes: 41 additions & 17 deletions src/VirtualDesktop/Interop/IID.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Configuration;
Expand All @@ -9,34 +9,58 @@

namespace WindowsDesktop.Interop;

internal record OsBuildSettings(
int osBuild,
SettingsProperty prop);

internal static class IID
{
private static readonly Regex _osBuildRegex = new(@"v_(?<build>\d{5}?)");

// ReSharper disable once InconsistentNaming
public static Dictionary<string, Guid> GetIIDs(string[] interfaceNames)
{
var result = new Dictionary<string, Guid>();

foreach (var prop in Settings.Default.Properties.OfType<SettingsProperty>())
{
if (int.TryParse(_osBuildRegex.Match(prop.Name).Groups["build"].ToString(), out var build)
&& build == Environment.OSVersion.Version.Build)

// Order configuration props by build version
var orderedProps = Settings.Default.Properties.OfType<SettingsProperty>()
.Select(prop =>
{
foreach (var str in (StringCollection)Settings.Default[prop.Name])
if (int.TryParse(_osBuildRegex.Match(prop.Name).Groups["build"].ToString(), out var build))
{
if (str == null) continue;
return new OsBuildSettings(build, prop);
}

var pair = str.Split(',');
if (pair.Length != 2) continue;
if (interfaceNames.Contains(pair[0]) == false || result.ContainsKey(pair[0])) continue;
if (Guid.TryParse(pair[1], out var guid) == false) continue;
return null;
})
.Where(s => s != null)
.OrderByDescending(s => s.osBuild)
.ToArray();

result.Add(pair[0], guid);
}
// Find first prop with build version <= current OS version
var selectedSettings = orderedProps.FirstOrDefault(p =>
p.osBuild <= Environment.OSVersion.Version.Build
);

if (selectedSettings == null)
{
var supportedBuilds = orderedProps.Select(v => v.osBuild).ToArray();
throw new ConfigurationException(
"Invalid application configuration. Unable to determine interop interfaces for " +
$"current OS Build: {Environment.OSVersion.Version.Build}. All configured OS Builds " +
$"have build version greater than current OS: {supportedBuilds}");
}

break;
}
foreach (var str in (StringCollection)Settings.Default[selectedSettings.prop.Name])
{
if (str == null) continue;

var pair = str.Split(',');
if (pair.Length != 2) continue;
if (interfaceNames.Contains(pair[0]) == false || result.ContainsKey(pair[0])) continue;
if (Guid.TryParse(pair[1], out var guid) == false) continue;

result.Add(pair[0], guid);
}

var except = interfaceNames.Except(result.Keys).ToArray();
Expand Down
30 changes: 25 additions & 5 deletions src/VirtualDesktop/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 25 additions & 8 deletions src/VirtualDesktop/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version='1.0' encoding='utf-8'?>
<?xml version="1.0" encoding="UTF-8"?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="WindowsDesktop.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="v_17134" Type="System.Collections.Specialized.StringCollection" Scope="Application">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
<Value Profile="(Default)">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
&lt;ArrayOfString xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
&lt;string&gt;IApplicationView,{871F602A-2B58-42B4-8C4B-6C43D642C06F}&lt;/string&gt;
&lt;string&gt;IApplicationViewCollection,{2C08ADF0-A386-4B35-9250-0FE183476FCC} &lt;/string&gt;
&lt;string&gt;IObjectArray,{92CA9DCD-5622-4BBA-A805-5E9F541BD8C9} &lt;/string&gt;
Expand All @@ -18,8 +18,8 @@
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="v_16299" Type="System.Collections.Specialized.StringCollection" Scope="Application">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
<Value Profile="(Default)">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
&lt;ArrayOfString xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
&lt;string&gt;IApplicationView,{9AC0B5C8-1484-4C5B-9533-4134A0F97CEA} &lt;/string&gt;
&lt;string&gt;IApplicationViewCollection,{2C08ADF0-A386-4B35-9250-0FE183476FCC} &lt;/string&gt;
&lt;string&gt;IObjectArray,{92CA9DCD-5622-4BBA-A805-5E9F541BD8C9} &lt;/string&gt;
Expand All @@ -33,8 +33,8 @@
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="v_22000" Type="System.Collections.Specialized.StringCollection" Scope="Application">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;ArrayOfString xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
<Value Profile="(Default)">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
&lt;ArrayOfString xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
&lt;string&gt;IApplicationView,{372e1d3b-38d3-42e4-a15b-8ab2b178f513} &lt;/string&gt;
&lt;string&gt;IApplicationViewCollection,{1841c6d7-4f9d-42c0-af41-8747538f10e5} &lt;/string&gt;
&lt;string&gt;IObjectArray,{92CA9DCD-5622-4BBA-A805-5E9F541BD8C9} &lt;/string&gt;
Expand All @@ -45,7 +45,24 @@
&lt;string&gt;IVirtualDesktopNotification,{cd403e52-deed-4c13-b437-b98380f2b1e8} &lt;/string&gt;
&lt;string&gt;IVirtualDesktopNotificationService,{0cd45e71-d927-4f15-8b0a-8fef525337bf} &lt;/string&gt;
&lt;string&gt;IVirtualDesktopPinnedApps,{4ce81583-1e4c-4632-a621-07a53543148f} &lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
<Setting Name="v_22621" Type="System.Collections.Specialized.StringCollection" Scope="Application">
<Value Profile="(Default)">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;
&lt;ArrayOfString xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&gt;
&lt;string&gt;IApplicationView,{372E1D3B-38D3-42E4-A15B-8AB2B178F513}&lt;/string&gt;
&lt;string&gt;IApplicationViewCollection,{1841C6D7-4F9D-42C0-AF41-8747538F10E5}&lt;/string&gt;
&lt;string&gt;IObjectArray,{92CA9DCD-5622-4BBA-A805-5E9F541BD8C9}&lt;/string&gt;
&lt;string&gt;IServiceProvider,{6D5140C1-7436-11CE-8034-00AA006009FA}&lt;/string&gt;
&lt;string&gt;IVirtualDesktop,{536D3495-B208-4CC9-AE26-DE8111275BF8}&lt;/string&gt;
&lt;string&gt;IVirtualDesktopManager,{A5CD92FF-29BE-454C-8D04-D82879FB3F1B}&lt;/string&gt;
&lt;string&gt;IVirtualDesktopManagerInternal,{B2F925B9-5A0F-4D2E-9F4D-2B1507593C10}&lt;/string&gt;
&lt;string&gt;IVirtualDesktopNotification,{cd403e52-deed-4c13-b437-b98380f2b1e8}&lt;/string&gt;
&lt;string&gt;IVirtualDesktopNotificationService,{0cd45e71-d927-4f15-8b0a-8fef525337bf}&lt;/string&gt;
&lt;string&gt;IVirtualDesktopPinnedApps,{4CE81583-1E4C-4632-A621-07A53543148F}&lt;/string&gt;
&lt;/ArrayOfString&gt;</Value>
</Setting>
</Settings>
</SettingsFile>
</SettingsFile>


Loading