Compare commits
4 Commits
884236177b
...
80f1ea87d7
Author | SHA1 | Date | |
---|---|---|---|
80f1ea87d7 | |||
a9f3ee2e3e | |||
f8cfbc1100 | |||
960ba8d746 |
@ -3,6 +3,9 @@ Class wrapper for API endpoint /resource
|
||||
"""
|
||||
|
||||
|
||||
from vollerei.common.enums import VoicePackLanguage
|
||||
|
||||
|
||||
class Segment:
|
||||
"""
|
||||
A segment of the game archive.
|
||||
@ -41,7 +44,7 @@ class VoicePack:
|
||||
`name` maybe converted from `path` if the server returns empty string.
|
||||
|
||||
Attributes:
|
||||
language (str): Language of the voice pack.
|
||||
language (VoicePackLanguage): Language of the voice pack.
|
||||
name (str): Voice pack archive name.
|
||||
path (str): Voice pack download path.
|
||||
size (int): Voice pack size.
|
||||
@ -49,7 +52,7 @@ class VoicePack:
|
||||
package_size (int): Voice pack package size.
|
||||
"""
|
||||
|
||||
language: str
|
||||
language: VoicePackLanguage
|
||||
name: str
|
||||
path: str
|
||||
# str -> int
|
||||
@ -60,7 +63,7 @@ class VoicePack:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
language: str,
|
||||
language: VoicePackLanguage,
|
||||
name: str,
|
||||
path: str,
|
||||
size: int,
|
||||
@ -77,7 +80,7 @@ class VoicePack:
|
||||
@staticmethod
|
||||
def from_dict(data: dict) -> "VoicePack":
|
||||
return VoicePack(
|
||||
data["language"],
|
||||
VoicePackLanguage.from_remote_str(data["language"]),
|
||||
data["name"],
|
||||
data["path"],
|
||||
int(data["size"]),
|
||||
|
27
vollerei/common/enums.py
Normal file
27
vollerei/common/enums.py
Normal file
@ -0,0 +1,27 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class VoicePackLanguage(Enum):
|
||||
Japanese = "ja-jp"
|
||||
Chinese = "zh-cn"
|
||||
Taiwanese = "zh-tw"
|
||||
Korean = "ko-kr"
|
||||
English = "en-us"
|
||||
|
||||
@staticmethod
|
||||
def from_remote_str(s: str) -> "VoicePackLanguage":
|
||||
"""
|
||||
Converts a language string from remote server to a VoicePackLanguage enum.
|
||||
"""
|
||||
if s == "ja-jp":
|
||||
return VoicePackLanguage.Japanese
|
||||
elif s == "zh-cn":
|
||||
return VoicePackLanguage.Chinese
|
||||
elif s == "zh-tw":
|
||||
return VoicePackLanguage.Taiwanese
|
||||
elif s == "ko-kr":
|
||||
return VoicePackLanguage.Korean
|
||||
elif s == "en-us":
|
||||
return VoicePackLanguage.English
|
||||
else:
|
||||
raise ValueError(f"Invalid language string: {s}")
|
@ -13,6 +13,13 @@ _hdiff = HDiffPatch()
|
||||
def apply_update_archive(
|
||||
game: GameABC, archive_file: Path | IOBase, auto_repair: bool = True
|
||||
) -> None:
|
||||
"""
|
||||
Applies an update archive to the game, it can be the game update or a
|
||||
voicepack update.
|
||||
|
||||
Because this function is shared for all games, you should use the game's
|
||||
`apply_update_archive()` method instead.
|
||||
"""
|
||||
# Most code here are copied from worthless-launcher.
|
||||
# worthless-launcher uses asyncio for multithreading while this one uses
|
||||
# ThreadPoolExecutor, probably better for this use case.
|
||||
|
@ -224,6 +224,9 @@ class Game(GameABC):
|
||||
"""
|
||||
Gets the current installed game version as a string.
|
||||
|
||||
Because this method uses `get_version()`, you should read the docs of
|
||||
that method too.
|
||||
|
||||
Returns:
|
||||
str: The version as a string.
|
||||
"""
|
||||
@ -234,7 +237,7 @@ class Game(GameABC):
|
||||
Gets the current game channel.
|
||||
|
||||
Only works for Star Rail version 1.0.5, other versions will return the
|
||||
overridden channel or None if no channel is overridden.
|
||||
overridden channel or GameChannel.Overseas if no channel is overridden.
|
||||
|
||||
This is not needed for game patching, since the patcher will automatically
|
||||
detect the channel.
|
||||
@ -265,7 +268,17 @@ class Game(GameABC):
|
||||
# fallback to overseas.
|
||||
return self._channel_override or GameChannel.Overseas
|
||||
|
||||
def get_remote_game(self, pre_download: bool) -> resource.Game:
|
||||
def get_remote_game(self, pre_download: bool = False) -> resource.Game:
|
||||
"""
|
||||
Gets the current game information from remote.
|
||||
|
||||
Args:
|
||||
pre_download (bool): Whether to get the pre-download version.
|
||||
Defaults to False.
|
||||
|
||||
Returns:
|
||||
A `Game` object that contains the game information.
|
||||
"""
|
||||
channel = self._channel_override or self.get_channel()
|
||||
if pre_download:
|
||||
game = api.get_resource(channel=channel).pre_download_game
|
||||
@ -278,13 +291,18 @@ class Game(GameABC):
|
||||
"""
|
||||
Gets the current game update.
|
||||
|
||||
Returns a `Diff` object that contains the update information or
|
||||
None if the game is not installed or already up-to-date.
|
||||
Args:
|
||||
pre_download (bool): Whether to get the pre-download version.
|
||||
Defaults to False.
|
||||
|
||||
Returns:
|
||||
A `Diff` object that contains the update information or
|
||||
`None` if the game is not installed or already up-to-date.
|
||||
"""
|
||||
if not self.is_installed():
|
||||
return None
|
||||
version = (
|
||||
".".join(x for x in self._version_override)
|
||||
".".join(str(x) for x in self._version_override)
|
||||
if self._version_override
|
||||
else self.get_version_str()
|
||||
)
|
||||
@ -297,8 +315,13 @@ class Game(GameABC):
|
||||
"""
|
||||
Repairs a game file.
|
||||
|
||||
This will automatically handle backup and restore the file if the repair
|
||||
fails.
|
||||
|
||||
Args:
|
||||
file (PathLike): The file to repair.
|
||||
pre_download (bool): Whether to get the pre-download version.
|
||||
Defaults to False.
|
||||
"""
|
||||
if not self.is_installed():
|
||||
raise GameNotInstalledError("Game is not installed.")
|
||||
@ -340,6 +363,7 @@ class Game(GameABC):
|
||||
Args:
|
||||
archive_file (PathLike | IOBase): The archive file.
|
||||
auto_repair (bool, optional): Whether to repair the file if it's broken.
|
||||
Defaults to True.
|
||||
"""
|
||||
if not self.is_installed():
|
||||
raise GameNotInstalledError("Game is not installed.")
|
||||
@ -355,10 +379,13 @@ class Game(GameABC):
|
||||
Installs an update from a `Diff` object.
|
||||
|
||||
You may want to download the update manually and pass it to
|
||||
`apply_update_archive()` instead for better control.
|
||||
`apply_update_archive()` instead for better control, and after that
|
||||
execute `set_version_config()` to set the game version.
|
||||
|
||||
Args:
|
||||
update_info (Diff, optional): The update information. Defaults to None.
|
||||
auto_repair (bool, optional): Whether to repair the file if it's broken.
|
||||
Defaults to True.
|
||||
"""
|
||||
if not self.is_installed():
|
||||
raise GameNotInstalledError("Game is not installed.")
|
||||
|
Loading…
Reference in New Issue
Block a user