added instances directory gui
This commit is contained in:
parent
8a8e1216c1
commit
1212dd49c6
144
Main.py
144
Main.py
@ -1,63 +1,133 @@
|
||||
# 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_TLS as FTP
|
||||
from ftplib import FTP
|
||||
import os
|
||||
import io
|
||||
import json
|
||||
import tempfile
|
||||
import subprocess
|
||||
import time
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
import configparser
|
||||
|
||||
# Initialize a configparser object for managing the configuration file
|
||||
config = configparser.ConfigParser()
|
||||
config_file_path = 'config.ini' # Path to the configuration file
|
||||
|
||||
|
||||
|
||||
def select_prism_instance_path():
|
||||
global prism_instance_path_entry
|
||||
directory = filedialog.askdirectory()
|
||||
prism_instance_path_entry.delete(0, tk.END)
|
||||
prism_instance_path_entry.insert(0, directory)
|
||||
|
||||
# Store the selected path in the configuration file
|
||||
config['PRISM'] = {'InstancePath': directory}
|
||||
with open(config_file_path, 'w') as configfile:
|
||||
config.write(configfile)
|
||||
|
||||
def main():
|
||||
|
||||
global prism_instance_path_entry
|
||||
|
||||
instance_name = "Familycraft Season 7"
|
||||
prism_command = "prismlauncher"
|
||||
prism_instance_path = os.getenv("HOME")+"/.local/share/PrismLauncher/instances"
|
||||
|
||||
# Default paths based on OS
|
||||
if os.name == 'nt':
|
||||
prism_command = os.getenv('LOCALAPPDATA')+"/Programs/PrismLauncher/prismlauncher.exe"
|
||||
prism_instance_path = os.getenv("APPDATA")+"/PrismLauncher/instances"
|
||||
prism_command = os.getenv('LOCALAPPDATA') + "/Programs/PrismLauncher/prismlauncher.exe"
|
||||
default_prism_instance_path = os.getenv("APPDATA") + "/PrismLauncher/instances"
|
||||
else:
|
||||
prism_command = "prismlauncher" # Update with the correct path for Linux/Mac
|
||||
default_prism_instance_path = os.getenv("HOME") + "/.local/share/PrismLauncher/instances"
|
||||
|
||||
# Load stored Prism instance path from the configuration file
|
||||
if os.path.exists(config_file_path):
|
||||
config.read(config_file_path)
|
||||
if 'PRISM' in config and 'InstancePath' in config['PRISM']:
|
||||
stored_prism_instance_path = config['PRISM']['InstancePath']
|
||||
else:
|
||||
stored_prism_instance_path = default_prism_instance_path
|
||||
else:
|
||||
stored_prism_instance_path = default_prism_instance_path
|
||||
|
||||
# GUI for selecting Prism instance path
|
||||
root = tk.Tk()
|
||||
root.title("Select Prism Instance Path")
|
||||
|
||||
# Label for instructions
|
||||
label = tk.Label(root, text="Select Prism instance path:")
|
||||
label.pack(pady=10)
|
||||
|
||||
# Entry widget for Prism instance path
|
||||
prism_instance_path_entry = tk.Entry(root, width=50)
|
||||
prism_instance_path_entry.pack(pady=5)
|
||||
|
||||
# If a stored Prism instance path exists, pre-fill the entry widget
|
||||
if stored_prism_instance_path:
|
||||
prism_instance_path_entry.insert(0, stored_prism_instance_path)
|
||||
|
||||
# Button to select directory
|
||||
select_button = tk.Button(root, text="Browse...", command=select_prism_instance_path)
|
||||
select_button.pack(pady=5)
|
||||
|
||||
# Function to proceed with installation
|
||||
def start_installation():
|
||||
prism_instance_path = prism_instance_path_entry.get()
|
||||
root.destroy() # Close the GUI window
|
||||
perform_installation(instance_name, prism_command, prism_instance_path)
|
||||
|
||||
# Button to start installation
|
||||
install_button = tk.Button(root, text="Launch Minecraft", command=start_installation)
|
||||
install_button.pack(pady=10)
|
||||
|
||||
root.mainloop()
|
||||
|
||||
def perform_installation(instance_name, prism_command, prism_instance_path):
|
||||
ftp = FTP("gitea.piwalker.net")
|
||||
ftp.login()
|
||||
ftp.prot_p()
|
||||
|
||||
# Fetching versions.json from FTP
|
||||
bio = io.BytesIO()
|
||||
ftp.retrbinary("RETR versions.json", bio.write)
|
||||
bio.seek(0)
|
||||
versions = json.load(bio)
|
||||
bio.close()
|
||||
version = "0.0.0"
|
||||
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:
|
||||
|
||||
# Checking current version
|
||||
version = "0.0.0"
|
||||
version_file_path = os.path.join(prism_instance_path, instance_name, ".minecraft", "version.txt")
|
||||
if os.path.exists(version_file_path):
|
||||
with open(version_file_path, 'r') as fp:
|
||||
version = fp.readline().rstrip()
|
||||
if version != versions[len(versions)-1]["Version"]:
|
||||
#version = versions[len(versions)-1]["Version"]
|
||||
# Update Modpack
|
||||
print(version)
|
||||
print(versions[len(versions)-1]["Version"])
|
||||
|
||||
# Checking if update is needed
|
||||
if version != versions[-1]["Version"]:
|
||||
print(f"Current version: {version}")
|
||||
print(f"Latest version: {versions[-1]['Version']}")
|
||||
|
||||
# Downloading modpack
|
||||
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()
|
||||
p = subprocess.Popen([prism_command, '-I', modpack.name])
|
||||
modpack_file_path = os.path.join(temp_dir, instance_name + ".mrpack")
|
||||
with open(modpack_file_path, 'wb') as modpack:
|
||||
ftp.retrbinary("RETR " + versions[-1]["File"], modpack.write)
|
||||
|
||||
# Running PrismLauncher with modpack
|
||||
p = subprocess.Popen([prism_command, '-I', modpack_file_path])
|
||||
|
||||
# Waiting for installation to complete
|
||||
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:
|
||||
if os.path.exists(version_file_path):
|
||||
with open(version_file_path, 'r') as fp:
|
||||
version = fp.readline().rstrip()
|
||||
if version == versions[len(versions)-1]["Version"]:
|
||||
break;
|
||||
|
||||
#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 version == versions[-1]["Version"]:
|
||||
break
|
||||
|
||||
# Launching PrismLauncher with the instance
|
||||
subprocess.run([prism_command, '-l', instance_name])
|
||||
|
||||
if __name__ == "__main__":
|
||||
main();
|
||||
main()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user