Skip to content

Commit

Permalink
Update OperatingSystemPolyfill.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 28, 2025
1 parent b7d85d6 commit 45c3227
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions src/Polyfill/OperatingSystemPolyfill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,6 @@ static class OperatingSystemPolyfill
{
#if !NET5_0_OR_GREATER

static Version GetFreeBSDVersion()
{
if (!IsFreeBSD())
{
return Environment.OSVersion.Version;
}

var version = Environment.OSVersion.VersionString
.Replace("Unix", string.Empty).Replace("FreeBSD", string.Empty)
.Replace("-release", string.Empty).Replace(" ", string.Empty);

return Version.Parse(version);
}

static Version GetAndroidVersion()
{
if (!IsAndroid())
{
return Environment.OSVersion.Version;
}

var result = RunProcess("getprop", "ro.build.version.release")
.Replace(" ", string.Empty);

return Version.Parse(result);
}

static string RunProcess(string name, string arguments)
{
using var process = new Process()
Expand Down Expand Up @@ -244,12 +217,27 @@ public static bool IsFreeBSD() =>
/// <param name="revision">The version revision number.</param>
/// <returns>true if the current application is running on a FreeBSD version that is at least what was specified in the parameters; false otherwise.</returns>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isfreebsdversionatleast
public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0) =>
public static bool IsFreeBSDVersionAtLeast(int major, int minor, int build = 0, int revision = 0)
{
#if NET5_0_OR_GREATER
OperatingSystem.IsFreeBSDVersionAtLeast(major, minor, build, revision);
return OperatingSystem.IsFreeBSDVersionAtLeast(major, minor, build, revision);
#else
GetFreeBSDVersion() >= new Version(major, minor, build, revision);
if (!IsFreeBSD())
{
return false;
}

var versionString = Environment.OSVersion.VersionString
.Replace("Unix", string.Empty)
.Replace("FreeBSD", string.Empty)
.Replace("-release", string.Empty)
.Replace(" ", string.Empty);

var version = Version.Parse(versionString);

return version >= new Version(major, minor, build, revision);
#endif
}

/// <summary>
/// Indicates whether the current application is running on iOS or MacCatalyst.
Expand Down Expand Up @@ -346,13 +334,24 @@ public static bool IsAndroid()
/// <param name="revision">The revision release number.</param>
/// <returns>true if the current application is running on an Android version that is at least what was specified in the parameters; false otherwise.</returns>
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.operatingsystem.isandroidversionatleast
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0) =>
public static bool IsAndroidVersionAtLeast(int major, int minor = 0, int build = 0, int revision = 0)
{
#if NET5_0_OR_GREATER
OperatingSystem.IsAndroidVersionAtLeast(major, minor, build, revision);
return OperatingSystem.IsAndroidVersionAtLeast(major, minor, build, revision);
#else
IsAndroid() &&
GetAndroidVersion() >= new Version(major, minor, build, revision);
if (!IsAndroid())
{
return false;
}

var result = RunProcess("getprop", "ro.build.version.release")
.Replace(" ", string.Empty);

var version = Version.Parse(result);

return version >= new Version(major, minor, build, revision);
#endif
}

/// <summary>
/// Indicates whether the current application is running on watchOS.
Expand Down

0 comments on commit 45c3227

Please sign in to comment.