ModpackUpdater/Main.py
2024-06-21 09:15:46 +10:00

134 lines
4.6 KiB
Python

import os
import tkinter as tk
from tkinter import filedialog
import configparser
import Backend
import customtkinter
from customtkinter import *
import PIL
from PIL import Image
# 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()
if not directory:
return
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 = "Test Modpack"
prism_command = "prismlauncher"
# Default paths based on OS
if os.name == 'nt':
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
app = CTk()
app.attributes('-type', 'dialog')
app.geometry("500x400")
app.title("FamilyCraft Launcher")
set_appearance_mode("dark")
set_default_color_theme("blue")
# Tabs to seperate options from launching the game
guitabs = CTkTabview(master=app, bg_color="transparent", corner_radius=20)
guitabs.pack(expand=True, fill='x', side="bottom", padx=0, pady=(20,0))
guitabs.add("Launcher")
guitabs.add("Options")
#Title image
titleimage = Image.open("Title.png")
titlelabel = CTkLabel(master=app, text="", image=CTkImage(titleimage, size=(400, 150)))
titlelabel.pack(expand=True, padx=0, pady=0)
#root.title("Select Prism Instance Path")
# Label for instructions
label = CTkLabel(master=guitabs.tab("Options"), text="Select Prism instance path:", font=("Impact", 30))
label.pack(pady=10)
# Entry widget for Prism instance path
prism_instance_path_entry = CTkEntry(master=guitabs.tab("Options"), width=350, font=("Arial", 14))
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)
options = []
modpacks = Backend.getModpacks()
for modpack in modpacks:
options.append(modpack["name"])
sorted_pack_selection = sorted(options)
sorted_pack_selection.reverse()
# Button to select directory
modpack_var = StringVar(value="N/A")
#modpack_label = CTkLabel(master=guitabs.tab("Launcher"), text="Select Modpack:", font=("Impact", 30))
#modpack_label.pack()
modpack_selector = CTkOptionMenu(master=guitabs.tab("Launcher"), values=sorted_pack_selection, variable=modpack_var, corner_radius=20)
modpack_selector.set(options[0])
select_button = CTkButton(master=guitabs.tab("Options"), text="Browse...", command=select_prism_instance_path, corner_radius=20)
select_button.pack(pady=5)
# Function to proceed with installation
def start_installation():
prism_instance_path = prism_instance_path_entry.get()
app.destroy() # Close the GUI window
for modpack in modpacks:
if modpack["name"] == modpack_var.get():
instance_name = modpack["name"]
instance_id = modpack["id"]
break
Backend.perform_installation(instance_name, prism_command, prism_instance_path, instance_id)
# Button to start installation
install_button = CTkButton(master=guitabs.tab("Launcher"), text="Launch Minecraft", command=start_installation, corner_radius=20)
install_button.pack(pady=10)
modpack_selector.pack(pady=20)
app.mainloop()
if __name__ == "__main__":
main()