mirror of
https://github.com/NinjaCheetah/WiiPy.git
synced 2025-04-26 13:21:01 -04:00
Added support for specifying an output path for NUS downloads
This commit is contained in:
parent
df7c8361fe
commit
c7e78476c0
@ -1,11 +1,13 @@
|
|||||||
# "nus.py" from WiiPy by NinjaCheetah
|
# "nus.py" from WiiPy by NinjaCheetah
|
||||||
# https://github.com/NinjaCheetah/WiiPy
|
# https://github.com/NinjaCheetah/WiiPy
|
||||||
|
|
||||||
|
import pathlib
|
||||||
import libWiiPy
|
import libWiiPy
|
||||||
|
|
||||||
|
|
||||||
def handle_nus(args):
|
def handle_nus(args):
|
||||||
title_version = None
|
title_version = None
|
||||||
|
file_path = None
|
||||||
|
|
||||||
# Check if --version was passed, because it'll be None if it wasn't.
|
# Check if --version was passed, because it'll be None if it wasn't.
|
||||||
if args.version is not None:
|
if args.version is not None:
|
||||||
@ -15,12 +17,23 @@ def handle_nus(args):
|
|||||||
print("Enter a valid integer for the Title Version.")
|
print("Enter a valid integer for the Title Version.")
|
||||||
return
|
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.
|
# 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)
|
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.write(title.dump_wad())
|
||||||
wad_file.close()
|
wad_file.close()
|
||||||
|
|
||||||
|
1
wiipy.py
1
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("tid", metavar="TID", type=str, help="Title ID to download")
|
||||||
nus_parser.add_argument("-v", "--version", metavar="VERSION", type=int,
|
nus_parser.add_argument("-v", "--version", metavar="VERSION", type=int,
|
||||||
help="version to download (optional)")
|
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.
|
# Argument parser for the U8 subcommand.
|
||||||
u8_parser = subparsers.add_parser("u8", help="pack/unpack a U8 archive",
|
u8_parser = subparsers.add_parser("u8", help="pack/unpack a U8 archive",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user