Package botw
Expand source code
# pylint: disable=bad-continuation
import os
from pathlib import Path
from typing import Union
DATA_DIR = Path(os.path.dirname(os.path.realpath(__file__))) / "data"
def get_canon_name(path: Union[str, Path], no_root: bool = False) -> str:
r"""Gets the canonical resource path of a given BOTW file from its relative file system path.
Args:
path (Union[str, Path]): The file path to render canonical. This must be either a
relative path to a file in a mod or game folder, or it must be the stored
path of a file inside a SARC. E.g. `content\Actor\ActorInfo.product.sbyml`
is valid, but not `C:\botw_mods\content\Actor\ActorInfo.product.sbyml`.
no_root (bool, optional): Specifies whether to allow paths that do not begin with a
recognized game folder. This is necessary for paths inside SARCs. Defaults to False.
Raises:
ValueError: Raises an error if the path does not appear to be a valid BOTW resource path
Returns:
str: Returns the canonical resource path for given file
"""
if isinstance(path, Path):
path = str(path)
name = (
path.replace("\\", "/")
.replace("Content", "content")
.replace("Aoc", "aoc")
.replace("atmosphere/titles/", "")
.replace("atmosphere/contents/", "")
.replace("01007EF00011E000/romfs", "content")
.replace("01007EF00011E001/romfs", "aoc/0010")
.replace("01007EF00011E002/romfs", "aoc/0010")
.replace("01007EF00011F001/romfs", "aoc/0010")
.replace("01007EF00011F002/romfs", "aoc/0010")
.replace("romfs", "content")
.replace(".s", ".")
)
if name.startswith("aoc/"):
return name.replace("aoc/content", "Aoc").replace("aoc", "Aoc")
elif name.startswith("content/") and "/aoc" not in name:
return name.replace("content/", "")
else:
if no_root:
return name
else:
raise ValueError(f"{name} does not appear to be a canonical BOTW path")
Sub-modules
botw.extensions
-
Contains sets representing file extensions used by BOTW for SARC, AAMP, and BYML files …
botw.hashes
-
Provides hash tables for unmodified game files using xxHash
botw.rstb
-
Functions to estimate RSTB values for complex file types
Functions
def get_canon_name(path: Union[str, pathlib.Path], no_root: bool = False) ‑> str
-
Gets the canonical resource path of a given BOTW file from its relative file system path.
Args
path
:Union[str, Path]
- The file path to render canonical. This must be either a
relative path to a file in a mod or game folder, or it must be the stored
path of a file inside a SARC. E.g.
content\Actor\ActorInfo.product.sbyml
is valid, but notC:\botw_mods\content\Actor\ActorInfo.product.sbyml
. no_root
:bool
, optional- Specifies whether to allow paths that do not begin with a recognized game folder. This is necessary for paths inside SARCs. Defaults to False.
Raises
ValueError
- Raises an error if the path does not appear to be a valid BOTW resource path
Returns
str
- Returns the canonical resource path for given file
Expand source code
def get_canon_name(path: Union[str, Path], no_root: bool = False) -> str: r"""Gets the canonical resource path of a given BOTW file from its relative file system path. Args: path (Union[str, Path]): The file path to render canonical. This must be either a relative path to a file in a mod or game folder, or it must be the stored path of a file inside a SARC. E.g. `content\Actor\ActorInfo.product.sbyml` is valid, but not `C:\botw_mods\content\Actor\ActorInfo.product.sbyml`. no_root (bool, optional): Specifies whether to allow paths that do not begin with a recognized game folder. This is necessary for paths inside SARCs. Defaults to False. Raises: ValueError: Raises an error if the path does not appear to be a valid BOTW resource path Returns: str: Returns the canonical resource path for given file """ if isinstance(path, Path): path = str(path) name = ( path.replace("\\", "/") .replace("Content", "content") .replace("Aoc", "aoc") .replace("atmosphere/titles/", "") .replace("atmosphere/contents/", "") .replace("01007EF00011E000/romfs", "content") .replace("01007EF00011E001/romfs", "aoc/0010") .replace("01007EF00011E002/romfs", "aoc/0010") .replace("01007EF00011F001/romfs", "aoc/0010") .replace("01007EF00011F002/romfs", "aoc/0010") .replace("romfs", "content") .replace(".s", ".") ) if name.startswith("aoc/"): return name.replace("aoc/content", "Aoc").replace("aoc", "Aoc") elif name.startswith("content/") and "/aoc" not in name: return name.replace("content/", "") else: if no_root: return name else: raise ValueError(f"{name} does not appear to be a canonical BOTW path")