Add support for new .toc client version suffixes: MyAddon-BCC.toc, MyAddon-Classic.toc, MyAddon-Mainline.toc.

This commit is contained in:
Casper V. Kristensen 2021-05-27 02:32:19 +02:00
parent 1f3bbbde28
commit 415041be8d
Signed by: caspervk
GPG key ID: 289CA03790535054

View file

@ -105,9 +105,11 @@ def find_addon_dirs(path: Path) -> Dict[str, Path]:
addon_dirs = {}
for p in level:
tocs = list(p.glob("*.toc"))
if any(toc.stem == p.name for toc in tocs):
if any(Path(toc_stem(str(toc))).stem == p.name for toc in tocs):
addon_dirs[p.name] = p
elif len(level) == 1 and len(tocs) == 1:
# using the length of the toc_stem set to allow multiple .tocs in the root, as long as they are identically
# named when the client version suffix is stripped
elif len(level) == 1 and len(set(toc_stem(str(t)) for t in tocs)) == 1:
addon_dirs[tocs[0].stem] = p
if addon_dirs:
logger.debug("Found AddOn dirs: %s in '%s'", addon_dirs, path)
@ -119,6 +121,14 @@ def find_addon_dirs(path: Path) -> Dict[str, Path]:
raise FileNotFoundError(f"No AddOn dirs found in {path}")
def toc_stem(toc: str):
"""
Removes AddOn .toc client version suffixes, such as '-Classic.toc' or '-BCC.toc'.
See https://github.com/Stanzilla/WoWUIBugs/issues/68#issuecomment-830351390 for more information.
"""
return re.sub(r"(.*)-(BCC|Classic|Mainline)(\.toc)", r"\1\3", toc)
def get_valid_dir_filename(s: str) -> str:
"""
From https://github.com/django/django/blob/master/django/utils/text.py