From c1cbff754ef681a94150758a10327f8063737f1a Mon Sep 17 00:00:00 2001 From: sk89q Date: Mon, 3 Aug 2015 14:25:54 -0700 Subject: [PATCH] Possibly improve detection of 32-bit/64-bit. --- .../skcraft/launcher/launch/JavaRuntimeFinder.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/launcher/src/main/java/com/skcraft/launcher/launch/JavaRuntimeFinder.java b/launcher/src/main/java/com/skcraft/launcher/launch/JavaRuntimeFinder.java index 798c0fe..5bf1cb3 100644 --- a/launcher/src/main/java/com/skcraft/launcher/launch/JavaRuntimeFinder.java +++ b/launcher/src/main/java/com/skcraft/launcher/launch/JavaRuntimeFinder.java @@ -11,6 +11,7 @@ import com.skcraft.launcher.util.Platform; import com.skcraft.launcher.util.WinRegistry; import java.io.File; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collections; @@ -49,7 +50,8 @@ public final class JavaRuntimeFinder { return null; } - private static void getEntriesFromRegistry(List entries, String basePath) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { + private static void getEntriesFromRegistry(List entries, String basePath) + throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { List subKeys = WinRegistry.readStringSubKeys(WinRegistry.HKEY_LOCAL_MACHINE, basePath); for (String subKey : subKeys) { JREEntry entry = getEntryFromRegistry(basePath, subKey); @@ -59,7 +61,7 @@ public final class JavaRuntimeFinder { } } - private static JREEntry getEntryFromRegistry(String basePath, String version) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { + private static JREEntry getEntryFromRegistry(String basePath, String version) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { String regPath = basePath + "\\" + version; String path = WinRegistry.readString(WinRegistry.HKEY_LOCAL_MACHINE, regPath, "JavaHome"); File dir = new File(path); @@ -75,8 +77,12 @@ public final class JavaRuntimeFinder { } private static boolean guessIf64Bit(File path) { - String programFilesX86 = System.getenv("ProgramFiles(x86)"); - return programFilesX86 == null || !path.toString().startsWith(new File(programFilesX86).toString()); + try { + String programFilesX86 = System.getenv("ProgramFiles(x86)"); + return programFilesX86 == null || !path.getCanonicalPath().startsWith(new File(programFilesX86).getCanonicalPath()); + } catch (IOException ignored) { + return false; + } } private static class JREEntry implements Comparable {