From 24adb62df83180cdbc925e895d1574f88bce978f Mon Sep 17 00:00:00 2001 From: Fierelier Date: Wed, 18 May 2022 02:32:22 +0200 Subject: [PATCH] Add Java check --- oml/stages/config.py | 9 ++++++++- oml/stages/launch.py | 5 +++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/oml/stages/config.py b/oml/stages/config.py index 72ce891..b94e8af 100644 --- a/oml/stages/config.py +++ b/oml/stages/config.py @@ -22,9 +22,16 @@ 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([lv["java"],"-version"]).decode("utf-8"): + if "64-Bit" in subprocess.check_output([javaExe,"-version"]).decode("utf-8"): lv["jvmArch"] = "amd64" else: lv["jvmArch"] = "x86" diff --git a/oml/stages/launch.py b/oml/stages/launch.py index ba7c48c..195e5f8 100644 --- a/oml/stages/launch.py +++ b/oml/stages/launch.py @@ -1,8 +1,9 @@ print(colored(colorama.Fore.GREEN,"\nLaunching Minecraft...")) if lv["console"] == "1": - proc = subprocess.Popen([lv["java"]] + args) + proc = subprocess.Popen([javaExe] + args) rtn = proc.wait() if rtn != 0: print(colored(colorama.Fore.RED,"> Launch failed: ") +"return isn't 0",file=sys.stderr) + sys.exit(rtn) else: pkwargs = { "stdout": subprocess.DEVNULL, @@ -10,4 +11,4 @@ else: "stderr": subprocess.DEVNULL } if lv["osName"] == "windows": pkwargs["creationflags"] = 0x00000008 - subprocess.Popen([lv["java"] + "w"] + args,**pkwargs) \ No newline at end of file + subprocess.Popen([shutil.which(lv["java"] + "w")] + args,**pkwargs) \ No newline at end of file