using bundled version of prism
This commit is contained in:
parent
bd53d50150
commit
4795a1f059
63
Backend.py
63
Backend.py
@ -14,6 +14,52 @@ import tarfile
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
|
def install_prism():
|
||||||
|
global data_dir
|
||||||
|
if not os.path.exists(os.path.join(data_dir, "prism")):
|
||||||
|
install_java(21)
|
||||||
|
suff = "win.zip"
|
||||||
|
if os.name == "posix":
|
||||||
|
suff = "lin.tar.gz"
|
||||||
|
prism_file = "prism/prism-"+suff
|
||||||
|
ftp = FTP("gitea.piwalker.net")
|
||||||
|
ftp.login()
|
||||||
|
ftp.prot_p()
|
||||||
|
with io.BytesIO() as buff:
|
||||||
|
ftp.retrbinary("RETR "+prism_file, buff.write)
|
||||||
|
buff.seek(0)
|
||||||
|
if os.name == "nt":
|
||||||
|
with zipfile.ZipFile(buff) as zip:
|
||||||
|
zip.extractall(os.path.join(data_dir, "prism"))
|
||||||
|
else:
|
||||||
|
with tarfile.open(fileobj=buff) as tar:
|
||||||
|
tar.extractall(os.path.join(data_dir, "prism"))
|
||||||
|
with io.BytesIO() as buff:
|
||||||
|
ftp.retrbinary("RETR prism/prismlauncher.cfg", buff.write)
|
||||||
|
buff.seek(0)
|
||||||
|
with open(os.path.join(data_dir, "prism", "prismlauncher.cfg"), 'wb') as file:
|
||||||
|
file.write(buff.getbuffer())
|
||||||
|
ftp.close()
|
||||||
|
suff = "win"
|
||||||
|
cmd = "java.exe"
|
||||||
|
if os.name == "posix":
|
||||||
|
suff = "lin"
|
||||||
|
cmd = "java"
|
||||||
|
data = []
|
||||||
|
with open(os.path.join(data_dir, "prism", "prismlauncher.cfg"), 'r') as file:
|
||||||
|
data = file.readlines()
|
||||||
|
|
||||||
|
for ind, line in enumerate(data):
|
||||||
|
if line.startswith("JavaPath="):
|
||||||
|
data[ind] = "JavaPath="+data_dir.replace("\\", "/")+"/java/java-21-"+suff+"/bin/"+cmd+"\n"
|
||||||
|
with open(os.path.join(data_dir, "prism", "prismlauncher.cfg"), 'w') as file:
|
||||||
|
file.writelines(data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_tar_members_stripped(tar, n_folders_stripped = 1):
|
def get_tar_members_stripped(tar, n_folders_stripped = 1):
|
||||||
@ -39,8 +85,7 @@ def unzip(zip, dest):
|
|||||||
with zip.open(file_info, 'r') as src:
|
with zip.open(file_info, 'r') as src:
|
||||||
shutil.copyfileobj(src, dst)
|
shutil.copyfileobj(src, dst)
|
||||||
|
|
||||||
|
def get_java_version(mc_version):
|
||||||
def install_java(mc_version):
|
|
||||||
global data_dir
|
global data_dir
|
||||||
tokens = mc_version.split(".")
|
tokens = mc_version.split(".")
|
||||||
java = 8
|
java = 8
|
||||||
@ -53,7 +98,10 @@ def install_java(mc_version):
|
|||||||
java = 17
|
java = 17
|
||||||
else:
|
else:
|
||||||
java = 21
|
java = 21
|
||||||
|
return java
|
||||||
|
|
||||||
|
|
||||||
|
def install_java(java):
|
||||||
suff = "win"
|
suff = "win"
|
||||||
ext = ".zip"
|
ext = ".zip"
|
||||||
if os.name == "posix":
|
if os.name == "posix":
|
||||||
@ -78,7 +126,6 @@ def install_java(mc_version):
|
|||||||
unzip(zip, data_dir+"/java/java-"+str(java)+"-"+suff)
|
unzip(zip, data_dir+"/java/java-"+str(java)+"-"+suff)
|
||||||
|
|
||||||
|
|
||||||
return java
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -98,6 +145,13 @@ def perform_installation(instance_name, prism_command, prism_instance_path, pack
|
|||||||
|
|
||||||
Path(data_dir).mkdir(parents=True, exist_ok=True)
|
Path(data_dir).mkdir(parents=True, exist_ok=True)
|
||||||
Path(data_dir+"/java").mkdir(parents=True, exist_ok=True)
|
Path(data_dir+"/java").mkdir(parents=True, exist_ok=True)
|
||||||
|
install_prism()
|
||||||
|
if os.name == "nt":
|
||||||
|
prism_command = os.path.join(data_dir, "prism", "prismlauncher.exe")
|
||||||
|
else:
|
||||||
|
prism_command = os.path.join(data_dir, "prism", "PrismLauncher")
|
||||||
|
prism_instance_path = os.path.join(data_dir, "prism", "instances")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ftp = FTP("gitea.piwalker.net")
|
ftp = FTP("gitea.piwalker.net")
|
||||||
@ -148,7 +202,8 @@ def perform_installation(instance_name, prism_command, prism_instance_path, pack
|
|||||||
if component["uid"] == "net.minecraft":
|
if component["uid"] == "net.minecraft":
|
||||||
mc_version = component["version"]
|
mc_version = component["version"]
|
||||||
break;
|
break;
|
||||||
java = install_java(mc_version)
|
java = get_java_version(mc_version)
|
||||||
|
install_java(java)
|
||||||
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"
|
||||||
|
Loading…
Reference in New Issue
Block a user