Skip to content

Commit 8f60a4a

Browse files
authored
Core: Detect and account for apworlds being downloaded with a (1) in their name (ArchipelagoMW#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
1 parent eac3e3c commit 8f60a4a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

worlds/LauncherComponents.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,16 @@ def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, path
100100

101101
apworld_path = pathlib.Path(apworld_src)
102102

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

125-
target = pathlib.Path(worlds.user_folder) / apworld_path.name
131+
target = pathlib.Path(worlds.user_folder) / apworld_name
126132
import shutil
127133
shutil.copyfile(apworld_path, target)
128134

0 commit comments

Comments
 (0)