diff --git a/src/libWiiPy/nand/emunand.py b/src/libWiiPy/nand/emunand.py index ed880bc..bffa9d2 100644 --- a/src/libWiiPy/nand/emunand.py +++ b/src/libWiiPy/nand/emunand.py @@ -128,6 +128,10 @@ class EmuNAND: uid_sys = _UidSys() if not uid_sys_path.exists(): uid_sys.create() + else: + uid_sys.load(uid_sys_path.read_bytes()) + uid_sys.add(title.tmd.title_id) + uid_sys_path.write_bytes(uid_sys.dump()) def uninstall_title(self, tid: str) -> None: """ diff --git a/src/libWiiPy/nand/sys.py b/src/libWiiPy/nand/sys.py index 54b2859..9b1440d 100644 --- a/src/libWiiPy/nand/sys.py +++ b/src/libWiiPy/nand/sys.py @@ -77,7 +77,8 @@ class UidSys: def add(self, title_id: str | bytes) -> int: """ - Adds a new Title ID to the uid.sys file and returns the UID assigned to that title. + Adds a new Title ID to the uid.sys file and returns the UID assigned to that title. The new entry will only + be added if the provided Title ID doesn't already have an assigned UID. Parameters ---------- @@ -106,6 +107,11 @@ class UidSys: title_id_converted = title_id else: raise TypeError("Title ID type is not valid! It must be either type str or bytes.") + # Ensure this TID hasn't already been assigned a UID. If it has, just exit early and return the UID. + if self.uid_entries.count != 0: + for entry in self.uid_entries: + if entry.title_id == title_id_converted: + return entry.uid # Generate the new UID by incrementing the current highest UID by 1. try: new_uid = self.uid_entries[-1].uid + 1