From 56b63fe6736bc24ed3c5019966b9b1da3b791557 Mon Sep 17 00:00:00 2001 From: Toast Date: Tue, 3 Jun 2025 00:33:25 +0200 Subject: [PATCH] ModInstaller: add install method --- src/leek/mod_installer.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/leek/mod_installer.py b/src/leek/mod_installer.py index f837778..dcbde74 100644 --- a/src/leek/mod_installer.py +++ b/src/leek/mod_installer.py @@ -1,12 +1,18 @@ from pathlib import Path from zipfile import Path as ZipPath from zipfile import ZipFile, is_zipfile +from leek.utils import GameFinder class ModInstaller: + __archive_path: Path __archive_format: str + __is_flat: bool + __is_installed: bool def __init__(self, mod_path: Path) -> None: + self.__archive_path = mod_path + self.__is_installed = False if is_zipfile(mod_path): self.__archive_format = "zip" archive: ZipFile = ZipFile(mod_path) @@ -22,11 +28,13 @@ class ModInstaller: config_toml = things_in_root[0] / "config.toml" if config_toml.exists() and config_toml.is_file(): # Mod can be extracted as is + self.__is_flat = False 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 return # If we ever get here there's either no mod on the archive, or we failed to find it @@ -35,11 +43,27 @@ class ModInstaller: else: raise UnsupportedArchiveTypeError(str(mod_path)) + @property + def is_installed(self) -> bool: + return self.__is_installed + def install(self) -> None: """ Install the mod to Project Diva's mod folder """ - raise NotImplementedError + if self.__is_installed: + return + + game_path: Path = GameFinder.find() + if self.__is_flat: + mod_folder_name: str = self.__archive_path.stem + ZipFile(self.__archive_path).extractall( + path=str(game_path / "mods" / mod_folder_name) + ) + else: + ZipFile(self.__archive_path).extractall(path=str(game_path / "mods")) + + self.__is_installed = True class UnsupportedArchiveTypeError(Exception):