Skip to content

Commit

Permalink
installer fixes for AskKillGame order of operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Die4Ever committed Oct 23, 2024
1 parent 0383fee commit fb27bba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
38 changes: 23 additions & 15 deletions installer/GUI/KillRunningGame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 20 additions & 11 deletions installer/Install/Install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit fb27bba

Please sign in to comment.