java-org.hwo.platform/src/org/hwo/platform/Platform.java

54 lines
1.2 KiB
Java

package org.hwo.platform;
public class Platform {
public enum OsType { UNKNOWN, LINUX, OSX, WINDOWS};
public enum Bitness { B32, B64 };
public static OsType getOperatingSystem()
{
if (System.getProperty("os.name").equals("Mac OS X"))
return OsType.OSX;
if (System.getProperty("os.name").equals("Linux"))
return OsType.LINUX;
if (System.getProperty("os.name").startsWith("Windows"))
return OsType.WINDOWS;
return OsType.UNKNOWN;
}
public static Bitness getBitness(){
String arch = System.getProperty("os.arch");
if (arch == null) {
return null;
}
if (arch.equals("x86")){
return Bitness.B32;
} else if (arch.equals("i386")){
return Bitness.B32;
} else if (arch.equals("xmd64")){
return Bitness.B64;
} else if (arch.equals("amd64")){
return Bitness.B64;
}
return null;
}
public static String PlatformName(){
OsType ost = getOperatingSystem();
Bitness bit = getBitness();
return String.format("%s%s",
(ost == OsType.LINUX) ? "linux" :
(ost == OsType.OSX) ? "osx" :
(ost == OsType.WINDOWS) ? "mswin" :
"unknown",
(bit == Bitness.B32) ? "32" :
(bit == Bitness.B64) ? "64" :
"XX"
);
}
}