Skip to content

Commit

Permalink
Fixed authkey being always on time out (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
nitolar authored Sep 28, 2023
1 parent e524719 commit 509af83
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions genshin/utility/logfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,36 @@
# ~/AppData/LocalLow/Cognosphere/Star Rail/Player.log
# ~/AppData/LocalLow/miHoYo/崩坏:星穹铁道/output_log.txt
# data_2
# C:/Program Files/Genshin Impact/Genshin Impact game/GenshinImpact_Data/webCaches/Cache/Cache_Data/data_2
# C:/Program Files/Genshin Impact/Genshin Impact game/YuanShen_Data/webCaches/Cache/Cache_Data/data_2
# C:/Program Files/Star Rail/StarRail_Data/webCaches/Cache/Cache_Data/data_2
# C:/Program Files/Star Rail/StarRail_Data/webCaches/Cache/Cache_Data/data_2
# C:/Program Files/Genshin Impact/Genshin Impact game/GenshinImpact_Data/webCaches/2.16.0.0/Cache/Cache_Data/data_2
# C:/Program Files/Genshin Impact/Genshin Impact game/YuanShen_Data/webCaches/2.16.0.0/Cache/Cache_Data/data_2
# C:/Program Files/Star Rail/StarRail_Data/webCaches/2.15.0.0/Cache/Cache_Data/data_2
# C:/Program Files/Star Rail/StarRail_Data/webCaches/2.15.0.0/Cache/Cache_Data/data_2


def _search_output_log(content: str) -> pathlib.Path:
"""Search output log for data_2."""
match = re.search(r"(?<=\s)(\S+?_Data)(?:/data.unity3d)?", content, re.MULTILINE)
if match is None:
raise FileNotFoundError("No genshin installation location in logfile")

data_location = pathlib.Path(match[1]) / "webCaches/Cache/Cache_Data/data_2"
match1 = re.search(r'([A-Z]:/.*?/GenshinImpact_Data)', content, re.MULTILINE)
match2 = re.search(r'([A-Z]:/.*?/YuanShen_Data)', content, re.MULTILINE)
match3 = re.search(r'([A-Z]:/.*?/StarRail_Data)', content, re.MULTILINE)
if match1 is None and match2 is None and match3 is None:
raise FileNotFoundError("No Genshin/Star Rail installation location in logfile")

match = None
if match1 is not None:
match = match1
elif match2 is not None:
match = match2
elif match3 is not None:
match = match3

base_dir = pathlib.Path(match[1]) / "webCaches"
webCaches = [entry for entry in base_dir.iterdir() if entry.is_dir() and entry.name.startswith("2.")]

data_location = max(webCaches, key=lambda x: x.name) / "Cache/Cache_Data/data_2"
if data_location.is_file():
return data_location

raise FileNotFoundError("Genshin installation location is improper")
raise FileNotFoundError("Genshin/Star Rail installation location is improper")


def get_output_log(*, game: typing.Optional[types.Game] = None) -> pathlib.Path:
Expand Down Expand Up @@ -78,7 +91,7 @@ def _expand_game_location(game_location: pathlib.Path, *, game: typing.Optional[
game_location / location / data_name for location in locations for data_name in data_names
]
if game is None or game == types.Game.STARRAIL:
locations = ["Star Rail", "崩坏:星穹铁道"]
locations = ["Star Rail", "Star Rail/Games", "Games", "崩坏:星穹铁道"]
data_names = ["StarRail_Data"]
data_location += [
game_location / location / data_name for location in locations for data_name in data_names
Expand All @@ -90,7 +103,10 @@ def _expand_game_location(game_location: pathlib.Path, *, game: typing.Optional[
if not directory.is_dir():
continue

datafile = directory / "webCaches/Cache/Cache_Data/data_2"
base_dir = directory / "webCaches"
webCaches = [entry for entry in base_dir.iterdir() if entry.is_dir() and entry.name.startswith("2.")]

datafile = max(webCaches, key=lambda x: x.name) / "Cache/Cache_Data/data_2"
if datafile.is_file():
return datafile

Expand All @@ -115,7 +131,7 @@ def _read_datafile(game_location: typing.Optional[PathLike] = None, *, game: typ
try:
return datafile.read_text(errors="replace")
except PermissionError as ex:
raise PermissionError("Pleas turn off genshin impact or try running script as administrator") from ex
raise PermissionError("Please turn off Genshin Impact/Star Rail or try running script as administrator") from ex


def extract_authkey(string: str) -> typing.Optional[str]:
Expand Down

0 comments on commit 509af83

Please sign in to comment.