only use WMI on Windows

This commit is contained in:
Jesse Plamondon-Willard 2017-03-02 22:03:23 -05:00
parent 1485d98b24
commit 6f07801b04
2 changed files with 12 additions and 10 deletions

View File

@ -4,10 +4,10 @@ using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Management;
using System.Reflection;
using System.Threading;
#if SMAPI_FOR_WINDOWS
using System.Management;
using System.Windows.Forms;
#endif
using Microsoft.Xna.Framework.Graphics;
@ -586,19 +586,21 @@ namespace StardewModdingAPI
}
/// <summary>Get a human-readable name for the current platform.</summary>
[SuppressMessage("ReSharper", "EmptyGeneralCatchClause", Justification = "Error suppressed deliberately to fallback to default behaviour.")]
private string GetFriendlyPlatformName()
{
#if SMAPI_FOR_WINDOWS
try
{
return (
from entry in new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem").Get().Cast<ManagementObject>()
select entry.GetPropertyValue("Caption").ToString()
).FirstOrDefault();
return new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem")
.Get()
.Cast<ManagementObject>()
.Select(entry => entry.GetPropertyValue("Caption").ToString())
.FirstOrDefault();
}
catch
{
catch { }
#endif
return Environment.OSVersion.ToString();
}
}
}
}

View File

@ -97,7 +97,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Management" />
<Reference Include="System.Management" Condition="$(OS) == 'Windows_NT'" />
<Reference Include="System.Numerics">
<Private>True</Private>
</Reference>