Add basic support for packing/extracting U8 archives

This commit is contained in:
Campbell 2024-06-12 14:22:17 -04:00
parent eb53a82957
commit 83d55ec189
Signed by: NinjaCheetah
GPG Key ID: 670C282B3291D63D
2 changed files with 40 additions and 0 deletions

11
main.py
View File

@ -4,6 +4,7 @@
import sys
from modules.wad import *
from modules.nus import *
from modules.u8 import *
opts = [opt for opt in sys.argv[1:] if opt.startswith("-")]
args = [arg for arg in sys.argv[1:] if not arg.startswith("-")]
@ -28,5 +29,15 @@ if __name__ == "__main__":
download_title(args[1], args[2])
exit(0)
raise SystemExit(f"Usage: {sys.argv[0]} NUS -d <Title ID> <Title Version (Optional)>")
elif "U8" in args:
if "-u" in opts:
if len(args) == 3:
extract_u8_to_folder(args[1], args[2])
exit(0)
elif "-p" in opts:
if len(args) == 3:
pack_u8_from_folder(args[1], args[2])
exit(0)
raise SystemExit(f"Usage: {sys.argv[0]} U8 (-u | -p) <input> <output>")
else:
raise SystemExit(f"Usage: {sys.argv[0]} WAD (-u | -p) <input> <output>")

29
modules/u8.py Normal file
View File

@ -0,0 +1,29 @@
# "u8.py" from libWiiPy-cli by NinjaCheetah
# https://github.com/NinjaCheetah/libWiiPy-cli
import os
import libWiiPy
def extract_u8_to_folder(in_file: str, out_folder: str):
if not os.path.isfile(in_file):
raise FileNotFoundError(in_file)
u8_data = open(in_file, "rb").read()
try:
libWiiPy.archive.extract_u8(u8_data, out_folder)
except ValueError:
print("Specified output folder already exists!")
def pack_u8_from_folder(in_folder: str, out_file: str):
try:
u8_data = libWiiPy.archive.pack_u8(in_folder)
except ValueError:
print("Specified input file/folder does not exist!")
return
out_file = open(out_file, "wb")
out_file.write(u8_data)
out_file.close()