WiiPy/modules/u8.py
NinjaCheetah 5e1bf6ed4e
Rewrote entire source to be based around argparse
This does change a large amount of the syntax for using the CLI, but I think that's for the better. This new system also allows for having help pages for each sub command, making the tool a lot easier to use. It also allows for having more arguments available for each subcommand, which is especially necessary for the ASH module.
2024-06-24 00:41:07 -04:00

38 lines
948 B
Python

# "u8.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy
import pathlib
import libWiiPy
def handle_u8(args):
input_path = pathlib.Path(args.input)
output_path = pathlib.Path(args.output)
if args.pack:
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!")
elif args.unpack:
if not input_path.exists():
raise FileNotFoundError(args.input)
u8_data = open(input_path, "rb").read()
if output_path.exists():
print("Error: Specified output directory already exists!")
return
libWiiPy.archive.extract_u8(u8_data, str(output_path))
print("U8 archive unpacked!")