-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOSs.java
More file actions
143 lines (126 loc) · 2.96 KB
/
OSs.java
File metadata and controls
143 lines (126 loc) · 2.96 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package dev.felnull.fnjl.os;
import java.util.Locale;
/**
* OS関連情報
*
* @author MORIMORI0317
* @since 1.10
*/
public class OSs {
/**
* OS名を取得
*
* @return OS名
*/
public static String getOSName() {
return System.getProperty("os.name");
}
/**
* アーキテクスチャ名を取得
*
* @return アーキテクスチャ名
*/
public static String getOSArch() {
return System.getProperty("os.arch");
}
/**
* OSのタイプを取得
*
* @return OSタイプ
*/
public static Type getOS() {
String osName = getOSName().toLowerCase(Locale.ROOT);
for (Type value : Type.values()) {
if (osName.contains(value.getName()))
return value;
}
return Type.OTHER;
}
/**
* Windowsかどうか
*
* @return Windowsか
*/
public static boolean isWindows() {
return getOS() == Type.WINDOWS;
}
/**
* Linuxかどうか
*
* @return Linuxか
*/
public static boolean isLinux() {
return getOS() == Type.LINUX;
}
/**
* MACかどうか
*
* @return MACか
*/
public static boolean isMAC() {
return getOS() == Type.MAC;
}
/**
* x64アーキテクスチャかどうか
*
* @return x64か
*/
public static boolean isX64() {
return "amd64".equalsIgnoreCase(getOSArch()) || "x86_64".equalsIgnoreCase(getOSArch());
}
/**
* x86アーキテクスチャかどうか
*
* @return x86か
*/
public static boolean isX86() {
return "x86".equalsIgnoreCase(getOSArch()) || "i386".equalsIgnoreCase(getOSArch());
}
/**
* Arm64アーキテクスチャかどうか
*
* @return Arm64か
*/
public static boolean isArm64() {
return "aarch64".equalsIgnoreCase(getOSArch());
}
/**
* Arm32アーキテクスチャかどうか
*
* @return Arm32かどうか
*/
public static boolean isArm32() {
return "arm".equalsIgnoreCase(getOSArch());
}
/**
* アーキテクスチャ名を取得
*
* @return アーキテクスチャ名
*/
public static String getArch() {
if (isX64())
return "x64";
if (isX86())
return "x86";
if (isArm64())
return "arm64";
if (isArm32())
return "arm32";
return "no-support";
}
public static enum Type {
WINDOWS("windows", "dll"), LINUX("linux", "so"), MAC("mac", "jnilib"), OTHER("", "so");
private final String name;
private final String libName;
private Type(String name, String libName) {
this.name = name;
this.libName = libName;
}
public String getName() {
return name;
}
public String getLibName() {
return libName;
}
}
}