ModInstaller: check if mod is already installed
This commit is contained in:
parent
a130a23a8a
commit
0ad0b3e605
1 changed files with 21 additions and 1 deletions
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue