mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-18 00:10:33 -04:00
New 'Platform' class
This commit is contained in:
parent
9b6f2d00ca
commit
dd8da57cfb
@ -432,13 +432,13 @@ public final class LauncherHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (javaVersion.getPlatform() != Architecture.SYSTEM.getBits()) {
|
if (javaVersion.getBits() != Architecture.SYSTEM.getBits()) {
|
||||||
Controllers.dialog(i18n("launch.advice.different_platform"), i18n("message.warning"), MessageType.ERROR, continueAction);
|
Controllers.dialog(i18n("launch.advice.different_platform"), i18n("message.warning"), MessageType.ERROR, continueAction);
|
||||||
suggested = true;
|
suggested = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 32-bit JVM cannot make use of too much memory.
|
// 32-bit JVM cannot make use of too much memory.
|
||||||
if (javaVersion.getPlatform() == Bits.BIT_32 &&
|
if (javaVersion.getBits() == Bits.BIT_32 &&
|
||||||
setting.getMaxMemory() > 1.5 * 1024) {
|
setting.getMaxMemory() > 1.5 * 1024) {
|
||||||
// 1.5 * 1024 is an inaccurate number.
|
// 1.5 * 1024 is an inaccurate number.
|
||||||
// Actual memory limit depends on operating system and memory.
|
// Actual memory limit depends on operating system and memory.
|
||||||
|
@ -547,7 +547,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
|||||||
Task.supplyAsync(JavaVersion::getJavas).thenAcceptAsync(Schedulers.javafx(), list -> {
|
Task.supplyAsync(JavaVersion::getJavas).thenAcceptAsync(Schedulers.javafx(), list -> {
|
||||||
List<MultiFileItem.Option<JavaVersion>> options = list.stream()
|
List<MultiFileItem.Option<JavaVersion>> options = list.stream()
|
||||||
.map(javaVersion -> new MultiFileItem.Option<>(javaVersion.getVersion() + i18n("settings.game.java_directory.bit",
|
.map(javaVersion -> new MultiFileItem.Option<>(javaVersion.getVersion() + i18n("settings.game.java_directory.bit",
|
||||||
javaVersion.getPlatform().getBit()), javaVersion)
|
javaVersion.getBits().getBit()), javaVersion)
|
||||||
.setSubtitle(javaVersion.getBinary().toString()))
|
.setSubtitle(javaVersion.getBinary().toString()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
options.add(0, javaAutoDeterminedOption);
|
options.add(0, javaAutoDeterminedOption);
|
||||||
|
@ -160,7 +160,7 @@ public class DefaultLauncher extends Launcher {
|
|||||||
|
|
||||||
// As 32-bit JVM allocate 320KB for stack by default rather than 64-bit version allocating 1MB,
|
// As 32-bit JVM allocate 320KB for stack by default rather than 64-bit version allocating 1MB,
|
||||||
// causing Minecraft 1.13 crashed accounting for java.lang.StackOverflowError.
|
// causing Minecraft 1.13 crashed accounting for java.lang.StackOverflowError.
|
||||||
if (options.getJava().getPlatform() == Bits.BIT_32) {
|
if (options.getJava().getBits() == Bits.BIT_32) {
|
||||||
res.addDefault("-Xss", "1m");
|
res.addDefault("-Xss", "1m");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ public final class JavaVersion {
|
|||||||
return longVersion;
|
return longVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bits getPlatform() {
|
public Bits getBits() {
|
||||||
return platform;
|
return platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,73 @@
|
|||||||
|
package org.jackhuang.hmcl.util.platform;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public final class Platform {
|
||||||
|
public static final Platform UNKNOWN = new Platform(OperatingSystem.UNKNOWN, Architecture.UNKNOWN);
|
||||||
|
public static final Platform CURRENT = new Platform(OperatingSystem.CURRENT_OS, Architecture.JDK);
|
||||||
|
|
||||||
|
public static final Platform WINDOWS_X86_64 = new Platform(OperatingSystem.WINDOWS, Architecture.X86_64);
|
||||||
|
public static final Platform OSX_X86_64 = new Platform(OperatingSystem.OSX, Architecture.X86_64);
|
||||||
|
public static final Platform LINUX_X86_64 = new Platform(OperatingSystem.LINUX, Architecture.X86_64);
|
||||||
|
|
||||||
|
private final OperatingSystem os;
|
||||||
|
private final Architecture arch;
|
||||||
|
|
||||||
|
private Platform(OperatingSystem os, Architecture arch) {
|
||||||
|
this.os = os;
|
||||||
|
this.arch = arch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Platform getPlatform() {
|
||||||
|
return CURRENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Platform getPlatform(OperatingSystem os, Architecture arch) {
|
||||||
|
if (os == OperatingSystem.UNKNOWN && arch == Architecture.UNKNOWN) {
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arch == Architecture.X86_64) {
|
||||||
|
switch (os) {
|
||||||
|
case WINDOWS:
|
||||||
|
return WINDOWS_X86_64;
|
||||||
|
case OSX:
|
||||||
|
return OSX_X86_64;
|
||||||
|
case LINUX:
|
||||||
|
return LINUX_X86_64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Platform(os, arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperatingSystem getOperatingSystem() {
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Architecture getArchitecture() {
|
||||||
|
return arch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Bits getBits() {
|
||||||
|
return arch.getBits();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(os, arch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (!(o instanceof Platform)) return false;
|
||||||
|
Platform platform = (Platform) o;
|
||||||
|
return os == platform.os && arch == platform.arch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return os.getCheckedName() + "-" + arch; // TODO: getCheckedName()
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user