Windows java installation

This commit is contained in:
Samuel Walker 2024-06-20 22:26:30 -06:00
parent cfa23c765d
commit 45e9c791b5

View File

@ -12,6 +12,7 @@ import time
import math
import tarfile
from pathlib import Path
import shutil
@ -23,6 +24,22 @@ def get_tar_members_stripped(tar, n_folders_stripped = 1):
members.append(member)
return members
def unzip(zip, dest):
for file_info in zip.infolist():
if file_info.is_dir():
continue
file_path = file_info.filename
extracted_path = file_path.split("/", 1)[1]
extracted_path = os.path.join(dest, extracted_path)
print(extracted_path)
os.makedirs(os.path.dirname(extracted_path), exist_ok=True)
with open(extracted_path, 'wb') as dst:
with zip.open(file_info, 'r') as src:
shutil.copyfileobj(src, dst)
def install_java(mc_version):
global data_dir
tokens = mc_version.split(".")
@ -56,6 +73,11 @@ def install_java(mc_version):
with tarfile.open(fileobj=buff) as tar:
print(tar.getnames())
tar.extractall(data_dir+"/java/java-"+str(java)+"-"+suff, members=get_tar_members_stripped(tar, 1))
else:
with zipfile.ZipFile(buff) as zip:
unzip(zip, data_dir+"/java/java-"+str(java)+"-"+suff)
return java
@ -130,17 +152,19 @@ def perform_installation(instance_name, prism_command, prism_instance_path, pack
option_path = os.path.join(prism_instance_path, instance_name, "instance.cfg")
data = []
suff = "win"
cmd = "java.exe"
if os.name == "posix":
suff = "lin"
cmd = "java"
with open(option_path, 'r') as file:
data = file.readlines()
was_set = False
for ind, line in enumerate(data):
if line.startswith("JavaPath="):
data[ind] = "JavaPath="+data_dir+"/java/java-"+str(java)+"-"+suff+"/bin/java\n"
data[ind] = "JavaPath="+data_dir.replace("\\", "/")+"/java/java-"+str(java)+"-"+suff+"/bin/"+cmd+"\n"
was_set = True
if not was_set:
data.append("JavaPath="+data_dir+"/java/java-"+str(java)+"-"+suff+"/bin/java\n")
data.append("JavaPath="+data_dir.replace("\\", "/")+"/java/java-"+str(java)+"-"+suff+"/bin/"+cmd+"\n")
data.append("OverrideJavaLocation=true\n")
data.append("OverrideJava=true\n")
with open(option_path, 'w') as file: