mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
82 lines
1.9 KiB
Java
82 lines
1.9 KiB
Java
package com.chameleonvision.settings;
|
|
|
|
import com.chameleonvision.util.ShellExec;
|
|
|
|
import java.io.IOException;
|
|
|
|
public enum Platform {
|
|
WINDOWS_64("Windows x64"),
|
|
LINUX_64("Linux x64"),
|
|
LINUX_RASPBIAN("Linux Raspbian"),
|
|
LINUX_TEGRA("Linux For Tegra"),
|
|
LINUX_ARM64("Linux ARM64"),
|
|
MACOS_64("Mac OS x64"),
|
|
UNSUPPORTED("Unsupported Platform");
|
|
|
|
public final String value;
|
|
|
|
Platform(String value) {
|
|
this.value = value;
|
|
}
|
|
|
|
public boolean isWindows() {
|
|
return this == WINDOWS_64;
|
|
}
|
|
|
|
public boolean isLinux() {
|
|
return this == LINUX_64 || this == LINUX_RASPBIAN || this == LINUX_ARM64 || this == LINUX_TEGRA;
|
|
}
|
|
|
|
public boolean isMac() {
|
|
return this == MACOS_64;
|
|
}
|
|
|
|
private static ShellExec shell = new ShellExec(true, false);
|
|
|
|
public boolean isRoot() {
|
|
if (isLinux() || isMac()) {
|
|
try {
|
|
shell.execute("id", null, true, "-u");
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
while (!shell.isOutputCompleted()) {}
|
|
if (shell.getExitCode() == 0) {
|
|
var out = shell.getOutput();
|
|
out = out.split("\n")[0];
|
|
return out.equals("0");
|
|
}
|
|
} else if (isWindows()) {
|
|
return true;
|
|
} else {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static Platform getCurrentPlatform() {
|
|
var osName = System.getProperty("os.name");
|
|
var osArch = System.getProperty("os.arch");
|
|
|
|
if (osName.contains("Windows")) {
|
|
if (osArch.equals("amd64")) return Platform.WINDOWS_64;
|
|
return Platform.UNSUPPORTED;
|
|
}
|
|
|
|
if (osName.contains("Linux")) {
|
|
if (osName.contains("Tegra")) return Platform.LINUX_TEGRA;
|
|
if (osArch.equals("amd64")) return Platform.LINUX_64;
|
|
if (osArch.contains("rasp")) return Platform.LINUX_RASPBIAN;
|
|
if (osArch.contains("aarch")) return Platform.LINUX_ARM64;
|
|
return Platform.UNSUPPORTED;
|
|
}
|
|
|
|
if (osName.contains("Mac")) {
|
|
if (osArch.equals("amd64")) return Platform.MACOS_64;
|
|
return Platform.UNSUPPORTED;
|
|
}
|
|
|
|
return Platform.UNSUPPORTED;
|
|
}
|
|
}
|