* update * update --------- Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
package org.jackhuang.hmcl.util.io;
|
package org.jackhuang.hmcl.util.io;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -74,6 +75,10 @@ public final class IOUtils {
|
|||||||
return readFully(stream).toString("UTF-8");
|
return readFully(stream).toString("UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String readFullyAsString(InputStream stream, Charset charset) throws IOException {
|
||||||
|
return readFully(stream).toString(charset.name());
|
||||||
|
}
|
||||||
|
|
||||||
public static void copyTo(InputStream src, OutputStream dest) throws IOException {
|
public static void copyTo(InputStream src, OutputStream dest) throws IOException {
|
||||||
copyTo(src, dest, new byte[DEFAULT_BUFFER_SIZE]);
|
copyTo(src, dest, new byte[DEFAULT_BUFFER_SIZE]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.jackhuang.hmcl.util.platform;
|
package org.jackhuang.hmcl.util.platform;
|
||||||
|
|
||||||
|
import org.jackhuang.hmcl.util.io.IOUtils;
|
||||||
import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.File;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@@ -192,30 +192,46 @@ public enum Architecture {
|
|||||||
static {
|
static {
|
||||||
CURRENT_ARCH = parseArchName(System.getProperty("os.arch"));
|
CURRENT_ARCH = parseArchName(System.getProperty("os.arch"));
|
||||||
|
|
||||||
String sysArchName = null;
|
Architecture sysArch = null;
|
||||||
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
|
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
|
||||||
String processorIdentifier = System.getenv("PROCESSOR_IDENTIFIER");
|
String processorIdentifier = System.getenv("PROCESSOR_IDENTIFIER");
|
||||||
if (processorIdentifier != null) {
|
if (processorIdentifier != null) {
|
||||||
int idx = processorIdentifier.indexOf(' ');
|
int idx = processorIdentifier.indexOf(' ');
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
sysArchName = processorIdentifier.substring(0, idx);
|
sysArch = parseArchName(processorIdentifier.substring(0, idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.OSX) {
|
||||||
|
if (CURRENT_ARCH == X86_64) {
|
||||||
|
try {
|
||||||
|
Process process = Runtime.getRuntime().exec(new String[]{"/usr/sbin/sysctl", "-n", "sysctl.proc_translated"});
|
||||||
|
if (process.waitFor(3, TimeUnit.SECONDS) && process.exitValue() == 0
|
||||||
|
&& "1".equals(IOUtils.readFullyAsString(process.getInputStream(), OperatingSystem.NATIVE_CHARSET).trim())) {
|
||||||
|
sysArch = ARM64;
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
for (String uname : new String[]{
|
||||||
Process process = Runtime.getRuntime().exec(new String[]{"/bin/uname", "-m"});
|
"/bin/uname",
|
||||||
if (process.waitFor(3, TimeUnit.SECONDS)) {
|
"/usr/bin/uname"
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), OperatingSystem.NATIVE_CHARSET))) {
|
}) {
|
||||||
sysArchName = reader.readLine().trim();
|
if (new File(uname).exists()) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
e.printStackTrace();
|
Process process = Runtime.getRuntime().exec(new String[]{uname, "-m"});
|
||||||
|
if (process.waitFor(3, TimeUnit.SECONDS) && process.exitValue() == 0) {
|
||||||
|
sysArch = parseArchName(IOUtils.readFullyAsString(process.getInputStream(), OperatingSystem.NATIVE_CHARSET).trim());
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace(System.err);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Architecture sysArch = parseArchName(sysArchName);
|
SYSTEM_ARCH = sysArch == null || sysArch == UNKNOWN ? CURRENT_ARCH : sysArch;
|
||||||
SYSTEM_ARCH = sysArch == UNKNOWN ? CURRENT_ARCH : sysArch;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user