diff --git a/backend.py b/backend.py index a0d393e..f9802f8 100644 --- a/backend.py +++ b/backend.py @@ -1,6 +1,7 @@ import platform import requests from os import popen,remove,mkdir +import shutil from time import sleep import re import pathlib @@ -156,19 +157,35 @@ VERSION = cur_version.split('-')[0] + file = getFile(VERSION,mono) + + if file.exists() and not file.is_dir() : + popen(f"{file.as_posix()}") + return 0 + elif file.exists() and file.is_dir() : + for exe in file.iterdir() : + if re.findall('exe|x86_64|64',exe.name) and exe.is_file() : + popen(f"{exe.as_posix()}") + else : + return 1 + +def getFile(cur_version: str, mono: str) -> pathlib.Path | int : + + if not pathlib.Path(APP_PATH).exists() : + return 1 + + VERSION = cur_version.split('-')[0] + appDir = pathlib.Path(APP_PATH) if mono == 'no_mono' : for i in appDir.iterdir() : - if re.findall(VERSION,i.name) == [VERSION] and i.is_file() : - popen(f"{APP_PATH}{i.name}") - return 0 + if re.findall(f"{VERSION}-|{VERSION}_",i.name) in [[f"{VERSION}-"],[f"{VERSION}_"]] and i.is_file() : + return i else : for i in appDir.iterdir() : - if re.findall(VERSION,i.name) + re.findall('mono',i.name) == [VERSION,'mono'] and i.is_dir() : - for exe in i.iterdir() : - if re.findall('exe|x86_64|64',exe.name) and exe.is_file() : - popen(f"{APP_PATH}{i.name}/{exe.name}") + if re.findall(f"{VERSION}-|{VERSION}_",i.name) + re.findall('mono',i.name) in [[f"{VERSION}-",'mono'],[f"{VERSION}_",'mono']] and i.is_dir() : + return i return 1 @@ -182,4 +199,21 @@ if settings['appPath'] == '' or settings['token'] == '' : return False else : - return True \ No newline at end of file + return True + +def removeGodot(cur_version: str, mono: str) -> int : + if not pathlib.Path(APP_PATH).exists() : + return 1 + + VERSION = cur_version.split('-')[0] + + file = getFile(VERSION,mono) + + if file.exists() : + if file.is_file() : + remove(f"{file.as_posix()}") + else : + shutil.rmtree(file.as_posix()) + return 0 + else : + return 1 \ No newline at end of file diff --git a/main.py b/main.py index c57436f..881ec94 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,8 @@ import tkinter.filedialog as fd import backend import pathlib +import asyncio +import threading def tryDownload() -> None : if backend.checkSettings() : @@ -13,6 +15,8 @@ else : openSettings() + + isInstalled() def tryLaunch() -> None : if backend.checkSettings() : @@ -23,9 +27,40 @@ else : openSettings() +def tryRemove() -> None : + if backend.checkSettings() : + if backend.removeGodot(strvar.get(),mono.get()) == 0 : + print(f"Godot {strvar.get()} was removed.") + else : + print("Couldn't be removed.") + else : + openSettings() + + isInstalled() + def getAppDir() -> None : app_path.set(fd.askdirectory(initialdir=pathlib.Path.home(),mustexist=True)) +def isInstalled(*event) -> None : + DOWNLOAD_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Download",command=tryDownload) + REMOVE_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Remove",command=tryRemove) + + if backend.getFile(strvar.get(),mono.get()) == 1 : + try : + REMOVE_BUTTON.destroy() + except : + pass + finally : + DOWNLOAD_BUTTON.place(width=72,height=36,relx=0.34,y=380) + else : + try : + DOWNLOAD_BUTTON.destroy() + except : + pass + finally : + REMOVE_BUTTON.place(width=72,height=36,relx=0.34,y=380) + + def quit() -> None : FRONTEND.quit() @@ -35,6 +70,7 @@ backend.suddenSet(dirSetting.get(),tokenSetting.get()) VERSION_MENU.destroy() updateVersionList() + FRONTEND.event_generate('<>',when='tail') settingsWindow.destroy() settingsWindow = tk.Toplevel(FRONTEND) @@ -54,12 +90,20 @@ tokenSetting.place(height=24,width=264,x=96,y=124) tk.Button(settingsCanvas,text="Save",activebackground='#aaa',bg='#888',command=saveSettings).place(height=36,width=90,x=195,y=180) + VERSION_MENU.destroy() + updateVersionList() + FRONTEND.event_generate('<>',when='tail') + def updateVersionList() -> None : CUR_VERSION = backend.verOptions() strvar.set(CUR_VERSION[0]) VERSION_MENU = ttk.Combobox(master=CANVAS,textvariable=strvar,values=CUR_VERSION,state='readonly',font="Sans 12",style='M.TCombobox') + VERSION_MENU.bind('<>',isInstalled) + VERSION_MENU.bind('',isInstalled) VERSION_MENU.place(width=256,height=36,relx=0.31,y=120) - + +def setMono() -> None : + MONO_CHECK.event_generate('<>',when='tail') CUR_VERSION = backend.verOptions() @@ -75,12 +119,15 @@ CANVAS = tk.Canvas(FRONTEND,bg="#4811a9") LAUNCH_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Launch",command=tryLaunch) DOWNLOAD_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Download",command=tryDownload) +REMOVE_BUTTON = tk.Button(CANVAS,activebackground="#aaa",bg="#888",text="Remove",command=tryRemove) strvar = tk.StringVar(CANVAS,CUR_VERSION[0]) VERSION_MENU = ttk.Combobox(master=CANVAS,textvariable=strvar,values=CUR_VERSION,state='readonly',font="Sans 12",style='M.TCombobox') +VERSION_MENU.bind('<>',isInstalled) +VERSION_MENU.bind('',isInstalled) mono = tk.StringVar(CANVAS,'no_mono') -MONO_CHECK = tk.Checkbutton(CANVAS,text="Mono Version",bg="#7245be",fg='#000',activebackground="#804ed8",activeforeground="#000",offvalue='no_mono',onvalue='mono',variable=mono) +MONO_CHECK = tk.Checkbutton(CANVAS,text="Mono Version",bg="#7245be",fg='#000',activebackground="#804ed8",activeforeground="#000",offvalue='no_mono',onvalue='mono',variable=mono,command=isInstalled) Menubar = tk.Menu(CANVAS,type='menubar') @@ -95,9 +142,11 @@ CANVAS.place(relheight=1,relwidth=1) CANVAS.create_text(325,36,font="Sans 24",text="Godot Version Manager") LAUNCH_BUTTON.place(width=72,height=36,relx=0.55,y=380) -DOWNLOAD_BUTTON.place(width=72,height=36,relx=0.34,y=380) +isInstalled() updateVersionList() MONO_CHECK.place(width=128,height=24,relx=0.75,y=126) + +#help line #tk.Canvas(bg="#ff0000").place(relheight=1,width=2,x=325) FRONTEND.configure(menu=Menubar)