Added custom java installation
This commit is contained in:
parent
8870b39592
commit
cfa23c765d
93
Backend.py
93
Backend.py
@ -10,6 +10,54 @@ import zipfile
|
|||||||
from customtkinter import *
|
from customtkinter import *
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
|
import tarfile
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def get_tar_members_stripped(tar, n_folders_stripped = 1):
|
||||||
|
members = []
|
||||||
|
for member in tar.getmembers():
|
||||||
|
p = Path(member.path)
|
||||||
|
member.path = p.relative_to(*p.parts[:n_folders_stripped])
|
||||||
|
members.append(member)
|
||||||
|
return members
|
||||||
|
|
||||||
|
def install_java(mc_version):
|
||||||
|
global data_dir
|
||||||
|
tokens = mc_version.split(".")
|
||||||
|
java = 8
|
||||||
|
if tokens[1] == "17":
|
||||||
|
java = 17
|
||||||
|
elif tokens[1] == "18" or tokens[1] == "19":
|
||||||
|
java = 17
|
||||||
|
elif int(tokens[1]) > 19:
|
||||||
|
if tokens[1] == "20" and int(tokens[2]) < 5:
|
||||||
|
java = 17
|
||||||
|
else:
|
||||||
|
java = 21
|
||||||
|
|
||||||
|
suff = "win"
|
||||||
|
ext = ".zip"
|
||||||
|
if os.name == "posix":
|
||||||
|
suff = "lin"
|
||||||
|
ext = ".tar.gz"
|
||||||
|
|
||||||
|
java_path = "java/java-"+str(java)+"-"+suff+ext
|
||||||
|
if not os.path.exists(data_dir+"/java/java-"+str(java)+"-"+suff):
|
||||||
|
print("Downloading Java "+str(java))
|
||||||
|
ftp = FTP("gitea.piwalker.net")
|
||||||
|
ftp.login()
|
||||||
|
ftp.prot_p()
|
||||||
|
with io.BytesIO() as buff:
|
||||||
|
ftp.retrbinary("RETR "+java_path,buff.write)
|
||||||
|
if os.name == "posix":
|
||||||
|
buff.seek(0)
|
||||||
|
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))
|
||||||
|
return java
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def resource_path(relative_path):
|
def resource_path(relative_path):
|
||||||
@ -20,6 +68,15 @@ def resource_path(relative_path):
|
|||||||
return os.path.join(base_path, relative_path)
|
return os.path.join(base_path, relative_path)
|
||||||
|
|
||||||
def perform_installation(instance_name, prism_command, prism_instance_path, pack):
|
def perform_installation(instance_name, prism_command, prism_instance_path, pack):
|
||||||
|
global data_dir
|
||||||
|
if os.name == "posix":
|
||||||
|
data_dir = os.getenv("HOME") + "/.local/share/FCLauncher"
|
||||||
|
else:
|
||||||
|
data_dir = os.getenv("APPDATA") + "/FCLauncher"
|
||||||
|
|
||||||
|
Path(data_dir).mkdir(parents=True, exist_ok=True)
|
||||||
|
Path(data_dir+"/java").mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ftp = FTP("gitea.piwalker.net")
|
ftp = FTP("gitea.piwalker.net")
|
||||||
ftp.login()
|
ftp.login()
|
||||||
@ -61,12 +118,44 @@ def perform_installation(instance_name, prism_command, prism_instance_path, pack
|
|||||||
with open(version_file_path, 'r') as fp:
|
with open(version_file_path, 'r') as fp:
|
||||||
version = fp.readline().rstrip()
|
version = fp.readline().rstrip()
|
||||||
if version == versions[-1]["Version"]:
|
if version == versions[-1]["Version"]:
|
||||||
|
info_file_path = os.path.join(prism_instance_path, instance_name, "mmc-pack.json")
|
||||||
|
mc_version = ""
|
||||||
|
with open(info_file_path) as file:
|
||||||
|
info = json.load(file)
|
||||||
|
for component in info["components"]:
|
||||||
|
if component["uid"] == "net.minecraft":
|
||||||
|
mc_version = component["version"]
|
||||||
|
break;
|
||||||
|
java = install_java(mc_version)
|
||||||
|
option_path = os.path.join(prism_instance_path, instance_name, "instance.cfg")
|
||||||
|
data = []
|
||||||
|
suff = "win"
|
||||||
|
if os.name == "posix":
|
||||||
|
suff = "lin"
|
||||||
|
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"
|
||||||
|
was_set = True
|
||||||
|
if not was_set:
|
||||||
|
data.append("JavaPath="+data_dir+"/java/java-"+str(java)+"-"+suff+"/bin/java\n")
|
||||||
|
data.append("OverrideJavaLocation=true\n")
|
||||||
|
data.append("OverrideJava=true\n")
|
||||||
|
with open(option_path, 'w') as file:
|
||||||
|
file.writelines(data)
|
||||||
|
print(data)
|
||||||
|
|
||||||
|
|
||||||
|
subprocess.run([prism_command, '-l', instance_name])
|
||||||
|
time.sleep(30)
|
||||||
break
|
break
|
||||||
|
else:
|
||||||
|
subprocess.run([prism_command, '-l', instance_name])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
print("Unable to check for updates. Modpack may be out of date")
|
print("Unable to check for updates. Modpack may be out of date")
|
||||||
finally:
|
|
||||||
# Launching PrismLauncher with the instance
|
|
||||||
subprocess.run([prism_command, '-l', instance_name])
|
subprocess.run([prism_command, '-l', instance_name])
|
||||||
|
|
||||||
|
|
||||||
|
2
build-windows.sh
Executable file
2
build-windows.sh
Executable file
@ -0,0 +1,2 @@
|
|||||||
|
wine /home/piwalker/.wine/drive_c/users/piwalker/AppData/Local/Programs/Python/Python312/Scripts/pyinstaller.exe --onefile Main.py --hidden-import=customtkinter --hidden-import='PIL._tkinter_finder' --add-data "Title.png:." --windowed --add-data="C:\\users\\piwalker\\AppData\\Local\\Programs\\Python\\Python312\\Lib\\site-packages;customtkinter/"
|
||||||
|
wine /home/piwalker/.wine/drive_c/users/piwalker/AppData/Local/Programs/Python/Python312/Scripts/pyinstaller.exe --onefile Upload.py --hidden-import='PIL._tkinter_finder' --windowed
|
Loading…
Reference in New Issue
Block a user