Core: Detect and account for apworlds being downloaded with a (1) in 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
This commit is contained in:
parent
eac3e3c29e
commit
8f60a4a259
|
@ -100,10 +100,16 @@ def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, path
|
||||||
|
|
||||||
apworld_path = pathlib.Path(apworld_src)
|
apworld_path = pathlib.Path(apworld_src)
|
||||||
|
|
||||||
module_name = pathlib.Path(apworld_path.name).stem
|
|
||||||
try:
|
try:
|
||||||
import zipfile
|
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:
|
except ValueError as e:
|
||||||
raise Exception("Archive appears invalid or damaged.") from e
|
raise Exception("Archive appears invalid or damaged.") from e
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
|
@ -122,7 +128,7 @@ def _install_apworld(apworld_src: str = "") -> Optional[Tuple[pathlib.Path, path
|
||||||
# TODO: run generic test suite over the apworld.
|
# 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.
|
# 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
|
import shutil
|
||||||
shutil.copyfile(apworld_path, target)
|
shutil.copyfile(apworld_path, target)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue