Skip to content

Commit

Permalink
Core: Detect and account for apworlds being downloaded with a (1) in …
Browse files Browse the repository at this point in the history
…their name (#4144)

* Core: Detect and account for apworlds being downloaded with a (1) in their name

* Reword comment

* Always use internal module name

* Requested changes from black-silver
  • Loading branch information
silasary authored Nov 14, 2024
1 parent eac3e3c commit 8f60a4a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions worlds/LauncherComponents.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,16 @@ def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, path

apworld_path = pathlib.Path(apworld_src)

module_name = pathlib.Path(apworld_path.name).stem
try:
import zipfile
zipfile.ZipFile(apworld_path).open(module_name + "/__init__.py")
zip = zipfile.ZipFile(apworld_path)
directories = [f.filename.strip('/') for f in zip.filelist if f.CRC == 0 and f.file_size == 0 and f.filename.count('/') == 1]
if len(directories) == 1 and directories[0] in apworld_path.stem:
module_name = directories[0]
apworld_name = module_name + ".apworld"
else:
raise Exception("APWorld appears to be invalid or damaged. (expected a single directory)")
zip.open(module_name + "/__init__.py")
except ValueError as e:
raise Exception("Archive appears invalid or damaged.") from e
except KeyError as e:
Expand All @@ -122,7 +128,7 @@ def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, path
# TODO: run generic test suite over the apworld.
# TODO: have some kind of version system to tell from metadata if the apworld should be compatible.

target = pathlib.Path(worlds.user_folder) / apworld_path.name
target = pathlib.Path(worlds.user_folder) / apworld_name
import shutil
shutil.copyfile(apworld_path, target)

Expand Down

0 comments on commit 8f60a4a

Please sign in to comment.