added instances directory gui
This commit is contained in:
parent
8a8e1216c1
commit
1212dd49c6
140
Main.py
140
Main.py
@ -1,63 +1,133 @@
|
|||||||
# Windows path: os.getenv('LOCALAPPDATA')/Programs/PrismLauncher/prismlauncher.exe
|
from ftplib import FTP
|
||||||
# Windows instance path: os.getenv('APPDATA')/PrismLauncher/instances
|
|
||||||
# Linux instance path: .local/share/PrismLauncher/instances
|
|
||||||
from ftplib import FTP_TLS as FTP
|
|
||||||
import os
|
import os
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import tempfile
|
import tempfile
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
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():
|
def main():
|
||||||
|
|
||||||
|
global prism_instance_path_entry
|
||||||
|
|
||||||
instance_name = "Familycraft Season 7"
|
instance_name = "Familycraft Season 7"
|
||||||
prism_command = "prismlauncher"
|
prism_command = "prismlauncher"
|
||||||
prism_instance_path = os.getenv("HOME")+"/.local/share/PrismLauncher/instances"
|
|
||||||
|
# Default paths based on OS
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
prism_command = os.getenv('LOCALAPPDATA')+"/Programs/PrismLauncher/prismlauncher.exe"
|
prism_command = os.getenv('LOCALAPPDATA') + "/Programs/PrismLauncher/prismlauncher.exe"
|
||||||
prism_instance_path = os.getenv("APPDATA")+"/PrismLauncher/instances"
|
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 = FTP("gitea.piwalker.net")
|
||||||
ftp.login()
|
ftp.login()
|
||||||
ftp.prot_p()
|
|
||||||
|
# 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
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
if os.path.exists(prism_instance_path+"/"+instance_name+"/.minecraft/version.txt"):
|
version_file_path = os.path.join(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()
|
version = fp.readline().rstrip()
|
||||||
if version != versions[len(versions)-1]["Version"]:
|
|
||||||
#version = versions[len(versions)-1]["Version"]
|
# Checking if update is needed
|
||||||
# Update Modpack
|
if version != versions[-1]["Version"]:
|
||||||
print(version)
|
print(f"Current version: {version}")
|
||||||
print(versions[len(versions)-1]["Version"])
|
print(f"Latest version: {versions[-1]['Version']}")
|
||||||
|
|
||||||
|
# Downloading modpack
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
modpack = open(os.path.join(temp_dir, instance_name+".mrpack"), 'wb')
|
modpack_file_path = os.path.join(temp_dir, instance_name + ".mrpack")
|
||||||
ftp.retrbinary("RETR "+versions[len(versions)-1]["File"], modpack.write)
|
with open(modpack_file_path, 'wb') as modpack:
|
||||||
modpack.close()
|
ftp.retrbinary("RETR " + versions[-1]["File"], modpack.write)
|
||||||
p = subprocess.Popen([prism_command, '-I', modpack.name])
|
|
||||||
|
# Running PrismLauncher with modpack
|
||||||
|
p = subprocess.Popen([prism_command, '-I', modpack_file_path])
|
||||||
|
|
||||||
|
# Waiting for installation to complete
|
||||||
while True:
|
while True:
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
if os.path.exists(prism_instance_path+"/"+instance_name+"/.minecraft/version.txt"):
|
if os.path.exists(version_file_path):
|
||||||
with open(prism_instance_path+"/"+instance_name+"/.minecraft/version.txt", 'r') as fp:
|
with open(version_file_path, 'r') as fp:
|
||||||
version = fp.readline().rstrip()
|
version = fp.readline().rstrip()
|
||||||
if version == versions[len(versions)-1]["Version"]:
|
if version == versions[-1]["Version"]:
|
||||||
break;
|
break
|
||||||
|
|
||||||
#with open(prism_instance_path+"/"+instance_name+"/version.txt", 'w') as fp:
|
# Launching PrismLauncher with the instance
|
||||||
# fp.seek(0)
|
|
||||||
# fp.truncate()
|
|
||||||
# fp.write(version)
|
|
||||||
subprocess.run([prism_command, '-l', instance_name])
|
subprocess.run([prism_command, '-l', instance_name])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main();
|
main()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user