diff --git a/vollerei/abc/launcher/game.py b/vollerei/abc/launcher/game.py index 667cf3b..90ce47d 100644 --- a/vollerei/abc/launcher/game.py +++ b/vollerei/abc/launcher/game.py @@ -1,5 +1,6 @@ from abc import ABC, abstractmethod from os import PathLike +from pathlib import Path class GameABC(ABC): @@ -10,6 +11,12 @@ class GameABC(ABC): def __init__(self, path: PathLike = None): pass + def data_folder(self) -> Path: + """ + Get the game data folder + """ + pass + def is_installed(self) -> bool: """ Check if the game is installed diff --git a/vollerei/abc/patcher.py b/vollerei/abc/patcher.py index 5bb3fb7..72de8a2 100644 --- a/vollerei/abc/patcher.py +++ b/vollerei/abc/patcher.py @@ -9,8 +9,28 @@ class PatcherABC(ABC): @abstractmethod def patch_game(self, game: GameABC): + """ + Patch the game + + If the game is not installed then it'll raise `GameNotInstalledError`, if the + game version is not supported then it'll raise `VersionNotSupportedError` and + if the patching fails then it'll raise `PatchingFailedError`. + + Args: + game (Game): Game instance to patch + """ pass @abstractmethod def unpatch_game(self, game: GameABC): + """ + Unpatch the game + + This method unpatch the game by restoring backups and removing the patch files. + It'll fail if you removed the backup files, in that case you'll have to repair + the game. + + If the game is not installed then it'll raise `GameNotInstalledError` and if the + unpatching fails then it'll raise `UnpatchingFailedError`. + """ pass diff --git a/vollerei/hsr/launcher/game.py b/vollerei/hsr/launcher/game.py index 2936b8c..a550b70 100644 --- a/vollerei/hsr/launcher/game.py +++ b/vollerei/hsr/launcher/game.py @@ -19,17 +19,28 @@ class Game(GameABC): def path(self) -> Path | None: return self._path + @path.setter + def path(self, path: PathLike): + self._path = Path(path) + def data_folder(self) -> Path: return self._path.joinpath("StarRail_Data") def is_installed(self) -> bool: + """ + Check if the game is installed. + """ if self._path is None: return False if ( not self._path.joinpath("StarRail.exe").exists() or not self._path.joinpath("StarRailBase.dll").exists() + or not self._path.joinpath("StarRail_Data").exists() ): return False + if self.get_version() == (0, 0, 0): + return False + return True def get_version(self) -> tuple[int, int, int]: """ @@ -86,9 +97,23 @@ class Game(GameABC): return (0, 0, 0) def get_version_str(self) -> str: + """ + Same as get_version, but returns a string instead. + + Returns: + str: The version as a string. + """ return ".".join(str(i) for i in self.get_version()) def get_channel(self) -> GameChannel: + """ + Get the current game channel. + + Only works for Star Rail version 1.0.5, other versions will return None + + Returns: + GameChannel: The current game channel. + """ if self.get_version() == (1, 0, 5): for channel, v in md5sums["1.0.5"].values(): for file, md5sum in v.values():