Skip to content

Commit 66393ba

Browse files
committed
替换并重命名 isCompatibleWithX86Java 方法为 isSupportedTranslationX86_64,优化代码的可读性和逻辑一致性
1 parent 098207a commit 66393ba

3 files changed

Lines changed: 14 additions & 10 deletions

File tree

HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
7373
import static org.jackhuang.hmcl.util.logging.Logger.LOG;
7474
import static org.jackhuang.hmcl.util.platform.Platform.SYSTEM_PLATFORM;
75-
import static org.jackhuang.hmcl.util.platform.Platform.isCompatibleWithX86Java;
7675

7776
public final class LauncherHelper {
7877

@@ -625,7 +624,7 @@ else if (violatedMandatoryConstraints.contains(JavaVersionConstraint.VANILLA))
625624
break;
626625
case VANILLA_X86:
627626
if (setting.getNativesDirType() == NativesDirectoryType.VERSION_FOLDER
628-
&& isCompatibleWithX86Java()) {
627+
&& Platform.isSupportedTranslationX86_64()) {
629628
suggestions.add(i18n("launch.advice.vanilla_x86.translation"));
630629
}
631630
break;

HMCL/src/main/java/org/jackhuang/hmcl/java/JavaManager.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static boolean isCompatible(Platform platform) {
124124
if (Architecture.SYSTEM_ARCH == Architecture.X86_64)
125125
return architecture == Architecture.X86;
126126
if (Architecture.SYSTEM_ARCH == Architecture.ARM64)
127-
return OperatingSystem.SYSTEM_BUILD_NUMBER >= 21277 && architecture == Architecture.X86_64 || architecture == Architecture.X86;
127+
return Platform.isSupportedTranslationX86_64() && architecture == Architecture.X86_64 || architecture == Architecture.X86;
128128
break;
129129
case LINUX:
130130
if (Architecture.SYSTEM_ARCH == Architecture.X86_64)
@@ -364,13 +364,13 @@ private static Map<Path, JavaRuntime> searchPotentialJavaExecutables(boolean use
364364
if (Architecture.SYSTEM_ARCH == Architecture.X86_64)
365365
searcher.searchAllJavaInRepository(Platform.WINDOWS_X86);
366366
if (Architecture.SYSTEM_ARCH == Architecture.ARM64) {
367-
if (OperatingSystem.SYSTEM_BUILD_NUMBER >= 21277)
367+
if (Platform.isSupportedTranslationX86_64())
368368
searcher.searchAllJavaInRepository(Platform.WINDOWS_X86_64);
369369
searcher.searchAllJavaInRepository(Platform.WINDOWS_X86);
370370
}
371371
break;
372372
case MACOS:
373-
if (Architecture.SYSTEM_ARCH == Architecture.ARM64)
373+
if (Architecture.SYSTEM_ARCH == Architecture.ARM64 && Platform.isSupportedTranslationX86_64())
374374
searcher.searchAllJavaInRepository(Platform.MACOS_X86_64);
375375
break;
376376
}
@@ -784,13 +784,15 @@ void searchAllOfficialJava(Path directory, boolean verify) {
784784
if (Architecture.SYSTEM_ARCH == Architecture.X86_64) {
785785
searchAllOfficialJava(directory, getMojangJavaPlatform(Platform.WINDOWS_X86), verify);
786786
} else if (Architecture.SYSTEM_ARCH == Architecture.ARM64) {
787-
if (OperatingSystem.SYSTEM_BUILD_NUMBER >= 21277) {
787+
if (Platform.isSupportedTranslationX86_64()) {
788788
searchAllOfficialJava(directory, getMojangJavaPlatform(Platform.WINDOWS_X86_64), verify);
789789
}
790790
searchAllOfficialJava(directory, getMojangJavaPlatform(Platform.WINDOWS_X86), verify);
791791
}
792-
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS && Architecture.CURRENT_ARCH == Architecture.ARM64) {
793-
searchAllOfficialJava(directory, getMojangJavaPlatform(Platform.MACOS_X86_64), verify);
792+
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) {
793+
if (Architecture.CURRENT_ARCH == Architecture.ARM64 && Platform.isSupportedTranslationX86_64()) {
794+
searchAllOfficialJava(directory, getMojangJavaPlatform(Platform.MACOS_X86_64), verify);
795+
}
794796
}
795797
}
796798

HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/Platform.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,11 @@ public record Platform(OperatingSystem os, Architecture arch) {
5656
}
5757
}
5858

59-
public static boolean isCompatibleWithX86Java() {
60-
return Architecture.SYSTEM_ARCH.isX86() || SYSTEM_PLATFORM.equals(MACOS_ARM64) || SYSTEM_PLATFORM.equals(WINDOWS_ARM64);
59+
/// Returns `true` if the current platform architecture is not x86-64,
60+
/// but can support executing x86-64 applications through translation;
61+
/// otherwise, returns `false`.
62+
public static boolean isSupportedTranslationX86_64() {
63+
return SUPPORTED_TRANSLATION_X86_64;
6164
}
6265

6366
public static Platform getPlatform(OperatingSystem os, Architecture arch) {

0 commit comments

Comments
 (0)