mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-01-13 14:19:12 +00:00
Switch to WmiLight & enable BuiltInComInteropSupport
This commit is contained in:
parent
9345d284d9
commit
5618760299
7 changed files with 51 additions and 57 deletions
|
@ -48,6 +48,7 @@
|
||||||
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="6.31.0" />
|
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="6.31.0" />
|
||||||
<PackageVersion Include="System.IO.Hashing" Version="7.0.0" />
|
<PackageVersion Include="System.IO.Hashing" Version="7.0.0" />
|
||||||
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
|
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />
|
||||||
|
<PackageVersion Include="WmiLight" Version="4.0.0" />
|
||||||
<PackageVersion Include="XamlNameReferenceGenerator" Version="1.6.1" />
|
<PackageVersion Include="XamlNameReferenceGenerator" Version="1.6.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -20,6 +20,7 @@
|
||||||
<PublishSingleFile>true</PublishSingleFile>
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
<TrimmerSingleWarn>false</TrimmerSingleWarn>
|
<TrimmerSingleWarn>false</TrimmerSingleWarn>
|
||||||
<PublishTrimmed>true</PublishTrimmed>
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
|
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||||
<TrimMode>partial</TrimMode>
|
<TrimMode>partial</TrimMode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" />
|
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" />
|
||||||
<PackageReference Include="Microsoft.Management.Infrastructure" />
|
|
||||||
<PackageReference Include="MsgPack.Cli" />
|
<PackageReference Include="MsgPack.Cli" />
|
||||||
|
<PackageReference Include="WmiLight" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using Microsoft.Management.Infrastructure;
|
using Ryujinx.Common.Logging;
|
||||||
using Ryujinx.Common.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
@ -7,6 +6,7 @@ using System.Linq;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Intrinsics.X86;
|
using System.Runtime.Intrinsics.X86;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using WmiLight;
|
||||||
|
|
||||||
namespace Ryujinx.Common.SystemInfo
|
namespace Ryujinx.Common.SystemInfo
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,7 @@ namespace Ryujinx.Common.SystemInfo
|
||||||
{
|
{
|
||||||
public string OsDescription { get; protected set; }
|
public string OsDescription { get; protected set; }
|
||||||
public string CpuName { get; protected set; }
|
public string CpuName { get; protected set; }
|
||||||
|
public static int PhysicalCores { get; protected set; }
|
||||||
public ulong RamTotal { get; protected set; }
|
public ulong RamTotal { get; protected set; }
|
||||||
public ulong RamAvailable { get; protected set; }
|
public ulong RamAvailable { get; protected set; }
|
||||||
protected static int LogicalCoreCount => Environment.ProcessorCount;
|
protected static int LogicalCoreCount => Environment.ProcessorCount;
|
||||||
|
@ -93,14 +94,7 @@ namespace Ryujinx.Common.SystemInfo
|
||||||
{
|
{
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
using (var session = CimSession.Create(null))
|
coreCount = PhysicalCores;
|
||||||
{
|
|
||||||
var instances = session.QueryInstances(@"root\cimv2", "WQL", "SELECT NumberOfCores FROM Win32_Processor");
|
|
||||||
foreach (CimInstance instance in instances)
|
|
||||||
{
|
|
||||||
coreCount = int.Parse(instance.CimInstanceProperties["NumberOfCores"].Value.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,86 +1,82 @@
|
||||||
using Microsoft.Management.Infrastructure;
|
|
||||||
using Ryujinx.Common.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.Versioning;
|
||||||
|
using WmiLight;
|
||||||
|
using Ryujinx.Common.Logging;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.Versioning;
|
|
||||||
|
|
||||||
namespace Ryujinx.Common.SystemInfo
|
namespace Ryujinx.Common.SystemInfo
|
||||||
{
|
{
|
||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
partial class WindowsSystemInfo : SystemInfo
|
partial class WindowsSystemInfo : SystemInfo
|
||||||
{
|
{
|
||||||
private CimSession _cimSession;
|
|
||||||
|
|
||||||
internal WindowsSystemInfo()
|
internal WindowsSystemInfo()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//Inefficient to create a session for each query do it all at once
|
using (WmiConnection connection = new WmiConnection())
|
||||||
_cimSession = CimSession.Create(null);
|
|
||||||
CpuName = $"{GetCpuNameMMI() ?? GetCpuidCpuName()} ; {GetPhysicalCoreCount()} physical ; {LogicalCoreCount} logical";
|
|
||||||
(RamTotal, RamAvailable) = GetMemoryStatsMMI();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
{
|
||||||
_cimSession?.Dispose();
|
(string cpuName, int physicalCores) = GetCpuStatsLight(connection);
|
||||||
|
CpuName = $"{cpuName} ; {physicalCores} physical ; {LogicalCoreCount} logical";
|
||||||
|
(RamTotal, RamAvailable) = GetMemoryStatsWmiLight(connection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.Error?.Print(LogClass.Application, $"WmiLight isn't available : {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetCpuNameMMI()
|
|
||||||
{
|
|
||||||
var cpuObjs = GetMMIObjects(@"root\cimv2", "SELECT Name FROM Win32_Processor");
|
|
||||||
|
|
||||||
if (cpuObjs != null)
|
private (string cpuName, int physicalCores) GetCpuStatsLight(WmiConnection connection)
|
||||||
{
|
{
|
||||||
foreach (var cpuObj in cpuObjs)
|
string cpuName = Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")?.Trim();
|
||||||
|
int physicalCores = LogicalCoreCount;
|
||||||
|
foreach (WmiObject cpuObj in GetWmiObjects(connection, "SELECT Name FROM Win32_Processor"))
|
||||||
{
|
{
|
||||||
return cpuObj.CimInstanceProperties["Name"].Value.ToString().Trim();
|
cpuName = cpuObj["Name"].ToString().Trim();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Environment.GetEnvironmentVariable("PROCESSOR_IDENTIFIER")?.Trim();
|
foreach (WmiObject cpuObj in GetWmiObjects(connection, "SELECT NumberOfCores FROM Win32_Processor"))
|
||||||
|
{
|
||||||
|
physicalCores = Convert.ToInt32(cpuObj["NumberOfCores"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private (ulong TotalPhys, ulong AvailPhys) GetMemoryStatsMMI()
|
return (cpuName, physicalCores);
|
||||||
{
|
}
|
||||||
var memObjs = GetMMIObjects(@"root\cimv2", "SELECT TotalPhysicalMemory FROM Win32_ComputerSystem");
|
|
||||||
var memObjs2 = GetMMIObjects(@"root\cimv2", "SELECT FreePhysicalMemory FROM Win32_OperatingSystem");
|
|
||||||
|
|
||||||
|
private (ulong TotalPhys, ulong AvailPhys) GetMemoryStatsWmiLight(WmiConnection connection)
|
||||||
|
{
|
||||||
ulong TotalPhys = 0;
|
ulong TotalPhys = 0;
|
||||||
ulong AvailPhys = 0;
|
ulong AvailPhys = 0;
|
||||||
|
|
||||||
if (memObjs != null)
|
foreach (WmiObject memObj in GetWmiObjects(connection, "SELECT TotalPhysicalMemory FROM Win32_ComputerSystem"))
|
||||||
{
|
{
|
||||||
foreach (var memObj in memObjs)
|
TotalPhys = Convert.ToUInt64(memObj["TotalPhysicalMemory"]);
|
||||||
{
|
|
||||||
TotalPhys = (ulong)memObj.CimInstanceProperties["TotalPhysicalMemory"].Value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memObjs2 != null)
|
foreach (WmiObject memObj2 in GetWmiObjects(connection, "SELECT FreePhysicalMemory FROM Win32_OperatingSystem"))
|
||||||
{
|
{
|
||||||
foreach (var memObj2 in memObjs2)
|
AvailPhys = Convert.ToUInt64(memObj2["FreePhysicalMemory"]) * 1000;
|
||||||
{
|
|
||||||
AvailPhys = (ulong)memObj2.CimInstanceProperties["FreePhysicalMemory"].Value*1000;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (TotalPhys, AvailPhys);
|
return (TotalPhys, AvailPhys);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<CimInstance> GetMMIObjects(string namespaceName, string query)
|
|
||||||
|
private IEnumerable<WmiObject> GetWmiObjects(WmiConnection connection, string query)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _cimSession.QueryInstances(namespaceName, "WQL", query).ToList();
|
return connection.CreateQuery(query).ToList();
|
||||||
}
|
}
|
||||||
catch (CimException ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.Error?.Print(LogClass.Application, $"MMI isn't available : {ex.Message}");
|
Logger.Error?.Print(LogClass.Application, $"WmiLight isn't available : {ex.Message}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Enumerable.Empty<WmiObject>();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Enumerable.Empty<CimInstance>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@
|
||||||
<PropertyGroup Condition="'$(RuntimeIdentifier)' != ''">
|
<PropertyGroup Condition="'$(RuntimeIdentifier)' != ''">
|
||||||
<PublishSingleFile>true</PublishSingleFile>
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
<PublishTrimmed>true</PublishTrimmed>
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
|
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||||
<TrimMode>partial</TrimMode>
|
<TrimMode>partial</TrimMode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
|
@ -16,6 +16,7 @@
|
||||||
<PublishSingleFile>true</PublishSingleFile>
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
<TrimmerSingleWarn>false</TrimmerSingleWarn>
|
<TrimmerSingleWarn>false</TrimmerSingleWarn>
|
||||||
<PublishTrimmed>true</PublishTrimmed>
|
<PublishTrimmed>true</PublishTrimmed>
|
||||||
|
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
|
||||||
<TrimMode>partial</TrimMode>
|
<TrimMode>partial</TrimMode>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue