docs: add some text

This commit is contained in:
tretrauit 2023-06-17 09:16:50 +07:00
parent 03c2c4ad38
commit e8ee174146
3 changed files with 52 additions and 0 deletions

View File

@ -1,5 +1,6 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from os import PathLike from os import PathLike
from pathlib import Path
class GameABC(ABC): class GameABC(ABC):
@ -10,6 +11,12 @@ class GameABC(ABC):
def __init__(self, path: PathLike = None): def __init__(self, path: PathLike = None):
pass pass
def data_folder(self) -> Path:
"""
Get the game data folder
"""
pass
def is_installed(self) -> bool: def is_installed(self) -> bool:
""" """
Check if the game is installed Check if the game is installed

View File

@ -9,8 +9,28 @@ class PatcherABC(ABC):
@abstractmethod @abstractmethod
def patch_game(self, game: GameABC): 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 pass
@abstractmethod @abstractmethod
def unpatch_game(self, game: GameABC): 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 pass

View File

@ -19,17 +19,28 @@ class Game(GameABC):
def path(self) -> Path | None: def path(self) -> Path | None:
return self._path return self._path
@path.setter
def path(self, path: PathLike):
self._path = Path(path)
def data_folder(self) -> Path: def data_folder(self) -> Path:
return self._path.joinpath("StarRail_Data") return self._path.joinpath("StarRail_Data")
def is_installed(self) -> bool: def is_installed(self) -> bool:
"""
Check if the game is installed.
"""
if self._path is None: if self._path is None:
return False return False
if ( if (
not self._path.joinpath("StarRail.exe").exists() not self._path.joinpath("StarRail.exe").exists()
or not self._path.joinpath("StarRailBase.dll").exists() or not self._path.joinpath("StarRailBase.dll").exists()
or not self._path.joinpath("StarRail_Data").exists()
): ):
return False return False
if self.get_version() == (0, 0, 0):
return False
return True
def get_version(self) -> tuple[int, int, int]: def get_version(self) -> tuple[int, int, int]:
""" """
@ -86,9 +97,23 @@ class Game(GameABC):
return (0, 0, 0) return (0, 0, 0)
def get_version_str(self) -> str: 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()) return ".".join(str(i) for i in self.get_version())
def get_channel(self) -> GameChannel: 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): if self.get_version() == (1, 0, 5):
for channel, v in md5sums["1.0.5"].values(): for channel, v in md5sums["1.0.5"].values():
for file, md5sum in v.values(): for file, md5sum in v.values():