mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-21 18:23:54 -04:00
Merge c3dabfaab44aa6be5fb194ec022cb4d325f6f08e into bd9ae189f83e33a6977bbe056774c851e96fe0a7
This commit is contained in:
commit
b653509ef4
@ -29,15 +29,12 @@ import javafx.stage.Stage;
|
||||
import org.jackhuang.hmcl.setting.ConfigHolder;
|
||||
import org.jackhuang.hmcl.setting.SambaException;
|
||||
import org.jackhuang.hmcl.ui.FXUtils;
|
||||
import org.jackhuang.hmcl.util.FileSaver;
|
||||
import org.jackhuang.hmcl.util.*;
|
||||
import org.jackhuang.hmcl.task.AsyncTaskExecutor;
|
||||
import org.jackhuang.hmcl.task.Schedulers;
|
||||
import org.jackhuang.hmcl.ui.Controllers;
|
||||
import org.jackhuang.hmcl.upgrade.UpdateChecker;
|
||||
import org.jackhuang.hmcl.upgrade.UpdateHandler;
|
||||
import org.jackhuang.hmcl.util.CrashReporter;
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
import org.jackhuang.hmcl.util.io.JarUtils;
|
||||
import org.jackhuang.hmcl.util.platform.Architecture;
|
||||
import org.jackhuang.hmcl.util.platform.CommandBuilder;
|
||||
@ -252,6 +249,7 @@ public final class Launcher extends Application {
|
||||
LOG.info("Java Version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor"));
|
||||
LOG.info("Java VM Version: " + System.getProperty("java.vm.name") + " (" + System.getProperty("java.vm.info") + "), " + System.getProperty("java.vm.vendor"));
|
||||
LOG.info("Java Home: " + System.getProperty("java.home"));
|
||||
LOG.info("User Privilege: " + AdminChecker.isAdmin());
|
||||
LOG.info("Current Directory: " + Metadata.CURRENT_DIRECTORY);
|
||||
LOG.info("HMCL Global Directory: " + Metadata.HMCL_GLOBAL_DIRECTORY);
|
||||
LOG.info("HMCL Current Directory: " + Metadata.HMCL_CURRENT_DIRECTORY);
|
||||
|
46
HMCL/src/main/java/org/jackhuang/hmcl/util/AdminChecker.java
Executable file
46
HMCL/src/main/java/org/jackhuang/hmcl/util/AdminChecker.java
Executable file
@ -0,0 +1,46 @@
|
||||
package org.jackhuang.hmcl.util;
|
||||
|
||||
import org.jackhuang.hmcl.util.platform.OperatingSystem;
|
||||
import org.jackhuang.hmcl.util.platform.windows.WinReg;
|
||||
|
||||
public class AdminChecker {
|
||||
|
||||
private AdminChecker() {
|
||||
}
|
||||
|
||||
public static boolean isAdmin() {
|
||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
|
||||
return isWindowsAdmin();
|
||||
} else if (OperatingSystem.CURRENT_OS.isLinuxOrBSD() && OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) {
|
||||
return isUnixRoot();
|
||||
} else {
|
||||
// 未知系统,保守返回 false
|
||||
System.err.println("Unknown OS: " + OperatingSystem.CURRENT_OS);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isWindowsAdmin() {
|
||||
WinReg reg = WinReg.INSTANCE;
|
||||
try {
|
||||
return reg.exists(WinReg.HKEY.HKEY_USERS, "S-1-5-19");
|
||||
} catch (Throwable t) {
|
||||
// 捕获 AccessException、JNA 错误等
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isUnixRoot() {
|
||||
try {
|
||||
ProcessBuilder pb = new ProcessBuilder("id", "-u");
|
||||
Process process = pb.start();
|
||||
java.util.Scanner scanner = new java.util.Scanner(process.getInputStream());
|
||||
String uid = scanner.hasNext() ? scanner.next() : "";
|
||||
scanner.close();
|
||||
process.waitFor();
|
||||
return "0".equals(uid.trim());
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user