Upload Base
This commit is contained in:
97
src/main/java/net/montoyo/mcef/utilities/Platform.java
Normal file
97
src/main/java/net/montoyo/mcef/utilities/Platform.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package net.montoyo.mcef.utilities;
|
||||
|
||||
import net.montoyo.mcef.MCEF;
|
||||
import net.montoyo.mcef.utilities.Log;
|
||||
import org.cef.OS;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class Platform {
|
||||
|
||||
public static String id;
|
||||
public static String idFull;
|
||||
public static String arch;
|
||||
public static String archFull;
|
||||
public static String PLATFORM;
|
||||
public static String PLATFORMFULL;
|
||||
|
||||
static { // Static block for initialization
|
||||
detectPlatform();
|
||||
}
|
||||
|
||||
private static void detectPlatform() {
|
||||
try {
|
||||
id = System.getProperty("os.name", "unknown").toLowerCase(Locale.US);
|
||||
arch = System.getProperty("os.arch", "unknown").toLowerCase(Locale.US);
|
||||
} catch (Exception e) {
|
||||
Log.error("Couldn't get OS name or architecture.");
|
||||
id = "unknown";
|
||||
arch = "unknown";
|
||||
}
|
||||
|
||||
// Normalize OS name
|
||||
if (OS.isWindows()) {
|
||||
id = "win";
|
||||
idFull = "windows";
|
||||
} else if (OS.isMacintosh()) {
|
||||
id = "mac";
|
||||
idFull = "macos";
|
||||
} else if (OS.isLinux()) {
|
||||
id = "linux";
|
||||
idFull = "linux";
|
||||
} else {
|
||||
Log.error("Your OS isn't supported by MCEF.");
|
||||
id = "unknown";
|
||||
idFull = "unknown";
|
||||
return;
|
||||
}
|
||||
|
||||
// Normalize CPU architecture
|
||||
if (arch.equals("x86_64") || arch.equals("amd64") || arch.equals("64")) {
|
||||
arch = "64";
|
||||
archFull = "amd64";
|
||||
} else if (arch.equals("aarch64") || arch.equals("arm64")) {
|
||||
if (!id.equals("mac") || !id.equals("darwin")) { // Only allow ARM64 for Macs
|
||||
Log.error("ARM-based platforms other than Mac are not supported by MCEF.");
|
||||
id = "unknown";
|
||||
idFull = "unknown";
|
||||
return;
|
||||
}
|
||||
arch = "arm64";
|
||||
archFull = "arm64";
|
||||
} else {
|
||||
Log.error("Your CPU architecture isn't supported by MCEF.");
|
||||
id = "unknown";
|
||||
idFull = "unknown";
|
||||
return;
|
||||
}
|
||||
|
||||
// Set platform strings
|
||||
PLATFORM = id + arch;
|
||||
PLATFORMFULL = idFull + "_" + archFull;
|
||||
}
|
||||
|
||||
public static String getOS() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public static String getPlatform() {
|
||||
return PLATFORM;
|
||||
}
|
||||
|
||||
public static String getPlatformFull() {
|
||||
return PLATFORMFULL;
|
||||
}
|
||||
|
||||
public static boolean isWindows() {
|
||||
return "win".equals(id);
|
||||
}
|
||||
|
||||
public static boolean isMacOS() {
|
||||
return "mac".equals(id) || "darwin".equals(id);
|
||||
}
|
||||
|
||||
public static boolean isLinux() {
|
||||
return "linux".equals(id);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user