diff --git a/src/leek/mod_installer.py b/src/leek/mod_installer.py index dcbde74..485d93f 100644 --- a/src/leek/mod_installer.py +++ b/src/leek/mod_installer.py @@ -29,12 +29,14 @@ class ModInstaller: if config_toml.exists() and config_toml.is_file(): # Mod can be extracted as is self.__is_flat = False + self.__check_if_already_installed() return case _: config_toml = path / "config.toml" if config_toml.exists() and config_toml.is_file(): # Mod needs to be extracted in a folder self.__is_flat = True + self.__check_if_already_installed() return # If we ever get here there's either no mod on the archive, or we failed to find it @@ -56,7 +58,7 @@ class ModInstaller: game_path: Path = GameFinder.find() if self.__is_flat: - mod_folder_name: str = self.__archive_path.stem + mod_folder_name: str = self.__get_mod_folder_name() ZipFile(self.__archive_path).extractall( path=str(game_path / "mods" / mod_folder_name) ) @@ -65,6 +67,24 @@ class ModInstaller: self.__is_installed = True + def __get_mod_folder_name(self) -> str: + mod_folder_name: str + if self.__is_flat: + mod_folder_name = self.__archive_path.stem + else: + path: ZipPath = ZipPath(ZipFile(self.__archive_path)) + things_in_root: list[ZipPath] = list(path.iterdir()) + mod_folder_name = things_in_root[0].stem + + return mod_folder_name + + def __check_if_already_installed(self) -> None: + installed_mod_path: Path = ( + GameFinder.find() / "mods" / self.__get_mod_folder_name() + ) + if installed_mod_path.exists(): + self.__is_installed = True + class UnsupportedArchiveTypeError(Exception): """