diff options
Diffstat (limited to 'src/Java/gtPlusPlus/core/util/SystemUtils.java')
-rw-r--r-- | src/Java/gtPlusPlus/core/util/SystemUtils.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/core/util/SystemUtils.java b/src/Java/gtPlusPlus/core/util/SystemUtils.java new file mode 100644 index 0000000000..45fc25caf6 --- /dev/null +++ b/src/Java/gtPlusPlus/core/util/SystemUtils.java @@ -0,0 +1,77 @@ +package gtPlusPlus.core.util; + +public class SystemUtils { + + private static OS SystemType; + + public static OS getOS(){ + if (SystemType != null){ + return SystemType; + } + else { + SystemType = getOperatingSystem(); + return SystemType; + } + } + + public static boolean isWindows() { + return (getOSString().indexOf("win") >= 0); + } + + public static boolean isMac() { + return (getOSString().indexOf("mac") >= 0); + } + + public static boolean isUnix() { + return (getOSString().indexOf("nix") >= 0 || getOSString().indexOf("nux") >= 0 || getOSString().indexOf("aix") > 0 ); + } + + public static boolean isSolaris() { + return (getOSString().indexOf("sunos") >= 0); + } + + public static String getOSString(){ + try { + return System.getProperty("os.name").toLowerCase(); + } + catch (Throwable t){ + return "other"; + } + } + + public static OS getOperatingSystem(){ + if (isMac()){ + return OS.MAC; + } + else if (isWindows()){ + return OS.WINDOWS; + } + else if (isUnix()){ + return OS.UNIX; + } + else if (isSolaris()){ + return OS.SOLARIS; + } + else { + return OS.OTHER; + } + } + + public static enum OS { + MAC(1), + WINDOWS(2), + UNIX(3), + SOLARIS(4), + OTHER(0); + + private int mID; + private OS (final int ID){ + this.mID = ID; + } + + public int getID() { + return this.mID; + } + } + +} |