From fb27bbac8456d39dcfddd901d86de0399a5c0df9 Mon Sep 17 00:00:00 2001 From: Die4Ever Date: Wed, 23 Oct 2024 14:57:35 -0500 Subject: [PATCH] installer fixes for AskKillGame order of operations --- installer/GUI/KillRunningGame.py | 38 +++++++++++++++++++------------- installer/Install/Install.py | 31 +++++++++++++++++--------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/installer/GUI/KillRunningGame.py b/installer/GUI/KillRunningGame.py index 8a6e951dd..936ae2fd8 100644 --- a/installer/GUI/KillRunningGame.py +++ b/installer/GUI/KillRunningGame.py @@ -13,32 +13,40 @@ def CopyExeTo(source:Path, dest:Path): try: CopyTo(source, dest) except PermissionError as e: - if not AskKillGame(source, dest): + if not AskKillGame(dest): raise + CopyTo(source, dest) -def AskKillGame(source:Path, dest:Path): +def AskKillGame(exe:Path): if not IsWindows(): return False - self = Path(sys.argv[0]).resolve() - if self == dest.resolve(): - info('Cannot overwrite self', dest) + selfpath = Path(sys.argv[0]).resolve() + if selfpath == exe.resolve(): + info('Cannot overwrite self', exe) messagebox.showerror('Cannot overwrite installer', 'Rename the installer file and run it again.') sys.exit(1) - cmd = ['TASKLIST', '/FI', 'imagename eq ' + dest.name] - info('running', cmd) - ret = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=30, creationflags=subprocess.CREATE_NO_WINDOW) - if 'INFO: No tasks are running which match the specified criteria.' in ret.stdout: + if not IsGameRunning(exe): return False - info('Ask kill game', dest) - resp = messagebox.askyesno('Close game?', dest.name + ' is currently running and must be closed in order to install. Would you like to close it now?\n\nYou will lose any unsaved progress.') + info('Ask kill game', exe) + resp = messagebox.askyesno('Close game?', exe.name + ' is currently running and must be closed in order to install. Would you like to close it now?\n\nYou will lose any unsaved progress.') if resp: - cmd = ['taskkill', '/F', '/IM', dest.name] - info('Killing game', dest, cmd) + cmd = ['taskkill', '/F', '/IM', exe.name] + info('Killing game', exe, cmd) subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=30, creationflags=subprocess.CREATE_NO_WINDOW) time.sleep(1) - # now try again, even if the user declines because maybe they closed the game manually - CopyTo(source, dest) + # try again, even if the user declines because maybe they closed the game manually + return True + + +def IsGameRunning(exe:Path): + if not IsWindows(): + return False # we don't care outside of Windows + cmd = ['TASKLIST', '/FI', 'imagename eq ' + exe.name] + info('running', cmd) + ret = subprocess.run(cmd, text=True, capture_output=True, check=True, timeout=30, creationflags=subprocess.CREATE_NO_WINDOW) + if 'INFO: No tasks are running which match the specified criteria.' in ret.stdout: + return False return True diff --git a/installer/Install/Install.py b/installer/Install/Install.py index f7730f5e6..ed5f2a49c 100644 --- a/installer/Install/Install.py +++ b/installer/Install/Install.py @@ -7,7 +7,7 @@ from Install import MapVariants from Install import Config from GUI.SaveMigration import SaveMigration - from GUI.KillRunningGame import CopyExeTo + from GUI.KillRunningGame import AskKillGame, CopyExeTo except Exception as e: info('ERROR: importing', e) raise @@ -77,6 +77,8 @@ def Install(exe:Path, flavors:dict, globalsettings:dict) -> dict: info('Installing flavors:', flavors, globalsettings, exe) + AskKillGame(exe) + for(f, settings) in flavors.items(): ret={} if not settings.get('install') and f != 'Vanilla': @@ -119,13 +121,6 @@ def InstallVanilla(system:Path, settings:dict, globalsettings:dict): if not settings.get('install') and not settings.get('LDDP') and not settings.get('FixVanilla'): return - if settings.get('LDDP'): - InstallLDDP(system, settings) - - # always install FemJCu because it doesn't hurt to have - FemJCu = GetSourcePath() / '3rdParty' / "FemJC.u" - CopyTo(FemJCu, system / 'FemJC.u') - exe_source = GetSourcePath() / '3rdParty' / "KentieDeusExe.exe" exetype = settings.get('exetype') kentie = True @@ -148,17 +143,25 @@ def InstallVanilla(system:Path, settings:dict, globalsettings:dict): else: info('skipping fixing of vanilla') + if settings.get('install'): + exedest:Path = system / (exename+'.exe') + CopyExeTo(exe_source, exedest) + if kentie: # kentie needs this, copy it into the regular System folder, doesn't hurt if you don't need it deusexeu = GetSourcePath() / '3rdParty' / "DeusExe.u" CopyTo(deusexeu, system / 'DeusExe.u') + if settings.get('LDDP'): + InstallLDDP(system, settings) + + # always install FemJCu because it doesn't hurt to have + FemJCu = GetSourcePath() / '3rdParty' / "FemJC.u" + CopyTo(FemJCu, system / 'FemJC.u') + if not settings.get('install'): info('skipping installation of vanilla DXRando') return - exedest:Path = system / (exename+'.exe') - CopyExeTo(exe_source, exedest) - intfile = GetSourcePath() / 'Configs' / 'DXRando.int' intdest = system / (exename+'.int') CopyTo(intfile, intdest) @@ -323,6 +326,8 @@ def InstallLDDP(system:Path, settings:dict): def InstallGMDX(system:Path, settings:dict, exename:str): game = system.parent + AskKillGame(system/'GMDX.exe') + AskKillGame(system/'GMDXv10.exe') (changes, additions) = GetConfChanges('GMDX') Mkdir(game/'SaveGMDXRando', exist_ok=True) # GMDX uses absolute path shortcuts with ini files in their arguments, so it's not as simple to copy their exe @@ -347,10 +352,12 @@ def InstallGMDX(system:Path, settings:dict, exename:str): def InstallRevision(system:Path, settings:dict): # Revision's exe is special and calls back to Steam which calls the regular Revision.exe file, so we pass in_place=True revsystem = system.parent / 'Revision' / 'System' + AskKillGame(revsystem/'Revision.exe') CreateModConfigs(revsystem, settings, 'Rev', 'Revision', in_place=True) def InstallHX(system:Path, settings:dict): + AskKillGame(system/'HX.exe') CopyPackageFiles('HX', system.parent, ['HXRandomizer.u']) (changes, additions) = GetConfChanges('HX') Mkdir(system.parent/'SaveHXRando', exist_ok=True) @@ -366,6 +373,8 @@ def CreateModConfigs(system:Path, settings:dict, modname:str, exename:str, in_pl newexepath = system / (newexename+'.exe') modpath = system.parent / (modname+'Randomizer') mapspath = modpath / 'Maps' + AskKillGame(exepath) + AskKillGame(newexepath) Mkdir(mapspath, exist_ok=True, parents=True) if not IsWindows(): in_place = True