Restructured command files, updated U8 command syntax to match others

This commit is contained in:
Campbell 2024-11-07 13:57:33 -05:00
parent 33197c36f1
commit ec7cb1063f
Signed by: NinjaCheetah
GPG Key ID: 670C282B3291D63D
15 changed files with 82 additions and 70 deletions

View File

@ -1,4 +1,4 @@
# "modules/archive/ash.py" from WiiPy by NinjaCheetah # "commands/archive/ash.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

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!")

View File

@ -1,4 +1,4 @@
# "modules/nand/emunand.py" from WiiPy by NinjaCheetah # "commands/nand/emunand.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

View File

@ -1,4 +1,4 @@
# "modules/nand/setting.py" from WiiPy by NinjaCheetah # "commands/nand/setting.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

View File

@ -1,4 +1,4 @@
# "modules/title/ciosbuild.py" from WiiPy by NinjaCheetah # "commands/title/ciosbuild.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import io import io
@ -59,7 +59,7 @@ def build_cios(args):
# We're ready to begin building the cIOS now. Find all the <content> tags that have <patch> tags, and then apply # We're ready to begin building the cIOS now. Find all the <content> tags that have <patch> tags, and then apply
# the patches listed in them to the content. # the patches listed in them to the content.
print("Patching existing modules...") print("Patching existing commands...")
for content in target_base.findall("content"): for content in target_base.findall("content"):
patches = content.findall("patch") patches = content.findall("patch")
if patches: if patches:
@ -91,8 +91,8 @@ def build_cios(args):
# Set the content in the title to the newly-patched content, and set the type to normal. # Set the content in the title to the newly-patched content, and set the type to normal.
title.set_content(dec_content, content_index, content_type=libWiiPy.title.ContentType.NORMAL) title.set_content(dec_content, content_index, content_type=libWiiPy.title.ContentType.NORMAL)
# Next phase of cIOS building is to add the required extra modules. # Next phase of cIOS building is to add the required extra commands.
print("Adding required additional modules...") print("Adding required additional commands...")
for content in target_base.findall("content"): for content in target_base.findall("content"):
target_module = content.get("module") target_module = content.get("module")
if target_module is not None: if target_module is not None:

View File

@ -1,4 +1,4 @@
# "modules/title/fakesign.py" from WiiPy by NinjaCheetah # "commands/title/fakesign.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

View File

@ -1,4 +1,4 @@
# "modules/title/info.py" from WiiPy by NinjaCheetah # "commands/title/info.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

View File

@ -1,4 +1,4 @@
# "modules/title/iospatcher.py" from WiiPy by NinjaCheetah # "commands/title/iospatcher.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

View File

@ -1,4 +1,4 @@
# "modules/title/nus.py" from WiiPy by NinjaCheetah # "commands/title/nus.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import hashlib import hashlib

View File

@ -1,4 +1,4 @@
# "modules/title/tmd.py" from WiiPy by NinjaCheetah # "commands/title/tmd.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

View File

@ -1,4 +1,4 @@
# "modules/title/wad.py" from WiiPy by NinjaCheetah # "commands/title/wad.py" from WiiPy by NinjaCheetah
# https://github.com/NinjaCheetah/WiiPy # https://github.com/NinjaCheetah/WiiPy
import pathlib import pathlib

View File

@ -1,37 +0,0 @@
# "modules/archive/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)
# Code for if the --pack argument was passed.
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!")
# Code for if the --unpack argument was passed.
elif args.unpack:
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!")

View File

@ -1,2 +1,2 @@
git+https://github.com/NinjaCheetah/libWiiPy git+https://github.com/NinjaCheetah/libWiiPy
nuitka==2.3.11 nuitka

View File

@ -4,17 +4,17 @@
import argparse import argparse
from importlib.metadata import version from importlib.metadata import version
from modules.archive.ash import * from commands.archive.ash import *
from modules.archive.u8 import * from commands.archive.u8 import *
from modules.nand.emunand import * from commands.nand.emunand import *
from modules.nand.setting import * from commands.nand.setting import *
from modules.title.ciosbuild import * from commands.title.ciosbuild import *
from modules.title.fakesign import * from commands.title.fakesign import *
from modules.title.info import * from commands.title.info import *
from modules.title.iospatcher import * from commands.title.iospatcher import *
from modules.title.nus import * from commands.title.nus import *
from modules.title.tmd import * from commands.title.tmd import *
from modules.title.wad import * from commands.title.wad import *
wiipy_ver = "1.4.0" wiipy_ver = "1.4.0"
@ -64,8 +64,8 @@ if __name__ == "__main__":
cios_parser.add_argument("output", metavar="OUT", type=str, help="file to output the cIOS to") cios_parser.add_argument("output", metavar="OUT", type=str, help="file to output the cIOS to")
cios_parser.add_argument("-c", "--cios-ver", metavar="CIOS", type=str, cios_parser.add_argument("-c", "--cios-ver", metavar="CIOS", type=str,
help="cIOS version from the map to build", required=True) help="cIOS version from the map to build", required=True)
cios_parser.add_argument("-m", "--modules", metavar="MODULES", type=str, cios_parser.add_argument("-m", "--commands", metavar="MODULES", type=str,
help="directory to look for cIOS modules in (optional, defaults to current directory)") help="directory to look for cIOS commands in (optional, defaults to current directory)")
cios_parser.add_argument("-s", "--slot", metavar="SLOT", type=int, cios_parser.add_argument("-s", "--slot", metavar="SLOT", type=int,
help="slot that this cIOS will install to (optional, defaults to 249)", default=249) help="slot that this cIOS will install to (optional, defaults to 249)", default=249)
cios_parser.add_argument("-v", "--version", metavar="VERSION", type=int, cios_parser.add_argument("-v", "--version", metavar="VERSION", type=int,
@ -218,12 +218,19 @@ if __name__ == "__main__":
# Argument parser for the U8 subcommand. # Argument parser for the U8 subcommand.
u8_parser = subparsers.add_parser("u8", help="pack/unpack a U8 archive", u8_parser = subparsers.add_parser("u8", help="pack/unpack a U8 archive",
description="pack/unpack a U8 archive") description="pack/unpack a U8 archive")
u8_parser.set_defaults(func=handle_u8) u8_subparsers = u8_parser.add_subparsers(dest="subcommand", required=True)
u8_group = u8_parser.add_mutually_exclusive_group(required=True) # Pack U8 subcommand.
u8_group.add_argument("-p", "--pack", help="pack a directory to a U8 archive", action="store_true") u8_pack_parser = u8_subparsers.add_parser("pack", help="pack a folder into U8 archive",
u8_group.add_argument("-u", "--unpack", help="unpack a U8 archive to a directory", action="store_true") description="pack a folder into U8 archive")
u8_parser.add_argument("input", metavar="IN", type=str, help="input file") u8_pack_parser.set_defaults(func=handle_u8_pack)
u8_parser.add_argument("output", metavar="OUT", type=str, help="output file") u8_pack_parser.add_argument("input", metavar="IN", type=str, help="folder to pack")
u8_pack_parser.add_argument("output", metavar="OUT", type=str, help="output U8 archive")
# Unpack U8 subcommand.
u8_unpack_parser = u8_subparsers.add_parser("unpack", help="unpack a U8 archive into a folder",
description="unpack a U8 archive into a folder")
u8_unpack_parser.set_defaults(func=handle_u8_unpack)
u8_unpack_parser.add_argument("input", metavar="IN", type=str, help="U8 archive to unpack")
u8_unpack_parser.add_argument("output", metavar="OUT", type=str, help="folder to output to")
# Argument parser for the WAD subcommand. # Argument parser for the WAD subcommand.
wad_parser = subparsers.add_parser("wad", help="pack/unpack a WAD file", wad_parser = subparsers.add_parser("wad", help="pack/unpack a WAD file",