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