ModpackUpdater/Main.py

146 lines
5.0 KiB
Python
Raw Permalink Normal View History

2024-06-19 21:10:32 -06:00
import os
2024-06-20 07:39:09 -06:00
import tkinter as tk
from tkinter import filedialog
import configparser
2024-06-20 08:30:57 -06:00
import Backend
2024-06-20 08:23:23 -06:00
import customtkinter
from customtkinter import *
2024-06-20 10:03:48 -06:00
import PIL
from PIL import Image, ImageTk
2024-06-20 07:39:09 -06:00
# 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
2024-06-20 07:39:09 -06:00
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)
2024-06-19 21:10:32 -06:00
def main():
2024-06-20 07:39:09 -06:00
global prism_instance_path_entry
instance_name = "Test Modpack"
2024-06-19 21:10:32 -06:00
prism_command = "prismlauncher"
2024-06-20 07:39:09 -06:00
# Default paths based on OS
2024-06-19 21:10:32 -06:00
if os.name == 'nt':
2024-06-20 07:39:09 -06:00
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
2024-06-20 08:23:23 -06:00
app = CTk()
2024-06-20 18:50:01 -06:00
if os.name == 'posix':
app.attributes('-type', 'dialog')
2024-06-20 17:57:08 -06:00
app.geometry("1280x720")
2024-06-20 08:37:56 -06:00
app.title("FamilyCraft Launcher")
2024-06-20 08:23:23 -06:00
set_appearance_mode("dark")
2024-06-20 09:12:37 -06:00
set_default_color_theme("blue")
2024-06-20 17:57:08 -06:00
2024-06-20 19:00:20 -06:00
#Add a frame for the tabs
#tab_frame = CTkFrame(master=app)
#tab_frame.pack()
2024-06-20 19:00:20 -06:00
2024-06-20 08:52:24 -06:00
#Add Canvas for background and title
2024-06-20 09:18:23 -06:00
titleimage = Image.open(Backend.resource_path("Title.png"))
titlephoto = ImageTk.PhotoImage(titleimage)
season6_bg = Image.open(Backend.resource_path("CityBase.png"))
season6_scale = season6_bg.resize((1280,720))
season6_ph = ImageTk.PhotoImage(season6_scale)
bg_canvas = CTkCanvas(master=app, height=720, width=1280)
bg_canvas.pack(expand=True, fill='both')
bg_canvas.create_image(1,1, anchor=NW, image = season6_ph)
bg_canvas.create_image(130,1, anchor=NW, image = titlephoto)
2024-06-20 10:03:48 -06:00
# Tabs to seperate options from launching the game
guitabs = CTkTabview(master=bg_canvas, bg_color="#292929", corner_radius=20)
guitabs.pack(expand=True, fill='x', padx=0, pady=(0), anchor="s")
2024-06-20 08:52:24 -06:00
guitabs.add("Launcher")
guitabs.add("Options")
2024-06-20 08:23:23 -06:00
#root.title("Select Prism Instance Path")
2024-06-20 07:39:09 -06:00
# Label for instructions
label = CTkLabel(master=guitabs.tab("Options"), text="Select Prism instance path:", font=("Arial", 30))
2024-06-20 07:39:09 -06:00
label.pack(pady=10)
# Entry widget for Prism instance path
2024-06-20 08:52:24 -06:00
prism_instance_path_entry = CTkEntry(master=guitabs.tab("Options"), width=350, font=("Arial", 14))
2024-06-20 07:39:09 -06:00
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"])
2024-06-20 16:54:45 -06:00
sorted_pack_selection = sorted(options)
sorted_pack_selection.reverse()
2024-06-20 07:39:09 -06:00
# Button to select directory
modpack_var = StringVar(value="N/A")
2024-06-20 16:54:45 -06:00
#modpack_label = CTkLabel(master=guitabs.tab("Launcher"), text="Select Modpack:", font=("Impact", 30))
#modpack_label.pack()
2024-06-20 17:15:46 -06:00
modpack_selector = CTkOptionMenu(master=guitabs.tab("Launcher"), values=sorted_pack_selection, variable=modpack_var, corner_radius=20)
modpack_selector.set(options[0])
2024-06-20 16:54:45 -06:00
2024-06-20 17:15:46 -06:00
select_button = CTkButton(master=guitabs.tab("Options"), text="Browse...", command=select_prism_instance_path, corner_radius=20)
2024-06-20 07:39:09 -06:00
select_button.pack(pady=5)
# Function to proceed with installation
def start_installation():
prism_instance_path = prism_instance_path_entry.get()
2024-06-20 08:23:23 -06:00
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)
2024-06-20 07:39:09 -06:00
# Button to start installation
2024-06-20 17:15:46 -06:00
install_button = CTkButton(master=guitabs.tab("Launcher"), text="Launch Minecraft", command=start_installation, corner_radius=20)
2024-06-20 07:39:09 -06:00
install_button.pack(pady=10)
2024-06-20 16:54:45 -06:00
modpack_selector.pack(pady=20)
2024-06-20 07:39:09 -06:00
2024-06-20 08:23:23 -06:00
app.mainloop()
2024-06-20 07:39:09 -06:00
if __name__ == "__main__":
main()
2024-06-19 21:10:32 -06:00