Restructured command files, updated U8 command syntax to match others

This commit is contained in:
2024-11-07 13:57:33 -05:00
parent 33197c36f1
commit ec7cb1063f
15 changed files with 82 additions and 70 deletions

32
commands/archive/ash.py Normal file
View File

@@ -0,0 +1,32 @@
# "commands/archive/ash.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy
import pathlib
import libWiiPy
def handle_ash_compress(args):
print("Compression is not implemented yet.")
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
if not input_path.exists():
raise FileNotFoundError(input_path)
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)
output_path.write_bytes(ash_decompressed)
print("ASH file decompressed!")

View File

@@ -0,0 +1,4 @@
# "commands/archive/theme.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy

38
commands/archive/u8.py Normal file
View File

@@ -0,0 +1,38 @@
# "commands/archive/u8.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy
import pathlib
import libWiiPy
def handle_u8_pack(args):
input_path = pathlib.Path(args.input)
output_path = pathlib.Path(args.output)
try:
u8_data = libWiiPy.archive.pack_u8(input_path)
except ValueError:
print("Error: Specified input file/folder does not exist!")
return
out_file = open(output_path, "wb")
out_file.write(u8_data)
out_file.close()
print("U8 archive packed!")
def handle_u8_unpack(args):
input_path = pathlib.Path(args.input)
output_path = pathlib.Path(args.output)
if not input_path.exists():
raise FileNotFoundError(args.input)
u8_data = open(input_path, "rb").read()
# Output path is deliberately not checked in any way because libWiiPy already has those checks, and it's easier
# and cleaner to only have one component doing all the checks.
libWiiPy.archive.extract_u8(u8_data, str(output_path))
print("U8 archive unpacked!")