ModpackUpdater/Main.py

63 lines
2.3 KiB
Python
Raw Normal View History

2024-06-19 21:10:32 -06:00
# Windows path: os.getenv('LOCALAPPDATA')/Programs/PrismLauncher/prismlauncher.exe
# Windows instance path: os.getenv('APPDATA')/PrismLauncher/instances
# Linux instance path: .local/share/PrismLauncher/instances
from ftplib import FTP
import os
import io
import json
import tempfile
import subprocess
2024-06-19 21:36:55 -06:00
import time
2024-06-19 21:10:32 -06:00
def main():
instance_name = "Familycraft Season 7"
prism_command = "prismlauncher"
prism_instance_path = os.getenv("HOME")+"/.local/share/PrismLauncher/instances"
if os.name == 'nt':
prism_command = os.getenv('LOCALAPPDATA')+"/Programs/PrismLauncher/prismlauncher.exe"
prism_instance_path = os.getenv("APPDATA")+"/PrismLauncher/instances"
ftp = FTP("gitea.piwalker.net")
ftp.login()
bio = io.BytesIO()
ftp.retrbinary("RETR versions.json", bio.write)
bio.seek(0)
versions = json.load(bio)
bio.close()
version = "0.0.0"
2024-06-19 21:36:55 -06:00
if os.path.exists(prism_instance_path+"/"+instance_name+"/.minecraft/version.txt"):
with open(prism_instance_path+"/"+instance_name+"/.minecraft/version.txt", 'r') as fp:
version = fp.readline().rstrip()
2024-06-19 21:10:32 -06:00
if version != versions[len(versions)-1]["Version"]:
#version = versions[len(versions)-1]["Version"]
# Update Modpack
2024-06-19 21:36:55 -06:00
print(version)
print(versions[len(versions)-1]["Version"])
2024-06-19 21:10:32 -06:00
with tempfile.TemporaryDirectory() as temp_dir:
modpack = open(os.path.join(temp_dir, instance_name+".mrpack"), 'wb')
ftp.retrbinary("RETR "+versions[len(versions)-1]["File"], modpack.write)
modpack.close()
2024-06-19 21:36:55 -06:00
p = subprocess.Popen([prism_command, '-I', modpack.name])
while True:
time.sleep(5)
if os.path.exists(prism_instance_path+"/"+instance_name+"/.minecraft/version.txt"):
with open(prism_instance_path+"/"+instance_name+"/.minecraft/version.txt", 'r') as fp:
2024-06-19 21:38:32 -06:00
version = fp.readline().rstrip()
2024-06-19 21:36:55 -06:00
if version == versions[len(versions)-1]["Version"]:
break;
2024-06-19 21:10:32 -06:00
#with open(prism_instance_path+"/"+instance_name+"/version.txt", 'w') as fp:
# fp.seek(0)
# fp.truncate()
# fp.write(version)
subprocess.run([prism_command, '-l', instance_name])
if __name__ == "__main__":
main();