From 90c01b8a8d6c00f4c19d9e081b35eea3a34599f3 Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 18 May 2022 14:54:39 +0200 Subject: [PATCH] Fix java whereis and enhance architecture detection --- oml/stages/config.py | 48 +++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/oml/stages/config.py b/oml/stages/config.py index b94e8af..e94b077 100644 --- a/oml/stages/config.py +++ b/oml/stages/config.py @@ -22,20 +22,6 @@ if lv["osName"] == "": if lv["osVersion"] == "": lv["osVersion"] = platform.version() -print(colored(colorama.Fore.GREEN,"Checking for Java...")) -global javaExe -javaExe = shutil.which(lv["java"]) -if javaExe == None: - print(colored(colorama.Fore.RED,"Java wasn't found at '" +lv["java"]+ "'. Please configure java in config.ini.")) - sys.exit(1) - -if lv["jvmArch"] == "": - print(colored(colorama.Fore.GREEN,"Querying JVM architecture...")) - if "64-Bit" in subprocess.check_output([javaExe,"-version"]).decode("utf-8"): - lv["jvmArch"] = "amd64" - else: - lv["jvmArch"] = "x86" - print("") for setting in lv: print(colored(colorama.Fore.BLACK,setting+ "=" +str(lv[setting]))) @@ -54,6 +40,40 @@ if not lv["osName"] in ["windows","linux","macos"]: print(colored(colorama.Fore.MAGENTA,"Falling back to assuming Linux.")) lv["osName"] = "linux" +print(colored(colorama.Fore.GREEN,"Checking for Java...")) +global javaExe +javaExe = whereis(lv["java"]) +if javaExe == None: + print(colored(colorama.Fore.RED,"Java wasn't found at '" +lv["java"]+ "'. Please configure java in config.ini.")) + sys.exit(1) + +if lv["jvmArch"] == "": + print(colored(colorama.Fore.GREEN,"Querying JVM architecture... "),end="") + try: + if lv["osName"] != "windows": + with open(javaExe,"rb") as jh: + jh.seek(4) + if int.from_bytes(jh.read(1),"little") == 1: + lv["jvmArch"] = "x86" + print("x86") + else: + lv["jvmArch"] = "amd64" + print("Not x86, assuming amd64") + else: + with open(javaExe,"rb") as jh: + jh.seek(60) + jh.seek(int.from_bytes(jh.read(2),"little") + 4) + if int.from_bytes(jh.read(2),"little") == 332: + lv["jvmArch"] = "x86" + print("x86") + else: + lv["jvmArch"] = "amd64" + print("Not x86, assuming amd64") + except: + print(colored(colorama.Fore.YELLOW,"\nWarning, could not query JVM architecture. Needs to be either amd64 or x86. Define it with jvmArch=arch in the config."),file=sys.stderr) + print(colored(colorama.Fore.MAGENTA,"Assuming amd64.")) + raise + print("") if not "version" in lv: lv["version"] = input("Version ID: ") if "-downloadonly" in sys.argv: lv["name"] = "Player"