From ec80d0fb1db19bd3dc0b465edcb272ec25aaf567 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 29 Jan 2021 11:20:37 +1000 Subject: [PATCH] Add prop OSTailoredCode.IsWSL --- src/BizHawk.Common/Extensions/StringExtensions.cs | 3 +++ src/BizHawk.Common/OSTailoredCode.cs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/BizHawk.Common/Extensions/StringExtensions.cs b/src/BizHawk.Common/Extensions/StringExtensions.cs index b2105959b9..52f0d47c95 100644 --- a/src/BizHawk.Common/Extensions/StringExtensions.cs +++ b/src/BizHawk.Common/Extensions/StringExtensions.cs @@ -5,6 +5,9 @@ namespace BizHawk.Common.StringExtensions { public static class StringExtensions { + public static bool Contains(this string haystack, string needle, StringComparison comparisonType) + => haystack.IndexOf(needle, comparisonType) != -1; + /// /// if appears in (case-insensitive) /// diff --git a/src/BizHawk.Common/OSTailoredCode.cs b/src/BizHawk.Common/OSTailoredCode.cs index da5e85b14e..2a54eebd2b 100644 --- a/src/BizHawk.Common/OSTailoredCode.cs +++ b/src/BizHawk.Common/OSTailoredCode.cs @@ -3,6 +3,8 @@ using System.Diagnostics; using System.Globalization; using System.Runtime.InteropServices; +using BizHawk.Common.StringExtensions; + #if EXE_PROJECT namespace EXE_PROJECT // Use a different namespace so the executable can still use this class' members without an implicit dependency on the BizHawk.Common library, and without resorting to code duplication. #else @@ -44,10 +46,14 @@ namespace BizHawk.Common return (winVer, null); }); + private static readonly Lazy _isWSL = new(() => IsUnixHost && SimpleSubshell("uname", "-r", "missing uname?").Contains("microsoft", StringComparison.InvariantCultureIgnoreCase)); + public static (WindowsVersion Version, int? Win10Release)? HostWindowsVersion => _HostWindowsVersion.Value; public static readonly bool IsUnixHost = CurrentOS != DistinctOS.Windows; + public static bool IsWSL => _isWSL.Value; + private static readonly Lazy _LinkedLibManager = new Lazy(() => CurrentOS switch { DistinctOS.Linux => new UnixMonoLLManager(),