Added support for specifying an output path for NUS downloads

This commit is contained in:
Campbell 2024-06-27 22:26:55 -04:00
parent df7c8361fe
commit c7e78476c0
Signed by: NinjaCheetah
GPG Key ID: B547958AF96ED344
2 changed files with 16 additions and 2 deletions

View File

@ -1,11 +1,13 @@
# "nus.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy
import pathlib
import libWiiPy
def handle_nus(args):
title_version = None
file_path = None
# Check if --version was passed, because it'll be None if it wasn't.
if args.version is not None:
@ -15,12 +17,23 @@ def handle_nus(args):
print("Enter a valid integer for the Title Version.")
return
# If --output was passed, then save the file to the specified path (as long as it's valid).
if args.output is not None:
file_path = pathlib.Path(args.output)
if not file_path.parent.exists() or not file_path.parent.is_dir():
print("The specified output path does not exist!")
return
if file_path.suffix != ".wad":
file_path = file_path.with_suffix(".wad")
# libWiiPy accepts a title version of "None" and will just use the latest available version if it gets it.
title = libWiiPy.title.download_title(args.tid, title_version)
file_name = args.tid + "-v" + str(title.tmd.title_version) + ".wad"
# If we haven't gotten a name yet, make one from the TID and version.
if file_path is None:
file_path = pathlib.Path(args.tid + "-v" + str(title.tmd.title_version) + ".wad")
wad_file = open(file_name, "wb")
wad_file = open(file_path, "wb")
wad_file.write(title.dump_wad())
wad_file.close()

View File

@ -34,6 +34,7 @@ if __name__ == "__main__":
nus_parser.add_argument("tid", metavar="TID", type=str, help="Title ID to download")
nus_parser.add_argument("-v", "--version", metavar="VERSION", type=int,
help="version to download (optional)")
nus_parser.add_argument("-o", "--output", metavar="OUT", type=str, help="output file (optional)")
# Argument parser for the U8 subcommand.
u8_parser = subparsers.add_parser("u8", help="pack/unpack a U8 archive",