mirror of
https://github.com/NinjaCheetah/WiiPy.git
synced 2025-04-26 21:31:02 -04:00
EmuNAND: uninstall now accepts a WAD file that it'll get the TID from
This commit is contained in:
parent
a863da98c7
commit
f09806e002
@ -39,34 +39,25 @@ def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Tit
|
|||||||
|
|
||||||
# Tickets are installed as <tid_lower>.tik in /ticket/<tid_upper>/
|
# Tickets are installed as <tid_lower>.tik in /ticket/<tid_upper>/
|
||||||
ticket_dir = emunand_struct.ticket_dir.joinpath(tid_upper)
|
ticket_dir = emunand_struct.ticket_dir.joinpath(tid_upper)
|
||||||
if not ticket_dir.exists():
|
ticket_dir.mkdir(exist_ok=True)
|
||||||
ticket_dir.mkdir()
|
open(ticket_dir.joinpath(tid_lower + ".tik"), "wb").write(title.wad.get_ticket_data())
|
||||||
ticket_out = open(ticket_dir.joinpath(tid_lower + ".tik"), "wb")
|
|
||||||
ticket_out.write(title.wad.get_ticket_data())
|
|
||||||
ticket_out.close()
|
|
||||||
|
|
||||||
# The TMD and normal contents are installed to /title/<tid_upper>/<tid_lower>/content/, with the tmd being named
|
# The TMD and normal contents are installed to /title/<tid_upper>/<tid_lower>/content/, with the tmd being named
|
||||||
# title.tmd and the contents being named <cid>.app.
|
# title.tmd and the contents being named <cid>.app.
|
||||||
title_dir = emunand_struct.title_dir.joinpath(tid_upper)
|
title_dir = emunand_struct.title_dir.joinpath(tid_upper)
|
||||||
if not title_dir.exists():
|
title_dir.mkdir(exist_ok=True)
|
||||||
title_dir.mkdir()
|
|
||||||
title_dir = title_dir.joinpath(tid_lower)
|
title_dir = title_dir.joinpath(tid_lower)
|
||||||
if not title_dir.exists():
|
title_dir.mkdir(exist_ok=True)
|
||||||
title_dir.mkdir()
|
|
||||||
content_dir = title_dir.joinpath("content")
|
content_dir = title_dir.joinpath("content")
|
||||||
if not content_dir.exists():
|
if content_dir.exists():
|
||||||
content_dir.mkdir()
|
shutil.rmtree(content_dir) # Clear the content directory so old contents aren't left behind.
|
||||||
tmd_out = open(content_dir.joinpath("title.tmd"), "wb")
|
content_dir.mkdir(exist_ok=True)
|
||||||
tmd_out.write(title.wad.get_tmd_data())
|
open(content_dir.joinpath("title.tmd"), "wb").write(title.wad.get_tmd_data())
|
||||||
tmd_out.close()
|
|
||||||
for content_file in range(0, title.tmd.num_contents):
|
for content_file in range(0, title.tmd.num_contents):
|
||||||
if title.tmd.content_records[content_file].content_type == 1:
|
if title.tmd.content_records[content_file].content_type == 1:
|
||||||
content_file_name = f"{title.tmd.content_records[content_file].content_id:08X}".lower()
|
content_file_name = f"{title.tmd.content_records[content_file].content_id:08X}".lower()
|
||||||
content_out = open(content_dir.joinpath(content_file_name + ".app"), "wb")
|
open(content_dir.joinpath(content_file_name + ".app"), "wb").write(title.get_content_by_index(content_file))
|
||||||
content_out.write(title.get_content_by_index(content_file))
|
title_dir.joinpath("data").mkdir(exist_ok=True) # Empty directory used for save data for the title.
|
||||||
content_out.close()
|
|
||||||
if not title_dir.joinpath("data").exists():
|
|
||||||
title_dir.joinpath("data").mkdir() # Empty directory used for save data for the title.
|
|
||||||
|
|
||||||
# Shared contents need to be installed to /shared1/, with incremental names determined by /shared1/content.map.
|
# Shared contents need to be installed to /shared1/, with incremental names determined by /shared1/content.map.
|
||||||
content_map_path = emunand_struct.shared1_dir.joinpath("content.map")
|
content_map_path = emunand_struct.shared1_dir.joinpath("content.map")
|
||||||
@ -80,26 +71,19 @@ def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Tit
|
|||||||
if title.tmd.content_records[content_file].content_type == 32769:
|
if title.tmd.content_records[content_file].content_type == 32769:
|
||||||
if title.tmd.content_records[content_file].content_hash not in existing_hashes:
|
if title.tmd.content_records[content_file].content_hash not in existing_hashes:
|
||||||
content_file_name = content_map.add_content(title.tmd.content_records[content_file].content_hash)
|
content_file_name = content_map.add_content(title.tmd.content_records[content_file].content_hash)
|
||||||
content_out = open(emunand_struct.shared1_dir.joinpath(content_file_name + ".app"), "wb")
|
open(emunand_struct.shared1_dir.joinpath(content_file_name + ".app"), "wb").write(
|
||||||
content_out.write(title.get_content_by_index(content_file))
|
title.get_content_by_index(content_file))
|
||||||
content_out.close()
|
open(emunand_struct.shared1_dir.joinpath("content.map"), "wb").write(content_map.dump())
|
||||||
content_map_out = open(emunand_struct.shared1_dir.joinpath("content.map"), "wb")
|
|
||||||
content_map_out.write(content_map.dump())
|
|
||||||
content_map_out.close()
|
|
||||||
|
|
||||||
# The "footer" or meta file is installed as title.met in /meta/<tid_upper>/<tid_lower>/. Only write this if meta
|
# The "footer" or meta file is installed as title.met in /meta/<tid_upper>/<tid_lower>/. Only write this if meta
|
||||||
# is not nothing.
|
# is not nothing.
|
||||||
meta_data = title.wad.get_meta_data()
|
meta_data = title.wad.get_meta_data()
|
||||||
if meta_data != b'':
|
if meta_data != b'':
|
||||||
meta_dir = emunand_struct.meta_dir.joinpath(tid_upper)
|
meta_dir = emunand_struct.meta_dir.joinpath(tid_upper)
|
||||||
if not meta_dir.exists():
|
meta_dir.mkdir(exist_ok=True)
|
||||||
meta_dir.mkdir()
|
|
||||||
meta_dir = meta_dir.joinpath(tid_lower)
|
meta_dir = meta_dir.joinpath(tid_lower)
|
||||||
if not meta_dir.exists():
|
meta_dir.mkdir(exist_ok=True)
|
||||||
meta_dir.mkdir()
|
open(meta_dir.joinpath("title.met"), "wb").write(title.wad.get_meta_data())
|
||||||
meta_out = open(meta_dir.joinpath("title.met"), "wb")
|
|
||||||
meta_out.write(title.wad.get_meta_data())
|
|
||||||
meta_out.close()
|
|
||||||
|
|
||||||
# The Title ID needs to be added to uid.sys, which is essentially a log of all titles that are installed or have
|
# The Title ID needs to be added to uid.sys, which is essentially a log of all titles that are installed or have
|
||||||
# ever been installed.
|
# ever been installed.
|
||||||
@ -115,9 +99,7 @@ def _do_wad_install(emunand_struct: _EmuNANDStructure, title: libWiiPy.title.Tit
|
|||||||
existing_tids.append(uid_sys.uid_entries[0].title_id)
|
existing_tids.append(uid_sys.uid_entries[0].title_id)
|
||||||
if title.tmd.title_id not in existing_tids:
|
if title.tmd.title_id not in existing_tids:
|
||||||
uid_sys.add(title.tmd.title_id)
|
uid_sys.add(title.tmd.title_id)
|
||||||
uid_sys_out = open(uid_sys_path, "wb")
|
open(uid_sys_path, "wb").write(uid_sys.dump())
|
||||||
uid_sys_out.write(uid_sys.dump())
|
|
||||||
uid_sys_out.close()
|
|
||||||
|
|
||||||
|
|
||||||
def handle_emunand_title(args):
|
def handle_emunand_title(args):
|
||||||
@ -144,22 +126,27 @@ def handle_emunand_title(args):
|
|||||||
raise FileNotFoundError("No WAD files were found in the provided input directory!")
|
raise FileNotFoundError("No WAD files were found in the provided input directory!")
|
||||||
wad_count = 0
|
wad_count = 0
|
||||||
for wad in wad_files:
|
for wad in wad_files:
|
||||||
wad_file = open(wad, "rb").read()
|
|
||||||
title = libWiiPy.title.Title()
|
title = libWiiPy.title.Title()
|
||||||
title.load_wad(wad_file)
|
title.load_wad(open(wad, "rb").read())
|
||||||
_do_wad_install(emunand_struct, title)
|
_do_wad_install(emunand_struct, title)
|
||||||
wad_count += 1
|
wad_count += 1
|
||||||
print(f"Successfully installed {wad_count} WAD(s) to EmuNAND!")
|
print(f"Successfully installed {wad_count} WAD(s) to EmuNAND!")
|
||||||
else:
|
else:
|
||||||
wad_file = open(input_path, "rb").read()
|
|
||||||
title = libWiiPy.title.Title()
|
title = libWiiPy.title.Title()
|
||||||
title.load_wad(wad_file)
|
title.load_wad(open(input_path, "rb").read())
|
||||||
_do_wad_install(emunand_struct, title)
|
_do_wad_install(emunand_struct, title)
|
||||||
print("Successfully installed WAD to EmuNAND!")
|
print("Successfully installed WAD to EmuNAND!")
|
||||||
|
|
||||||
# Code for if the --uninstall argument was passed.
|
# Code for if the --uninstall argument was passed.
|
||||||
elif args.uninstall:
|
elif args.uninstall:
|
||||||
target_tid = args.uninstall
|
input_str = args.uninstall
|
||||||
|
if pathlib.Path(input_str).exists():
|
||||||
|
title = libWiiPy.title.Title()
|
||||||
|
title.load_wad(open(pathlib.Path(input_str), "rb").read())
|
||||||
|
target_tid = title.tmd
|
||||||
|
else:
|
||||||
|
target_tid = args.install
|
||||||
|
|
||||||
if len(target_tid) != 16:
|
if len(target_tid) != 16:
|
||||||
raise ValueError("Invalid Title ID! Title IDs must be 16 characters long.")
|
raise ValueError("Invalid Title ID! Title IDs must be 16 characters long.")
|
||||||
|
|
||||||
|
3
wiipy.py
3
wiipy.py
@ -50,7 +50,8 @@ if __name__ == "__main__":
|
|||||||
help="install the target WAD(s) to an EmuNAND (can be a single file or a "
|
help="install the target WAD(s) to an EmuNAND (can be a single file or a "
|
||||||
"folder of WADs)")
|
"folder of WADs)")
|
||||||
emunand_title_install_group.add_argument("--uninstall", metavar="TID", type=str,
|
emunand_title_install_group.add_argument("--uninstall", metavar="TID", type=str,
|
||||||
help="uninstall a title with the provided Title ID from an EmuNAND")
|
help="uninstall a title with the provided Title ID from an EmuNAND (also"
|
||||||
|
"accepts a WAD file to read the TID from)")
|
||||||
|
|
||||||
# Argument parser for the fakesign subcommand.
|
# Argument parser for the fakesign subcommand.
|
||||||
fakesign_parser = subparsers.add_parser("fakesign", help="fakesign a TMD, Ticket, or WAD (trucha bug)",
|
fakesign_parser = subparsers.add_parser("fakesign", help="fakesign a TMD, Ticket, or WAD (trucha bug)",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user