mirror of
https://github.com/NinjaCheetah/WiiPy.git
synced 2025-04-26 13:21:01 -04:00
Add basic support for packing/extracting U8 archives
This commit is contained in:
parent
eb53a82957
commit
83d55ec189
11
main.py
11
main.py
@ -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
29
modules/u8.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user