Properly create/update uid.sys during EmuNAND title installs

This commit is contained in:
Campbell 2025-04-18 13:54:28 -04:00
parent 8269a0db98
commit e06bb39f4c
Signed by: NinjaCheetah
GPG Key ID: 39C2500E1778B156
2 changed files with 11 additions and 1 deletions

View File

@ -128,6 +128,10 @@ class EmuNAND:
uid_sys = _UidSys() uid_sys = _UidSys()
if not uid_sys_path.exists(): if not uid_sys_path.exists():
uid_sys.create() 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: def uninstall_title(self, tid: str) -> None:
""" """

View File

@ -77,7 +77,8 @@ class UidSys:
def add(self, title_id: str | bytes) -> int: 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 Parameters
---------- ----------
@ -106,6 +107,11 @@ class UidSys:
title_id_converted = title_id title_id_converted = title_id
else: else:
raise TypeError("Title ID type is not valid! It must be either type str or bytes.") 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. # Generate the new UID by incrementing the current highest UID by 1.
try: try:
new_uid = self.uid_entries[-1].uid + 1 new_uid = self.uid_entries[-1].uid + 1