-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPlatformCheck.cs
113 lines (100 loc) · 3.59 KB
/
PlatformCheck.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
namespace KiwiGui
{
public class PlatformCheck
{
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern long GetEnabledXStateFeatures();
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern Int32 IsProcessorFeaturePresent(Int32 ProcessorFeature);
public static bool Is64Bit()
{
return IntPtr.Size == 8;
}
public static string GetBinPath()
{
return (Is64Bit() ? "x64" : "x86") + "/tomoto.exe";
}
public enum SIMD
{
None,
SSE,
SSE2,
SSE3,
AVX
}
public static SIMD GetSIMDAvailable()
{
try
{
if ((GetEnabledXStateFeatures() & 4) != 0) return SIMD.AVX;
}
catch
{
}
try
{
if (IsProcessorFeaturePresent(13) != 0) return SIMD.SSE3;
if (IsProcessorFeaturePresent(10) != 0) return SIMD.SSE2;
if (IsProcessorFeaturePresent(6) != 0) return SIMD.SSE;
}
catch
{
}
return SIMD.None;
}
public class SystemInfo
{
public string cpuClockSpeed, cpuName, cpuManufacturer, cpuVersion;
public long physicalMemory;
public string osName;
}
public static SystemInfo GetSystemInfo()
{
SystemInfo si = new SystemInfo();
using (ManagementObjectSearcher win32Proc = new ManagementObjectSearcher("select * from Win32_Processor"),
win32CompSys = new ManagementObjectSearcher("select * from Win32_ComputerSystem"),
win32OS = new ManagementObjectSearcher("select * from Win32_OperatingSystem"))
{
foreach (ManagementObject obj in win32Proc.Get())
{
si.cpuClockSpeed = obj["MaxClockSpeed"].ToString();
si.cpuName = obj["Name"].ToString();
si.cpuManufacturer = obj["Manufacturer"].ToString();
si.cpuVersion = obj["Version"].ToString();
}
foreach (ManagementObject obj in win32CompSys.Get())
{
si.physicalMemory = long.Parse(obj["TotalPhysicalMemory"].ToString());
}
foreach (ManagementObject obj in win32OS.Get())
{
si.osName = obj["Caption"].ToString();
}
}
return si;
}
public static string GetUniqueComputerID()
{
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
string drive = "C";
ManagementObject dsk = new ManagementObject(
@"win32_logicaldisk.deviceid=""" + drive + @":""");
dsk.Get();
string volumeSerial = dsk["VolumeSerialNumber"].ToString();
return cpuInfo + "_" + volumeSerial;
}
}
}