ModInstaller: add install method
This commit is contained in:
parent
6290a18c52
commit
56b63fe673
1 changed files with 25 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue