diff --git a/openGOALModLauncher.py b/openGOALModLauncher.py index 3b5d3c0..cafc3ab 100644 --- a/openGOALModLauncher.py +++ b/openGOALModLauncher.py @@ -7,7 +7,7 @@ # we will clean these up later but for now leave even unused imports -from PIL import Image +from PIL import Image from utils import launcherUtils, githubUtils import PySimpleGUI as sg import cloudscraper @@ -25,59 +25,62 @@ # Folder where script is placed, It looks in this for the Exectuable if getattr(sys, 'frozen', False): - #If we are a pyinstaller exe get the path of this file, not python + # If we are a pyinstaller exe get the path of this file, not python LauncherDir = os.path.dirname(os.path.realpath(sys.executable)) elif __file__: - #if we are running the .py directly use this path + # if we are running the .py directly use this path LauncherDir = os.path.dirname(__file__) installpath = str(LauncherDir + "\\resources\\") -#intialize default variables so they are never null +# intialize default variables so they are never null currentModderSelected = None currentModSelected = None currentModURL = None currentModImage = None steamDIR = None dirs = AppDirs(roaming=True) -#C:\Users\USERNAME\AppData\Roaming\OPENGOAL-UnofficalModLauncher\ -AppdataPATH = os.path.join(dirs.user_data_dir, "OPENGOAL-UnofficalModLauncher","") +# C:\Users\USERNAME\AppData\Roaming\OPENGOAL-UnofficalModLauncher\ +AppdataPATH = os.path.join( + dirs.user_data_dir, "OPENGOAL-UnofficalModLauncher", "") -#C:\Users\USERNAME\AppData\Roaming\OpenGOAL-Mods\ -ModFolderPATH = os.path.join(dirs.user_data_dir, "OpenGOAL-Mods","") +# C:\Users\USERNAME\AppData\Roaming\OpenGOAL-Mods\ +ModFolderPATH = os.path.join(dirs.user_data_dir, "OpenGOAL-Mods", "") # comment this out if you want to test with a local file -moddersAndModsJSON = requests.get("https://raw.githubusercontent.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/main/resources/ListOfMods.json").json() - - -j_file = json.dumps(moddersAndModsJSON) +listOfModsJSON = requests.get( + "https://raw.githubusercontent.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/main/resources/ListOfMods.json").json() +j_file = json.dumps(listOfModsJSON) # Left hand column showing installed mods installed_mods_column = [ [sg.Text("Installed Mods", font=("Helvetica", 14))], - [sg.Listbox(values=["This List is not", "Classic+"],size=(40,5),key="InstalledModListBox",enable_events=True)], + [sg.Listbox(values=["This List is not", "Classic+"], size=(40, 5), + key="InstalledModListBox", enable_events=True)], [ sg.Btn(button_text="Refresh"), sg.Btn(button_text="Uninstall"), - sg.Btn(button_text="Add to Steam",key='AddToSteam',enable_events=True) + sg.Btn(button_text="Add to Steam", + key='AddToSteam', enable_events=True) ], ] # Second half of Left Hand column letting user select mod mod_list_column = [ - [sg.Text("Available Mods", font=("Helvetica", 14))], - [sg.Text("Mod Creator")], - [sg.Combo(list(moddersAndModsJSON.keys()), enable_events=True, key='pick_modder', size=(40, 0))], - [sg.Text("Their Mods")], - [sg.Combo([], key='pick_mod', size=(40, 0),enable_events=True)], - [sg.Btn(button_text="Search Available mods",key='mod_search')] + [sg.Text("Available Mods", font=("Helvetica", 14))], + [sg.Text("Mod Creator")], + [sg.Combo(list(listOfModsJSON.keys()), enable_events=True, + key='pick_modder', size=(40, 0))], + [sg.Text("Their Mods")], + [sg.Combo([], key='pick_mod', size=(40, 0), enable_events=True)], + [sg.Btn(button_text="Search Available mods", key='mod_search')] ] # Right column showing the currently selected mod + area for user to interact mod_details_column = [ - [sg.Text("Selected Mod", font=("Helvetica", 14))], + [sg.Text("Selected Mod", font=("Helvetica", 14))], [ sg.Text("", key="-SELECTEDMOD-"), sg.Text("", key="-SELECTEDMODURL-", visible=False) @@ -86,10 +89,10 @@ [sg.Image(key="-SELECTEDMODIMAGE-")], [ sg.Btn(button_text="Launch!"), - sg.Btn(button_text="View Folder",key="ViewFolder_1"), - sg.Btn(button_text="Reinstall",key="Reinstall_1"), - sg.Btn(button_text="Uninstall",key="Uninstall_1"), - sg.Btn(button_text="View mod on github!",key="-GITHUB-_1") + sg.Btn(button_text="View Folder", key="ViewFolder_1"), + sg.Btn(button_text="Reinstall", key="Reinstall_1"), + sg.Btn(button_text="Uninstall", key="Uninstall_1"), + sg.Btn(button_text="View mod on github!", key="-GITHUB-_1") ] ] @@ -99,95 +102,103 @@ [sg.Column(installed_mods_column)], [sg.HSeparator()], [sg.Column(mod_list_column)], - ]), - sg.VSeparator(), - sg.Column(mod_details_column)] + ]), + sg.VSeparator(), + sg.Column(mod_details_column)] ] sg.theme('Python') # url to icon for the window -url= "https://raw.githubusercontent.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/main/appicon.ico" +url = "https://raw.githubusercontent.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/main/appicon.ico" jpg_data = ( - cloudscraper.create_scraper( - browser={"browser": "firefox", "platform": "windows", "mobile": False} - ) - .get(url) - .content - ) - + cloudscraper.create_scraper( + browser={"browser": "firefox", "platform": "windows", "mobile": False} + ) + .get(url) + .content +) + pil_image = Image.open(io.BytesIO(jpg_data)) png_bio = io.BytesIO() pil_image.save(png_bio, format="PNG") iconfile = png_bio.getvalue() # url to use if we have no image -url= "https://raw.githubusercontent.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/main/resources/noRepoImageERROR.png" +url = "https://raw.githubusercontent.com/OpenGOAL-Unofficial-Mods/OpenGoal-ModLauncher-dev/main/resources/noRepoImageERROR.png" jpg_data = ( - cloudscraper.create_scraper( - browser={"browser": "firefox", "platform": "windows", "mobile": False} - ) - .get(url) - .content - ) - + cloudscraper.create_scraper( + browser={"browser": "firefox", "platform": "windows", "mobile": False} + ) + .get(url) + .content +) + pil_image = Image.open(io.BytesIO(jpg_data)) png_bio = io.BytesIO() pil_image.save(png_bio, format="PNG") noimagefile = png_bio.getvalue() -window = sg.Window('OpenGOAL Mod Launcher v0.03', layout, icon = iconfile, finalize=True) -window.Element('AddToSteam').Update(visible = False) +window = sg.Window('OpenGOAL Mod Launcher v0.03', + layout, icon=iconfile, finalize=True) +window.Element('AddToSteam').Update(visible=False) + +# When we boot, start with a currently installed mod selected, if there are no installed mods, default to a featured mod. + -#When we boot, start with a currently installed mod selected, if there are no installed mods, default to a featured mod. def bootup(): - #print("BOOT") - - #installed mods + # print("BOOT") + + # installed mods if not os.path.exists(ModFolderPATH): print("Creating Mod dir: " + ModFolderPATH) os.makedirs(ModFolderPATH) - subfolders = [ f.name for f in os.scandir(ModFolderPATH) if f.is_dir() ] + subfolders = [f.name for f in os.scandir(ModFolderPATH) if f.is_dir()] if subfolders == []: subfolders = ["No Mods Installed"] - #print(subfolders) + # print(subfolders) window["InstalledModListBox"].update(subfolders) print() - + if subfolders == [] or subfolders[0] == "No Mods Installed": - #default mod selection on boot - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(noimagefile ,resize=(1,1))) + # default mod selection on boot + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(noimagefile, resize=(1, 1))) item = "Modding Community" window['pick_modder'].update(item) - title_list = [i["name"] for i in moddersAndModsJSON[item]] + title_list = [i["name"] for i in listOfModsJSON[item]] window['pick_mod'].update(value=title_list[0], values=title_list) currentModderSelected = "Modding Community" currentModSelected = "Randomizer" currentModURL = "https://github.com/OpenGOAL-Unofficial-Mods/opengoal-randomizer-mod-pack/tree/main" currentModImage = None - [currentModderSelected, currentModSelected, currentModURL, currentModImage] = handleModSelected() - + [currentModderSelected, currentModSelected, + currentModURL, currentModImage] = handleModSelected() + if subfolders != [] and subfolders[0] != "No Mods Installed": - #if there is a mod installed, use the first one in the list on boot. This can error if only a local mod is installed. - for modder in moddersAndModsJSON.keys(): - for mod in moddersAndModsJSON[modder]: - if mod["name"] == subfolders[0]: - currentMOD = modder + # if there is a mod installed, use the first one in the list on boot. This can error if only a local mod is installed. + for modder in listOfModsJSON.keys(): + for mod in listOfModsJSON[modder]: + if mod["name"] == subfolders[0]: + currentMOD = modder print(currentMOD) - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(noimagefile ,resize=(1,1))) + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(noimagefile, resize=(1, 1))) item = currentMOD window['pick_modder'].update(item) - title_list = [i["name"] for i in moddersAndModsJSON[item]] - #below is not correct but it does work. + title_list = [i["name"] for i in listOfModsJSON[item]] + # below is not correct but it does work. window['pick_mod'].update(value=subfolders[0], values=title_list) - + currentModderSelected = modder currentModSelected = subfolders[0] currentModURL = "https://github.com/OpenGOAL-Unofficial-Mods/opengoal-randomizer-mod-pack/tree/main" currentModImage = None - [currentModderSelected, currentModSelected, currentModURL, currentModImage] = handleModSelected() + [currentModderSelected, currentModSelected, + currentModURL, currentModImage] = handleModSelected() if window['-SELECTEDMOD-'].get().lower() == "local multiplayer (beta) + randomizer": - window.Element('AddToSteam').Update(visible = True) + window.Element('AddToSteam').Update(visible=True) else: - window.Element('AddToSteam').Update(visible = False) + window.Element('AddToSteam').Update(visible=False) + def handleModSelected(): tmpModderSelected = window['pick_modder'].get() @@ -196,14 +207,14 @@ def handleModSelected(): tmpModDesc = "" tmpModImage = None print("\nLoading new mod selection one moment...") - for mod in moddersAndModsJSON[tmpModderSelected]: + for mod in listOfModsJSON[tmpModderSelected]: if mod["name"] == tmpModSelected: tmpModURL = mod["URL"] if mod.get("desc"): tmpModDesc = mod["desc"] - + tmpModImage = githubUtils.returnModImageURL(tmpModURL) - + url = tmpModImage try: r = requests.head(tmpModImage).status_code @@ -212,165 +223,172 @@ def handleModSelected(): if r == 200: jpg_data = ( cloudscraper.create_scraper( - browser={"browser": "firefox", "platform": "windows", "mobile": False} + browser={"browser": "firefox", + "platform": "windows", "mobile": False} ) .get(url) .content ) - + pil_image = Image.open(io.BytesIO(jpg_data)) png_bio = io.BytesIO() pil_image.save(png_bio, format="PNG") png_data = png_bio.getvalue() - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(png_data ,resize=(250,250))) - # prints the int of the status code. Find more at httpstatusrappers.com :) + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(png_data, resize=(250, 250))) + # prints the int of the status code. Find more at httpstatusrappers.com :) else: - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(noimagefile ,resize=(250,250))) + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(noimagefile, resize=(250, 250))) print("Done Loading new mod selection") changePlayInstallButtonText() except requests.exceptions.MissingSchema: - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(noimagefile ,resize=(250,250))) + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(noimagefile, resize=(250, 250))) window['-SELECTEDMOD-'].update(tmpModSelected) window['-SELECTEDMODDESC-'].update(tmpModDesc) window['-SELECTEDMODURL-'].update(tmpModURL) - + if tmpModSelected.lower() == "local multiplayer (beta) + randomizer": - window.Element('AddToSteam').Update(visible = True) + window.Element('AddToSteam').Update(visible=True) else: - window.Element('AddToSteam').Update(visible = False) + window.Element('AddToSteam').Update(visible=False) return [tmpModderSelected, tmpModSelected, tmpModURL, tmpModImage] + def handleInstalledModSelected(): if len(window['InstalledModListBox'].get()) == 0: return [None, None] - + tmpModSelected = window['InstalledModListBox'].get()[0] tmpModderSelected = None - for modder in moddersAndModsJSON.keys(): + for modder in listOfModsJSON.keys(): if not tmpModderSelected: - for mod in moddersAndModsJSON[modder]: + for mod in listOfModsJSON[modder]: if mod["name"] == tmpModSelected: tmpModderSelected = modder break return [tmpModderSelected, tmpModSelected] + def changePlayInstallButtonText(): - subfolders = [ f.name for f in os.scandir(ModFolderPATH) if f.is_dir() ] + subfolders = [f.name for f in os.scandir(ModFolderPATH) if f.is_dir()] if not window['pick_mod'].get() in subfolders: - window['Launch!'].update('Install') - window['Uninstall'].update(disabled=True) - window['ViewFolder_1'].update(disabled=True) - window['Reinstall_1'].update(disabled=True) - window['Uninstall_1'].update(disabled=True) + window['Launch!'].update('Install') + window['Uninstall'].update(disabled=True) + window['ViewFolder_1'].update(disabled=True) + window['Reinstall_1'].update(disabled=True) + window['Uninstall_1'].update(disabled=True) else: window['Launch!'].update('Launch!') window['Uninstall'].update(disabled=False) window['ViewFolder_1'].update(disabled=False) window['Reinstall_1'].update(disabled=False) window['Uninstall_1'].update(disabled=False) - + def refreshInstalledList(): - subfolders = [ f.name for f in os.scandir(ModFolderPATH) if f.is_dir() ] + subfolders = [f.name for f in os.scandir(ModFolderPATH) if f.is_dir()] window["InstalledModListBox"].update(subfolders) + def open_steamPrompt(): - filelayout = [ [sg.FolderBrowse("Select Steam Directory",enable_events=True,key="PICKSTEAMDIR")]] - filewindow = sg.Window('Search for offered mods', filelayout, keep_on_top=True,icon = iconfile, size=window.size,location = window.CurrentLocation()) - + filelayout = [[sg.FolderBrowse( + "Select Steam Directory", enable_events=True, key="PICKSTEAMDIR")]] + filewindow = sg.Window('Search for offered mods', filelayout, keep_on_top=True, + icon=iconfile, size=window.size, location=window.CurrentLocation()) + # Event Loop while True: - event, values = filewindow.read() - print(event) + event, values = filewindow.read() + print(event) + print(values[event]) + if event in (sg.WIN_CLOSED, 'Exit'): # always check for closed window + break + if exists(values[event]+"/steam.exe"): + print("FOUND STEAM DIR") print(values[event]) - if event in (sg.WIN_CLOSED, 'Exit'): # always check for closed window - break - if exists(values[event]+"/steam.exe"): - print("FOUND STEAM DIR") - print(values[event]) - steamDIR = values[event] - print(steamDIR) - filewindow.close() - return steamDIR - else: - sg.popup("Did not find Steam install Directory try again",keep_on_top=True) - - - + steamDIR = values[event] + print(steamDIR) + filewindow.close() + return steamDIR + else: + sg.popup("Did not find Steam install Directory try again", + keep_on_top=True) + else: filewindow.close() - def open_search(): names = [] - for modder in moddersAndModsJSON.keys(): - for mod in moddersAndModsJSON[modder]: + for modder in listOfModsJSON.keys(): + for mod in listOfModsJSON[modder]: if not mod["name"] in names: - names.append(mod["name"]) - - + names.append(mod["name"]) layout = [[sg.Text('Search for offered mods')], - [sg.Input(size=window.size, enable_events=True, key='-INPUT-')], - [sg.Listbox(names, size=window.size, enable_events=True, key='-LIST-')], - [sg.Button('Chrome'), sg.Button('Exit')]] + [sg.Input(size=window.size, enable_events=True, key='-INPUT-')], + [sg.Listbox(names, size=window.size, + enable_events=True, key='-LIST-')], + [sg.Button('Chrome'), sg.Button('Exit')]] - window2 = sg.Window('Search for offered mods', layout, keep_on_top=True,icon = iconfile, size=window.size,location = window.CurrentLocation()) + window2 = sg.Window('Search for offered mods', layout, keep_on_top=True, + icon=iconfile, size=window.size, location=window.CurrentLocation()) # Event Loop while True: event, values = window2.read() if event in (sg.WIN_CLOSED, 'Exit'): # always check for closed window break - if values['-INPUT-'] != '': # if a keystroke entered in search field + # if a keystroke entered in search field + if values['-INPUT-'] != '': search = values['-INPUT-'].lower() - new_values = [x for x in names if search.lower() in x.lower()] # do the filtering + # do the filtering + new_values = [x for x in names if search.lower() in x.lower()] window2['-LIST-'].update(new_values) # display in the listbox - - + print(len(values['-LIST-'])) if event == '-LIST-': print(values['-LIST-'][0]) print("was CLICKED!") currentMOD = "unkown" - p=0 - for modder in moddersAndModsJSON.keys(): - - for mod in moddersAndModsJSON[modder]: - - print(mod["name"]) - print(values['-LIST-'][0]) - if mod["name"].lower() == values['-LIST-'][0].lower(): - print("MATCH") - indexOfMod = p - currentMOD = modder - + p = 0 + for modder in listOfModsJSON.keys(): + + for mod in listOfModsJSON[modder]: + + print(mod["name"]) + print(values['-LIST-'][0]) + if mod["name"].lower() == values['-LIST-'][0].lower(): + print("MATCH") + indexOfMod = p + currentMOD = modder + print(currentMOD) item = currentMOD window['pick_modder'].update(item) - - title_list = [i["name"] for i in moddersAndModsJSON[item]] - p=-1 + + title_list = [i["name"] for i in listOfModsJSON[item]] + p = -1 for title in title_list: - p=p+1 - + p = p+1 + if title == values['-LIST-'][0]: print("MATCH") indexOfMod = p - - window['pick_mod'].update(value=title_list[indexOfMod], values=title_list) + + window['pick_mod'].update( + value=title_list[indexOfMod], values=title_list) handleModSelected() window2.close() - #sg.popup('Selected ', values['-LIST-'], keep_on_top=True,icon = iconfile) - + # sg.popup('Selected ', values['-LIST-'], keep_on_top=True,icon = iconfile) - else: # display original unfiltered list window2['-LIST-'].update(names) @@ -380,30 +398,31 @@ def open_search(): print(values['-LIST-'][0]) print("was CLICKED!") currentMOD = "unkown" - for modder in moddersAndModsJSON.keys(): - for mod in moddersAndModsJSON[modder]: - print(mod["name"]) - print(values['-LIST-'][0]) - if mod["name"].lower() == values['-LIST-'][0].lower(): - print("MATCH") - currentMOD = modder + for modder in listOfModsJSON.keys(): + for mod in listOfModsJSON[modder]: + print(mod["name"]) + print(values['-LIST-'][0]) + if mod["name"].lower() == values['-LIST-'][0].lower(): + print("MATCH") + currentMOD = modder print(currentMOD) item = currentMOD window['pick_modder'].update(item) - - title_list = [i["name"] for i in moddersAndModsJSON[item]] - p=-1 + + title_list = [i["name"] for i in listOfModsJSON[item]] + p = -1 for title in title_list: - p=p+1 - + p = p+1 + if title == values['-LIST-'][0]: print("MATCH") indexOfMod = p - - window['pick_mod'].update(value=title_list[indexOfMod], values=title_list) + + window['pick_mod'].update( + value=title_list[indexOfMod], values=title_list) handleModSelected() window2.close() - #sg.popup('Selected ', values['-LIST-'], keep_on_top=True,icon = iconfile) + # sg.popup('Selected ', values['-LIST-'], keep_on_top=True,icon = iconfile) window2.close() @@ -417,46 +436,51 @@ def open_search(): if event == "Exit" or event == sg.WIN_CLOSED: break - + # Folder name was filled in, make a list of files in the folder if event == "InstalledModListBox" and not window["InstalledModListBox"].get() == ['No Mods Installed']: [tmpModderSelected, tmpModSelected] = handleInstalledModSelected() if not tmpModderSelected: - sg.Popup('Installed mod not found in available mods!', keep_on_top=True, icon = iconfile) + sg.Popup('Installed mod not found in available mods!', + keep_on_top=True, icon=iconfile) window['-SELECTEDMOD-'].update(tmpModSelected) window['-SELECTEDMODDESC-'].update("") window['-SELECTEDMODURL-'].update("") local_img = launcherUtils.local_mod_image(tmpModSelected) if local_img: - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(local_img ,resize=(250,250))) + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(local_img, resize=(250, 250))) else: - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(noimagefile ,resize=(250,250))) + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(noimagefile, resize=(250, 250))) else: window['pick_modder'].update(tmpModderSelected) - title_list = [i["name"] for i in moddersAndModsJSON[tmpModderSelected]] + title_list = [i["name"] + for i in listOfModsJSON[tmpModderSelected]] window['pick_mod'].update(value=tmpModSelected, values=title_list) - + handleModSelected() elif event == "Refresh": refreshInstalledList() if (len(window['InstalledModListBox'].get())) == 0: bootup() - elif event =='pick_modder': - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(noimagefile ,resize=(1,1))) + elif event == 'pick_modder': + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(noimagefile, resize=(1, 1))) item = values[event] print("\nChaning to this modder") print(item) print("Done!") - title_list = [i["name"] for i in moddersAndModsJSON[item]] + title_list = [i["name"] for i in listOfModsJSON[item]] window['pick_mod'].update(value=title_list[0], values=title_list) handleModSelected() - elif event =='pick_mod': + elif event == 'pick_mod': handleModSelected() elif event == 'mod_search': open_search() - + elif event == "Launch!": tmpModSelected = window['-SELECTEDMOD-'].get() tmpModURL = window['-SELECTEDMODURL-'].get() @@ -467,29 +491,29 @@ def open_search(): window['Launch!'].update('Updating...') [linkType, tmpModURL] = githubUtils.identifyLinkType(tmpModURL) launcherUtils.launch(tmpModURL, tmpModSelected, linkType) - #turn the button back on + # turn the button back on window['Launch!'].update('Launch!') window['Launch!'].update(disabled=False) - #may have installed new mod, update list + # may have installed new mod, update list refreshInstalledList() elif tmpModSelected: # local launch window['Launch!'].update(disabled=True) err = launcherUtils.launch_local(tmpModSelected) if err: - sg.popup("Error: " + err, icon = iconfile) - #turn the button back on + sg.popup("Error: " + err, icon=iconfile) + # turn the button back on window['Launch!'].update(disabled=False) else: bootup() - sg.Popup('No mod selected', keep_on_top=True, icon = iconfile) + sg.Popup('No mod selected', keep_on_top=True, icon=iconfile) elif event == "ViewFolder_1": tmpModSelected = window['-SELECTEDMOD-'].get() tmpModURL = window['-SELECTEDMODURL-'].get() - subfolders = [ f.name for f in os.scandir(ModFolderPATH) if f.is_dir() ] + subfolders = [f.name for f in os.scandir(ModFolderPATH) if f.is_dir()] if subfolders == []: subfolders = ["No Mods Installed"] - + if tmpModSelected and not tmpModSelected == "No Mods Installed" and tmpModSelected in subfolders: print(tmpModSelected) dir = dirs.user_data_dir + "\\OpenGOAL-Mods\\" + tmpModSelected @@ -497,18 +521,20 @@ def open_search(): else: if (len(window['InstalledModListBox'].get())) == 0: bootup() - sg.Popup('No installed mod selected', keep_on_top=True,icon = iconfile) + sg.Popup('No installed mod selected', + keep_on_top=True, icon=iconfile) elif event == "Reinstall_1": tmpModSelected = window['-SELECTEDMOD-'].get() tmpModURL = window['-SELECTEDMODURL-'].get() - subfolders = [ f.name for f in os.scandir(ModFolderPATH) if f.is_dir() ] + subfolders = [f.name for f in os.scandir(ModFolderPATH) if f.is_dir()] if subfolders == []: subfolders = ["No Mods Installed"] - + if tmpModSelected and not tmpModSelected == "No Mods Installed" and tmpModSelected in subfolders: print(tmpModSelected) dir = dirs.user_data_dir + "\\OpenGOAL-Mods\\" + tmpModSelected - ans = sg.popup_ok_cancel('Confirm: reinstalling ' + dir + " \n\nNote: this will re-extract texture_replacements too",icon = iconfile) + ans = sg.popup_ok_cancel('Confirm: reinstalling ' + dir + + " \n\nNote: this will re-extract texture_replacements too", icon=iconfile) if ans == 'OK': launcherUtils.reinstall(tmpModSelected) refreshInstalledList() @@ -517,18 +543,20 @@ def open_search(): else: if (len(window['InstalledModListBox'].get())) == 0: bootup() - sg.Popup('No installed mod selected', keep_on_top=True,icon = iconfile) - elif event == "Uninstall" or event =="Uninstall_1": + sg.Popup('No installed mod selected', + keep_on_top=True, icon=iconfile) + elif event == "Uninstall" or event == "Uninstall_1": tmpModSelected = window['-SELECTEDMOD-'].get() tmpModURL = window['-SELECTEDMODURL-'].get() - subfolders = [ f.name for f in os.scandir(ModFolderPATH) if f.is_dir() ] + subfolders = [f.name for f in os.scandir(ModFolderPATH) if f.is_dir()] if subfolders == []: subfolders = ["No Mods Installed"] - + if tmpModSelected and not tmpModSelected == "No Mods Installed" and tmpModSelected in subfolders: print(tmpModSelected) dir = dirs.user_data_dir + "\\OpenGOAL-Mods\\" + tmpModSelected - ans = sg.popup_ok_cancel('Confirm: uninstalling ' + dir ,icon = iconfile) + ans = sg.popup_ok_cancel( + 'Confirm: uninstalling ' + dir, icon=iconfile) if ans == 'OK': launcherUtils.try_remove_dir(dir) refreshInstalledList() @@ -537,14 +565,16 @@ def open_search(): window['-SELECTEDMOD-'].update("") window['-SELECTEDMODDESC-'].update("") window['-SELECTEDMODURL-'].update("") - window['-SELECTEDMODIMAGE-'].update(githubUtils.resize_image(noimagefile ,resize=(1,1))) - sg.popup('Uninstalled ' + tmpModSelected,icon = iconfile) + window['-SELECTEDMODIMAGE-'].update( + githubUtils.resize_image(noimagefile, resize=(1, 1))) + sg.popup('Uninstalled ' + tmpModSelected, icon=iconfile) if (len(window['InstalledModListBox'].get())) == 0: bootup() else: if (len(window['InstalledModListBox'].get())) == 0: bootup() - sg.Popup('No installed mod selected', keep_on_top=True,icon = iconfile) + sg.Popup('No installed mod selected', + keep_on_top=True, icon=iconfile) elif event == "-GITHUB-_1": window = window.refresh() url = window['-SELECTEDMODURL-'].get() @@ -558,34 +588,41 @@ def open_search(): else: print("trying to find it") steamDIR = open_steamPrompt() - + if exists(steamDIR + "\steamapps\common\Play With Gilbert"): print("FOUND GILBERT") if sg.PopupYesNo('Do you want to replace Play With Gilbert with the unoffical Mod Launcher?') == "Yes": print("Preparing to replace Gilbert") - launcherUtils.try_remove_file(steamDIR + "\steamapps\common\Play With Gilbert\PlayWithGilbert.exe") + launcherUtils.try_remove_file( + steamDIR + "\steamapps\common\Play With Gilbert\PlayWithGilbert.exe") autoUpdaterURL = "https://github.com/OpenGOAL-Unofficial-Mods/OpenGOAL-Unofficial-Mods.github.io/raw/main/Launcher%20with%20autoupdater.exe" print("Downloading update from " + autoUpdaterURL) file = urllib.request.urlopen(autoUpdaterURL) print() print(str("File size is ") + str(file.length)) - urllib.request.urlretrieve(autoUpdaterURL, "PlaywithGilbert.exe", launcherUtils.show_progress) + urllib.request.urlretrieve( + autoUpdaterURL, "PlaywithGilbert.exe", launcherUtils.show_progress) print("Done downloading") print("moving to steam") - shutil.move("PlaywithGilbert.exe", steamDIR + "\steamapps\common\Play With Gilbert\\") + shutil.move("PlaywithGilbert.exe", steamDIR + + "\steamapps\common\Play With Gilbert\\") if sg.PopupYesNo('Do you ever want to play the real Play with Gilbert') == "Yes": sg.Popup("Ok we will leave the Play with Gilbert files") else: - sg.Popup("Ok removing the play with gilbert game files to save space. ( :( )") - launcherUtils.try_remove_dir(steamDIR + "\steamapps\common\Play With Gilbert\Engine") - launcherUtils.try_remove_dir(steamDIR + "\steamapps\common\Play With Gilbert\PWG_2020") - sg.Popup("Mod Launcher added to steam, launch by playing \"Play with Gilbert\" in Steam.") + sg.Popup( + "Ok removing the play with gilbert game files to save space. ( :( )") + launcherUtils.try_remove_dir( + steamDIR + "\steamapps\common\Play With Gilbert\Engine") + launcherUtils.try_remove_dir( + steamDIR + "\steamapps\common\Play With Gilbert\PWG_2020") + sg.Popup( + "Mod Launcher added to steam, launch by playing \"Play with Gilbert\" in Steam.") else: sg.Popup("Understandable") - + else: - sg.Popup("Did not find play with gilbert please download from " + "https://store.steampowered.com/app/1359630/Play_With_Gilbert__A_Small_Tail" , keep_on_top=True,icon = iconfile) - + sg.Popup("Did not find play with gilbert please download from " + + "https://store.steampowered.com/app/1359630/Play_With_Gilbert__A_Small_Tail", keep_on_top=True, icon=iconfile) -window.close() +window.close() diff --git a/resources/appicon.ico b/resources/appicon.ico new file mode 100644 index 0000000..4bf2849 Binary files /dev/null and b/resources/appicon.ico differ diff --git a/utils/launcherUtils.py b/utils/launcherUtils.py index 9f25b47..76a7d9e 100644 --- a/utils/launcherUtils.py +++ b/utils/launcherUtils.py @@ -173,6 +173,35 @@ def reinstall(MOD_NAME): #try_remove_dir(InstallDir + "/data/iso_data") #os.symlink("" + UniversalIsoPath +"", InstallDir + "/data/iso_data") +def replaceText(path, search_text, replace_text): + # creating a variable and storing the discord RPC text, + # if the mod has changed this then we leave it as the modder wanted. + # that we want to search + + # creating a variable and storing the mod name we want to display + # in discord RPC + + # Opening our pckernel file in read only + # mode using the open() function + with open(path, 'r') as file: + + # Reading the content of the pckernel file + # using the read() function and storing + # them in a new variable + data = file.read() + + # Searching and replacing the text + # using the replace() function + data = data.replace(search_text, replace_text) + + # Opening our pckernel file in write only + # mode to write the replaced content + with open(path, 'w') as file: + + # Writing the replaced data in our + # pckernel file + file.write(data) + def launch(URL, MOD_NAME, LINK_TYPE): if URL is None: return @@ -301,39 +330,9 @@ def launch(URL, MOD_NAME, LINK_TYPE): shutil.move(SubDir + "/" + f, InstallDir + "/" + f) try_remove_dir(TempDir) - - - - # creating a variable and storing the discord RPC text, - # if the mod has changed this then we leave it as the modder wanted. - # that we want to search - search_text = "Playing Jak and Daxter: The Precursor Legacy" - - # creating a variable and storing the mod name we want to display - # in discord RPC - replace_text = MOD_NAME - - # Opening our pckernel file in read only - # mode using the open() function - with open(InstallDir + r'\data\goal_src\jak1\pc\pckernel.gc', 'r') as file: - - # Reading the content of the pckernel file - # using the read() function and storing - # them in a new variable - data = file.read() - - # Searching and replacing the text - # using the replace() function - data = data.replace(search_text, replace_text) - - # Opening our pckernel file in write only - # mode to write the replaced content - with open(InstallDir + r'\data\goal_src\jak1\pc\pckernel.gc', 'w') as file: - - # Writing the replaced data in our - # pckernel file - file.write(data) - + replaceText(InstallDir + r'\data\goal_src\jak1\pc\pckernel.gc',"Playing Jak and Daxter: The Precursor Legacy", MOD_NAME) + replaceText(InstallDir + r'\data\goal_src\jak1\pc\pckernel.gc',"/pc-settings.gc", r"/"+MOD_NAME+"-settings.gc") + #if extractOnUpdate is True, check their ISO_DATA folder #Close Gk and goalc if they were open.