Windows java installation
This commit is contained in:
parent
cfa23c765d
commit
45e9c791b5
28
Backend.py
28
Backend.py
@ -12,6 +12,7 @@ import time
|
|||||||
import math
|
import math
|
||||||
import tarfile
|
import tarfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -23,6 +24,22 @@ def get_tar_members_stripped(tar, n_folders_stripped = 1):
|
|||||||
members.append(member)
|
members.append(member)
|
||||||
return members
|
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):
|
def install_java(mc_version):
|
||||||
global data_dir
|
global data_dir
|
||||||
tokens = mc_version.split(".")
|
tokens = mc_version.split(".")
|
||||||
@ -56,6 +73,11 @@ def install_java(mc_version):
|
|||||||
with tarfile.open(fileobj=buff) as tar:
|
with tarfile.open(fileobj=buff) as tar:
|
||||||
print(tar.getnames())
|
print(tar.getnames())
|
||||||
tar.extractall(data_dir+"/java/java-"+str(java)+"-"+suff, members=get_tar_members_stripped(tar, 1))
|
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
|
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")
|
option_path = os.path.join(prism_instance_path, instance_name, "instance.cfg")
|
||||||
data = []
|
data = []
|
||||||
suff = "win"
|
suff = "win"
|
||||||
|
cmd = "java.exe"
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
suff = "lin"
|
suff = "lin"
|
||||||
|
cmd = "java"
|
||||||
with open(option_path, 'r') as file:
|
with open(option_path, 'r') as file:
|
||||||
data = file.readlines()
|
data = file.readlines()
|
||||||
was_set = False
|
was_set = False
|
||||||
for ind, line in enumerate(data):
|
for ind, line in enumerate(data):
|
||||||
if line.startswith("JavaPath="):
|
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
|
was_set = True
|
||||||
if not was_set:
|
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("OverrideJavaLocation=true\n")
|
||||||
data.append("OverrideJava=true\n")
|
data.append("OverrideJava=true\n")
|
||||||
with open(option_path, 'w') as file:
|
with open(option_path, 'w') as file:
|
||||||
|
Loading…
Reference in New Issue
Block a user