custominstall: don't extract or rebuild title.db if no titles were installed

This commit is contained in:
Ian Burgwin
2020-05-25 19:26:02 -07:00
parent a515ca7e61
commit b3365c47bd

View File

@@ -162,14 +162,11 @@ class CustomInstall:
# TODO: Move a lot of these into their own methods # TODO: Move a lot of these into their own methods
self.log("Finding path to install to...") self.log("Finding path to install to...")
[sd_path, id1s] = self.get_sd_path() [sd_path, id1s] = self.get_sd_path()
try: if len(id1s) > 1:
if len(id1s) > 1: raise SDPathError(f'There are multiple id1 directories for id0 {crypto.id0.hex()}, '
raise SDPathError(f'There are multiple id1 directories for id0 {crypto.id0.hex()}, ' f'please remove extra directories')
f'please remove extra directories') elif len(id1s) == 0:
elif len(id1s) == 0: raise SDPathError(f'Could not find a suitable id1 directory for id0 {crypto.id0.hex()}')
raise SDPathError(f'Could not find a suitable id1 directory for id0 {crypto.id0.hex()}')
except SDPathError:
self.log("")
cifinish_path = join(self.sd, 'cifinish.bin') cifinish_path = join(self.sd, 'cifinish.bin')
sd_path = join(sd_path, id1s[0]) sd_path = join(sd_path, id1s[0])
@@ -369,34 +366,39 @@ class CustomInstall:
cifinish_data[int(cia.tmd.title_id, 16)] = {'seed': (cia.contents[0].seed if cia.contents[0].flags.uses_seed else None)} cifinish_data[int(cia.tmd.title_id, 16)] = {'seed': (cia.contents[0].seed if cia.contents[0].flags.uses_seed else None)}
# This is saved regardless if any titles were installed, so the file can be upgraded just in case.
save_cifinish(cifinish_path, cifinish_data) save_cifinish(cifinish_path, cifinish_data)
with TemporaryDirectory(suffix='-custom-install') as tempdir: if title_info_entries:
# set up the common arguments for the two times we call save3ds_fuse with TemporaryDirectory(suffix='-custom-install') as tempdir:
save3ds_fuse_common_args = [ # set up the common arguments for the two times we call save3ds_fuse
join(script_dir, 'bin', platform, 'save3ds_fuse'), save3ds_fuse_common_args = [
'-b', crypto.b9_path, join(script_dir, 'bin', platform, 'save3ds_fuse'),
'-m', self.movable, '-b', crypto.b9_path,
'--sd', self.sd, '-m', self.movable,
'--db', 'sdtitle', '--sd', self.sd,
tempdir '--db', 'sdtitle',
] tempdir
]
# extract the title database to add our own entry to # extract the title database to add our own entry to
self.log('Extracting Title Database...') self.log('Extracting Title Database...')
subprocess.run(save3ds_fuse_common_args + ['-x']) subprocess.run(save3ds_fuse_common_args + ['-x'])
for title_id, entry in title_info_entries.items(): for title_id, entry in title_info_entries.items():
# write the title info entry to the temp directory # write the title info entry to the temp directory
with open(join(tempdir, title_id), 'wb') as o: with open(join(tempdir, title_id), 'wb') as o:
o.write(entry) o.write(entry)
# import the directory, now including our title # import the directory, now including our title
self.log('Importing into Title Database...') self.log('Importing into Title Database...')
subprocess.run(save3ds_fuse_common_args + ['-i']) subprocess.run(save3ds_fuse_common_args + ['-i'])
self.log('FINAL STEP:\nRun custom-install-finalize through homebrew launcher.') self.log('FINAL STEP:\nRun custom-install-finalize through homebrew launcher.')
self.log('This will install a ticket and seed if required.') self.log('This will install a ticket and seed if required.')
else:
self.log('Did not install any titles.', 2)
def get_sd_path(self): def get_sd_path(self):
sd_path = join(self.sd, 'Nintendo 3DS', self.crypto.id0.hex()) sd_path = join(self.sd, 'Nintendo 3DS', self.crypto.id0.hex())