aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/util/SystemUtils.java
blob: 45fc25caf62f6905c09ca74313c4fbafd35762bf (plain)
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
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;
		}
	}
	
}