Added failsafe to allow minecraft to launch if update server cant be
contacted
This commit is contained in:
parent
1de111ee2c
commit
2f24519015
79
Backend.py
79
Backend.py
@ -9,49 +9,52 @@ import datetime
|
|||||||
|
|
||||||
|
|
||||||
def perform_installation(instance_name, prism_command, prism_instance_path):
|
def perform_installation(instance_name, prism_command, prism_instance_path):
|
||||||
ftp = FTP("gitea.piwalker.net")
|
try:
|
||||||
ftp.login()
|
ftp = FTP("gitea.piwalker.net")
|
||||||
ftp.prot_p()
|
ftp.login()
|
||||||
|
ftp.prot_p()
|
||||||
|
|
||||||
# Fetching versions.json from FTP
|
# Fetching versions.json from FTP
|
||||||
bio = io.BytesIO()
|
bio = io.BytesIO()
|
||||||
ftp.retrbinary("RETR versions.json", bio.write)
|
ftp.retrbinary("RETR versions.json", bio.write)
|
||||||
bio.seek(0)
|
bio.seek(0)
|
||||||
versions = json.load(bio)
|
versions = json.load(bio)
|
||||||
bio.close()
|
bio.close()
|
||||||
|
|
||||||
# Checking current version
|
# Checking current version
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
version_file_path = os.path.join(prism_instance_path, instance_name, ".minecraft", "version.txt")
|
version_file_path = os.path.join(prism_instance_path, instance_name, ".minecraft", "version.txt")
|
||||||
if os.path.exists(version_file_path):
|
if os.path.exists(version_file_path):
|
||||||
with open(version_file_path, 'r') as fp:
|
with open(version_file_path, 'r') as fp:
|
||||||
version = fp.readline().rstrip()
|
version = fp.readline().rstrip()
|
||||||
|
|
||||||
# Checking if update is needed
|
# Checking if update is needed
|
||||||
if version != versions[-1]["Version"]:
|
if version != versions[-1]["Version"]:
|
||||||
print(f"Current version: {version}")
|
print(f"Current version: {version}")
|
||||||
print(f"Latest version: {versions[-1]['Version']}")
|
print(f"Latest version: {versions[-1]['Version']}")
|
||||||
|
|
||||||
# Downloading modpack
|
# Downloading modpack
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
modpack_file_path = os.path.join(temp_dir, instance_name + ".mrpack")
|
modpack_file_path = os.path.join(temp_dir, instance_name + ".mrpack")
|
||||||
with open(modpack_file_path, 'wb') as modpack:
|
with open(modpack_file_path, 'wb') as modpack:
|
||||||
ftp.retrbinary("RETR " + versions[-1]["File"], modpack.write)
|
ftp.retrbinary("RETR " + versions[-1]["File"], modpack.write)
|
||||||
|
|
||||||
|
# Running PrismLauncher with modpack
|
||||||
|
subprocess.Popen([prism_command, '-I', modpack_file_path])
|
||||||
|
|
||||||
# Running PrismLauncher with modpack
|
# Waiting for installation to complete
|
||||||
subprocess.Popen([prism_command, '-I', modpack_file_path])
|
while True:
|
||||||
|
time.sleep(5)
|
||||||
# Waiting for installation to complete
|
if os.path.exists(version_file_path):
|
||||||
while True:
|
with open(version_file_path, 'r') as fp:
|
||||||
time.sleep(5)
|
version = fp.readline().rstrip()
|
||||||
if os.path.exists(version_file_path):
|
if version == versions[-1]["Version"]:
|
||||||
with open(version_file_path, 'r') as fp:
|
break
|
||||||
version = fp.readline().rstrip()
|
except:
|
||||||
if version == versions[-1]["Version"]:
|
print("Unable to check for updates. Modpack may be out of date")
|
||||||
break
|
finally:
|
||||||
|
# Launching PrismLauncher with the instance
|
||||||
# Launching PrismLauncher with the instance
|
subprocess.run([prism_command, '-l', instance_name])
|
||||||
subprocess.run([prism_command, '-l', instance_name])
|
|
||||||
|
|
||||||
|
|
||||||
def upload_pack(username, password, version_tag, fileName):
|
def upload_pack(username, password, version_tag, fileName):
|
||||||
|
Loading…
Reference in New Issue
Block a user