Improve syntax for ASH command to match other new commands

This commit is contained in:
Campbell 2024-10-16 11:21:16 -04:00
parent cde90c474d
commit 31635a8015
Signed by: NinjaCheetah
GPG Key ID: 670C282B3291D63D
2 changed files with 46 additions and 35 deletions

View File

@ -5,17 +5,17 @@ import pathlib
import libWiiPy
def handle_ash(args):
input_path = pathlib.Path(args.input)
output_path = pathlib.Path(args.output)
# Code for if --compress was passed.
# ASH compression has not been implemented in libWiiPy yet, but it'll be filled in here when it has.
if args.compress:
def handle_ash_compress(args):
print("Compression is not implemented yet.")
# Code for if --decompress was passed.
elif args.decompress:
def handle_ash_decompress(args):
input_path = pathlib.Path(args.input)
if args.output is not None:
output_path = pathlib.Path(args.output)
else:
output_path = pathlib.Path(input_path.name + ".arc")
# These default to 9 and 11, respectively, so we can always read them.
sym_tree_bits = args.sym_bits
dist_tree_bits = args.dist_bits
@ -23,16 +23,10 @@ def handle_ash(args):
if not input_path.exists():
raise FileNotFoundError(input_path)
ash_file = open(input_path, "rb")
ash_data = ash_file.read()
ash_file.close()
ash_data = input_path.read_bytes()
# Decompress ASH file using the provided symbol/distance tree widths.
ash_decompressed = libWiiPy.archive.decompress_ash(ash_data, sym_tree_bits=sym_tree_bits,
dist_tree_bits=dist_tree_bits)
ash_out = open(output_path, "wb")
ash_out.write(ash_decompressed)
ash_out.close()
output_path.write_bytes(ash_decompressed)
print("ASH file decompressed!")

View File

@ -15,27 +15,44 @@ from modules.title.iospatcher import *
from modules.title.nus import *
from modules.title.wad import *
wiipy_ver = "1.4.0"
if __name__ == "__main__":
# Main argument parser.
parser = argparse.ArgumentParser(
description="A simple command line tool to manage file formats used by the Wii.")
parser.add_argument("--version", action="version",
version=f"WiiPy v1.4.0, based on libWiiPy v{version('libWiiPy')} (from branch \'main\')")
version=f"WiiPy v{wiipy_ver}, based on libWiiPy v{version('libWiiPy')} (from branch \'main\')")
subparsers = parser.add_subparsers(title="subcommands", dest="subcommand", required=True)
# Argument parser for the ASH subcommand.
ash_parser = subparsers.add_parser("ash", help="compress/decompress an ASH file",
description="compress/decompress an ASH file")
ash_parser.set_defaults(func=handle_ash)
ash_group = ash_parser.add_mutually_exclusive_group(required=True)
ash_group.add_argument("-c", "--compress", help="compress a file into an ASH file", action="store_true")
ash_group.add_argument("-d", "--decompress", help="decompress an ASH file", action="store_true")
ash_parser.add_argument("input", metavar="IN", type=str, help="input file")
ash_parser.add_argument("output", metavar="OUT", type=str, help="output file")
ash_parser.add_argument("--sym-bits", metavar="SYM_BITS", type=int,
ash_subparsers = ash_parser.add_subparsers(title="emunand", dest="emunand", required=True)
# ASH compress parser.
ash_compress_parser = ash_subparsers.add_parser("compress", help="compress a file into an ASH file",
description="compress a file into an ASH file; by default, this "
"will output to <input file>.ash")
ash_compress_parser.set_defaults(func=handle_ash_compress)
ash_compress_parser.add_argument("input", metavar="IN", type=str, help="file to compress")
ash_compress_parser.add_argument("--sym-bits", metavar="SYM_BITS", type=int,
help="number of bits in each symbol tree leaf (default: 9)", default=9)
ash_parser.add_argument("--dist-bits", metavar="DIST_BITS", type=int,
ash_compress_parser.add_argument("--dist-bits", metavar="DIST_BITS", type=int,
help="number of bits in each distance tree leaf (default: 11)", default=11)
ash_compress_parser.add_argument("-o", "--output", metavar="OUT", type=str,
help="file to output the ASH file to (optional)")
# ASH decompress parser.
ash_decompress_parser = ash_subparsers.add_parser("decompress", help="decompress an ASH file",
description="decompress an ASH file; by default, this will "
"output to <input file>.arc")
ash_decompress_parser.set_defaults(func=handle_ash_decompress)
ash_decompress_parser.add_argument("input", metavar="IN", type=str, help="ASH file to decompress")
ash_decompress_parser.add_argument("--sym-bits", metavar="SYM_BITS", type=int,
help="number of bits in each symbol tree leaf (default: 9)", default=9)
ash_decompress_parser.add_argument("--dist-bits", metavar="DIST_BITS", type=int,
help="number of bits in each distance tree leaf (default: 11)", default=11)
ash_decompress_parser.add_argument("-o", "--output", metavar="OUT", type=str,
help="file to output the ASH file to (optional)")
# Argument parser for the cIOS command
cios_parser = subparsers.add_parser("cios", help="build a cIOS from a base IOS and provided map",