diff --git a/modules/nus.py b/modules/nus.py index ee6dc31..259e4bd 100644 --- a/modules/nus.py +++ b/modules/nus.py @@ -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() diff --git a/wiipy.py b/wiipy.py index 2d4b375..433ffa7 100644 --- a/wiipy.py +++ b/wiipy.py @@ -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",