mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-19 04:07:10 -04:00
Move OS detection code out of CmdServerInfo.cs and into Server.cs
This commit is contained in:
parent
5a5eb4492b
commit
a75ea460b2
@ -110,21 +110,15 @@ namespace MCGalaxy.Commands.Info
|
|||||||
public ulong IdleTime, KernelTime, UserTime;
|
public ulong IdleTime, KernelTime, UserTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe static CPUTime MeasureAllCPUTime()
|
unsafe static CPUTime MeasureAllCPUTime() {
|
||||||
|
switch (Server.DetectOS())
|
||||||
{
|
{
|
||||||
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
case DetectedOS.Windows: return MeasureAllWindows();
|
||||||
return MeasureAllWindows();
|
case DetectedOS.OSX: return MeasureAllMac();
|
||||||
|
case DetectedOS.Linux: return MeasureAllLinux();
|
||||||
sbyte* ascii = stackalloc sbyte[8192];
|
}
|
||||||
uname(ascii);
|
return default(CPUTime);
|
||||||
string kernel = new String(ascii);
|
|
||||||
if (kernel == "Darwin") return MeasureAllMac();
|
|
||||||
|
|
||||||
return MeasureAllLinux();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libc")]
|
|
||||||
unsafe static extern void uname(sbyte* uname_struct);
|
|
||||||
|
|
||||||
|
|
||||||
static CPUTime MeasureAllWindows() {
|
static CPUTime MeasureAllWindows() {
|
||||||
|
@ -37,8 +37,12 @@ using MCGalaxy.Tasks;
|
|||||||
using MCGalaxy.Util;
|
using MCGalaxy.Util;
|
||||||
using MCGalaxy.Modules.Awards;
|
using MCGalaxy.Modules.Awards;
|
||||||
|
|
||||||
namespace MCGalaxy {
|
namespace MCGalaxy
|
||||||
public sealed partial class Server {
|
{
|
||||||
|
public enum DetectedOS { Unknown, Windows, OSX, Linux }
|
||||||
|
|
||||||
|
public sealed partial class Server
|
||||||
|
{
|
||||||
|
|
||||||
public Server() { Server.s = this; }
|
public Server() { Server.s = this; }
|
||||||
|
|
||||||
@ -456,5 +460,24 @@ namespace MCGalaxy {
|
|||||||
if (!name.EndsWith("+")) name += "+";
|
if (!name.EndsWith("+")) name += "+";
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public unsafe static DetectedOS DetectOS() {
|
||||||
|
PlatformID platform = Environment.OSVersion.Platform;
|
||||||
|
if (platform == PlatformID.Win32NT || platform == PlatformID.Win32Windows)
|
||||||
|
return DetectedOS.Windows;
|
||||||
|
|
||||||
|
sbyte* ascii = stackalloc sbyte[8192];
|
||||||
|
uname(ascii);
|
||||||
|
string kernel = new String(ascii);
|
||||||
|
|
||||||
|
if (kernel == "Darwin") return DetectedOS.OSX;
|
||||||
|
if (kernel == "Linux") return DetectedOS.Linux;
|
||||||
|
|
||||||
|
return DetectedOS.Unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("libc")]
|
||||||
|
unsafe static extern void uname(sbyte* uname_struct);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user