mirror of
https://github.com/NinjaCheetah/WiiPy.git
synced 2025-06-29 07:31:02 -04:00
Improve syntax for ASH command to match other new commands
This commit is contained in:
parent
cde90c474d
commit
31635a8015
@ -5,34 +5,28 @@ import pathlib
|
|||||||
import libWiiPy
|
import libWiiPy
|
||||||
|
|
||||||
|
|
||||||
def handle_ash(args):
|
def handle_ash_compress(args):
|
||||||
|
print("Compression is not implemented yet.")
|
||||||
|
|
||||||
|
|
||||||
|
def handle_ash_decompress(args):
|
||||||
input_path = pathlib.Path(args.input)
|
input_path = pathlib.Path(args.input)
|
||||||
output_path = pathlib.Path(args.output)
|
if args.output is not None:
|
||||||
|
output_path = pathlib.Path(args.output)
|
||||||
|
else:
|
||||||
|
output_path = pathlib.Path(input_path.name + ".arc")
|
||||||
|
|
||||||
# Code for if --compress was passed.
|
# These default to 9 and 11, respectively, so we can always read them.
|
||||||
# ASH compression has not been implemented in libWiiPy yet, but it'll be filled in here when it has.
|
sym_tree_bits = args.sym_bits
|
||||||
if args.compress:
|
dist_tree_bits = args.dist_bits
|
||||||
print("Compression is not implemented yet.")
|
|
||||||
|
|
||||||
# Code for if --decompress was passed.
|
if not input_path.exists():
|
||||||
elif args.decompress:
|
raise FileNotFoundError(input_path)
|
||||||
# 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
|
|
||||||
|
|
||||||
if not input_path.exists():
|
ash_data = input_path.read_bytes()
|
||||||
raise FileNotFoundError(input_path)
|
# 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)
|
||||||
|
output_path.write_bytes(ash_decompressed)
|
||||||
|
|
||||||
ash_file = open(input_path, "rb")
|
print("ASH file decompressed!")
|
||||||
ash_data = ash_file.read()
|
|
||||||
ash_file.close()
|
|
||||||
|
|
||||||
# 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()
|
|
||||||
|
|
||||||
print("ASH file decompressed!")
|
|
||||||
|
35
wiipy.py
35
wiipy.py
@ -15,27 +15,44 @@ from modules.title.iospatcher import *
|
|||||||
from modules.title.nus import *
|
from modules.title.nus import *
|
||||||
from modules.title.wad import *
|
from modules.title.wad import *
|
||||||
|
|
||||||
|
wiipy_ver = "1.4.0"
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Main argument parser.
|
# Main argument parser.
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description="A simple command line tool to manage file formats used by the Wii.")
|
description="A simple command line tool to manage file formats used by the Wii.")
|
||||||
parser.add_argument("--version", action="version",
|
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)
|
subparsers = parser.add_subparsers(title="subcommands", dest="subcommand", required=True)
|
||||||
|
|
||||||
# Argument parser for the ASH subcommand.
|
# Argument parser for the ASH subcommand.
|
||||||
ash_parser = subparsers.add_parser("ash", help="compress/decompress an ASH file",
|
ash_parser = subparsers.add_parser("ash", help="compress/decompress an ASH file",
|
||||||
description="compress/decompress an ASH file")
|
description="compress/decompress an ASH file")
|
||||||
ash_parser.set_defaults(func=handle_ash)
|
ash_subparsers = ash_parser.add_subparsers(title="emunand", dest="emunand", required=True)
|
||||||
ash_group = ash_parser.add_mutually_exclusive_group(required=True)
|
# ASH compress parser.
|
||||||
ash_group.add_argument("-c", "--compress", help="compress a file into an ASH file", action="store_true")
|
ash_compress_parser = ash_subparsers.add_parser("compress", help="compress a file into an ASH file",
|
||||||
ash_group.add_argument("-d", "--decompress", help="decompress an ASH file", action="store_true")
|
description="compress a file into an ASH file; by default, this "
|
||||||
ash_parser.add_argument("input", metavar="IN", type=str, help="input file")
|
"will output to <input file>.ash")
|
||||||
ash_parser.add_argument("output", metavar="OUT", type=str, help="output file")
|
ash_compress_parser.set_defaults(func=handle_ash_compress)
|
||||||
ash_parser.add_argument("--sym-bits", metavar="SYM_BITS", type=int,
|
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)
|
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)
|
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
|
# Argument parser for the cIOS command
|
||||||
cios_parser = subparsers.add_parser("cios", help="build a cIOS from a base IOS and provided map",
|
cios_parser = subparsers.add_parser("cios", help="build a cIOS from a base IOS and provided map",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user