Skip to content

Commit e06bb39

Browse files
committed
Properly create/update uid.sys during EmuNAND title installs
1 parent 8269a0d commit e06bb39

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/libWiiPy/nand/emunand.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def install_title(self, title: Title, skip_hash=False) -> None:
128128
uid_sys = _UidSys()
129129
if not uid_sys_path.exists():
130130
uid_sys.create()
131+
else:
132+
uid_sys.load(uid_sys_path.read_bytes())
133+
uid_sys.add(title.tmd.title_id)
134+
uid_sys_path.write_bytes(uid_sys.dump())
131135

132136
def uninstall_title(self, tid: str) -> None:
133137
"""

src/libWiiPy/nand/sys.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ def dump(self) -> bytes:
7777

7878
def add(self, title_id: str | bytes) -> int:
7979
"""
80-
Adds a new Title ID to the uid.sys file and returns the UID assigned to that title.
80+
Adds a new Title ID to the uid.sys file and returns the UID assigned to that title. The new entry will only
81+
be added if the provided Title ID doesn't already have an assigned UID.
8182
8283
Parameters
8384
----------
@@ -106,6 +107,11 @@ def add(self, title_id: str | bytes) -> int:
106107
title_id_converted = title_id
107108
else:
108109
raise TypeError("Title ID type is not valid! It must be either type str or bytes.")
110+
# Ensure this TID hasn't already been assigned a UID. If it has, just exit early and return the UID.
111+
if self.uid_entries.count != 0:
112+
for entry in self.uid_entries:
113+
if entry.title_id == title_id_converted:
114+
return entry.uid
109115
# Generate the new UID by incrementing the current highest UID by 1.
110116
try:
111117
new_uid = self.uid_entries[-1].uid + 1

0 commit comments

Comments
 (0)