コード例 #1
0
ファイル: cli.py プロジェクト: nbusseneau/hephaistos
    def __configure_hades_dir(self, hades_dir_arg: str) -> None:
        # if we are on macOS and running PyInstaller executable and defaulting
        # to current directory, force working directory to be the one containing
        # the executable
        # this is a kludge around macOS calling executables from the user home
        # rather than the current directory when double-clicked on from Finder
        if config.platform == Platform.MACOS and getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS') and hades_dir_arg == '.':
            hades_dir_arg = Path(sys.argv[0]).parent
            LOGGER.debug(f"Running macOS executable from Finder: forced working directory to {hades_dir_arg}")
        config.hades_dir = Path(hades_dir_arg)
        try:
            helpers.is_valid_hades_dir(config.hades_dir)
            config.content_dir = config.hades_dir.joinpath(CONTENT_DIR_PATH[config.platform])
            LOGGER.debug(f"Detected platform: {config.platform}")
        except HadesNotFound as e:
            LOGGER.error(e)
            hades_dirs = helpers.try_detect_hades_dirs()
            if len(hades_dirs) > 0:
                advice = '\n'.join(f"  - {hades_dir}" for hades_dir in hades_dirs)
            else:
                advice = "  - Could not auto-detect any Hades directory."
            msg = f"""Hephaistos does not seem to be located in the Hades directory:
{advice}
Please move Hephaistos directly to the Hades directory.

If you know what you're doing, you can also re-run with '--hades-dir' to manually specify Hades directory while storing Hephaistos elsewhere."""
            LOGGER.error(msg)
            self.__end(1, prompt_user=config.interactive_mode)
コード例 #2
0
ファイル: cli.py プロジェクト: nbusseneau/hephaistos
    def handler(self, width: int, height: int, scaling: Scaling, hud: HUD, custom_resolution: bool, force: bool, **kwargs) -> None:
        """Compute viewport depending on arguments, then patch all needed files and install Lua mod.
        If using '--force', discard backups, hashes and SJSON data, and uninstall Lua mod."""
        helpers.configure_screen_variables(width, height, scaling)
        LOGGER.info(f"Using resolution: {config.resolution.width, config.resolution.height}")
        LOGGER.info(f"Using '--scaling={scaling}': computed patch viewport {config.new_screen.width, config.new_screen.height}")

        config.center_hud = True if hud == HUD.CENTER else False
        msg = f"Using '--hud={hud}': HUD will be kept in the center of the screen" if config.center_hud else f"Using '--hud={hud}': HUD will be expanded horizontally"
        LOGGER.info(msg)

        if not custom_resolution:
            LOGGER.info("Using '--no-custom-resolution': will not bypass monitor resolution detection")
        config.custom_resolution = custom_resolution

        if force:
            LOGGER.info("Using '--force': will repatch on top of existing files in case of hash mismatch and store new backups / hashes")
            config.force = True

        # run 'modimporter --clean' (if available) to restore everything before patching
        if config.modimporter:
            LOGGER.info(f"Running 'modimporter --clean' to restore original state before patching")
            helpers.run_modimporter(config.modimporter, clean_only=True) 

        try:
            patchers.patch_engines()
            patchers.patch_sjsons()
            patchers.patch_profile_sjsons()
            lua_mod.install()
        except hashes.HashMismatch as e:
            LOGGER.error(e)
            if config.interactive_mode:
                LOGGER.error("It looks like the game was updated. Do you wish to discard previous backups and re-patch Hades from its current state?")
                choice = interactive.pick(options=['Yes', 'No',], add_option=None)
                if choice == 'Yes':
                    self.handler(width, height, scaling, hud, custom_resolution, force=True)
            else:
                LOGGER.error("Was the game updated? Re-run with '--force' to discard previous backups and re-patch Hades from its current state.")
        except (LookupError, FileExistsError) as e:
            LOGGER.error(e)