installer/interpreter: Refactor and address issues raised in code review.

This commit is contained in:
Tom Todd 2018-10-10 20:17:01 +01:00 committed by Mathieu Comandon
parent e464b87d4e
commit 21f5762964

View file

@ -532,34 +532,36 @@ class ScriptInterpreter(CommandsMixin):
# ----------------
def _finish_install(self):
exe = self.script.get('game').get('exe')
if not exe is None:
path = self._substitute(exe)
game = self.script.get('game')
launcher, launcher_value = self._find_launcher_in_script(game)
if game:
launcher_value = game.get('exe')
if launcher_value:
path = self._substitute(launcher_value)
if not os.path.isabs(path):
path = os.path.join(self.target_path, exe)
path = os.path.join(self.target_path, launcher_value)
if not os.path.isfile(path):
if path and not os.path.isfile(path):
self.parent.set_status("Installation didn't complete successfully")
self.parent.on_install_error("Installation failed (specified"
" executable not found)!")
return
else:
self.parent.set_status("Writing configuration")
self._write_config()
self.parent.set_status("Installation finished !")
self.parent.on_install_finished()
self.parent.set_status("Writing configuration")
self._write_config()
self.parent.set_status("Installation finished !")
self.parent.on_install_finished()
def _get_game_launcher(self):
def _get_game_launcher(self, script):
"""Return the key and value of the launcher"""
launcher_value = None
# exe64 can be provided to specify an executable for 64bit systems
exe = 'exe64' if 'exe64' in self.script and system.IS_64BIT else 'exe'
exe = 'exe64' if 'exe64' in script and system.IS_64BIT else 'exe'
for launcher in [exe, 'iso', 'rom', 'disk', 'main_file']:
if launcher not in self.script:
if launcher not in script:
continue
launcher_value = self.script[launcher]
launcher_value = script[launcher]
if launcher == "exe64":
launcher = "exe" # If exe64 is used, rename it to exe
@ -623,7 +625,7 @@ class ScriptInterpreter(CommandsMixin):
# Game options such as exe or main_file can be added at the root of the
# script as a shortcut, this integrates them into the game config
# properly
launcher, launcher_value = self._get_game_launcher()
launcher, launcher_value = self._get_game_launcher(self.script)
if type(launcher_value) == list:
game_files = []
for game_file in launcher_value: