diff --git a/backend.py b/backend.py index f9802f8..5cdb407 100644 --- a/backend.py +++ b/backend.py @@ -6,7 +6,6 @@ import re import pathlib import json -import tkinter.filedialog as fd def getArch() -> str : arch = platform.machine() @@ -58,9 +57,11 @@ # Get the versions of the Godot Engine and sort them from latest to oldest -def verOptions() -> list: +def verOptions(mono: str) -> list: tag_list = [] response = requestGitHubInfo() + installed_files = getAllFiles(mono) + installed_files.sort(reverse=True) if type(response) == dict : return ['No options available'] @@ -72,6 +73,8 @@ if tag_list != [] : tag_list.pop() + elif installed_files != [] : + tag_list = installed_files else : tag_list.append('No options available') @@ -182,13 +185,41 @@ for i in appDir.iterdir() : if re.findall(f"{VERSION}-|{VERSION}_",i.name) in [[f"{VERSION}-"],[f"{VERSION}_"]] and i.is_file() : return i - else : + elif mono == 'mono' : for i in appDir.iterdir() : 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 +def getAllFiles(mono: str) -> list : + if not pathlib.Path(APP_PATH).exists() : + return [] + + files = [] + + appDir = pathlib.Path(APP_PATH) + + if mono == 'no_mono' : + for i in appDir.iterdir() : + if re.findall("-stable|_stable",i.name) in [["-stable"],["_stable"]] and i.is_file() : + if re.findall("_stable",i.name) in ["_stable"] : + i.name.replace("_stable","-stable") + + files.append(re.findall("[1-9].+-stable",i.name)[0]) + elif mono == 'mono' : + for i in appDir.iterdir() : + if re.findall("-stable|_stable",i.name) + re.findall('mono',i.name) in [["-stable",'mono'],["_stable",'mono']] and i.is_dir() : + if re.findall("_stable",i.name) in ["_stable"] : + i.name.replace("_stable","-stable") + + files.append(re.findall("[1-9].+-stable",i.name)[0]) + + if files != [] : + return files + else : + return [] + def suddenSet(appPath: str, token: str) -> None : open(f"{APPDATA}settings.json",'w').write(json.dumps({'appPath':appPath,'token':token})) updateSettings(appPath,token) diff --git a/main.py b/main.py index 881ec94..f1bfb25 100644 --- a/main.py +++ b/main.py @@ -3,8 +3,6 @@ import tkinter.filedialog as fd import backend import pathlib -import asyncio -import threading def tryDownload() -> None : if backend.checkSettings() : @@ -42,6 +40,10 @@ app_path.set(fd.askdirectory(initialdir=pathlib.Path.home(),mustexist=True)) def isInstalled(*event) -> None : + global CUR_VERSION + if CUR_VERSION != backend.verOptions(mono.get()) : + updateVersionList() + 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) @@ -95,7 +97,8 @@ FRONTEND.event_generate('<>',when='tail') def updateVersionList() -> None : - CUR_VERSION = backend.verOptions() + global CUR_VERSION + CUR_VERSION = backend.verOptions(mono.get()) 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) @@ -105,8 +108,6 @@ def setMono() -> None : MONO_CHECK.event_generate('<>',when='tail') -CUR_VERSION = backend.verOptions() - FRONTEND = tk.Tk() FRONTEND.geometry("650x480") FRONTEND.resizable(False,False) @@ -121,12 +122,15 @@ 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) +mono = tk.StringVar(CANVAS,'no_mono') + +CUR_VERSION = backend.verOptions(mono.get()) + 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,command=isInstalled) Menubar = tk.Menu(CANVAS,type='menubar')