custominstall: separate reader creation to get_reader, check against more errors

This commit is contained in:
Ian Burgwin
2021-02-08 23:43:40 -08:00
parent f904049c06
commit 0dcaaedda7

View File

@@ -26,9 +26,10 @@ if TYPE_CHECKING:
from events import Events from events import Events
from pyctr.crypto import CryptoEngine, Keyslot, load_seeddb, get_seed from pyctr.crypto import CryptoEngine, Keyslot, load_seeddb, get_seed
from pyctr.type.cdn import CDNReader from pyctr.type.cdn import CDNReader, CDNError
from pyctr.type.cia import CIAReader, CIAError from pyctr.type.cia import CIAReader, CIAError
from pyctr.type.ncch import NCCHSection from pyctr.type.ncch import NCCHSection
from pyctr.type.tmd import TitleMetadataError
from pyctr.util import roundup from pyctr.util import roundup
if platform == 'msys': if platform == 'msys':
@@ -221,10 +222,8 @@ class CustomInstall:
return hasher.digest() return hasher.digest()
def prepare_titles(self, paths: 'List[PathLike]'): @staticmethod
readers = [] def get_reader(path: 'Union[PathLike, bytes, str]'):
for path in paths:
self.log(f'Reading {path}')
if isdir(path): if isdir(path):
# try the default tmd file # try the default tmd file
reader = CDNReader(join(path, 'tmd')) reader = CDNReader(join(path, 'tmd'))
@@ -236,6 +235,17 @@ class CustomInstall:
# the file would be tried in CDNReader next (assuming it's a tmd) # the file would be tried in CDNReader next (assuming it's a tmd)
# any other error should be propagated to the caller # any other error should be propagated to the caller
reader = CDNReader(path) reader = CDNReader(path)
return reader
def prepare_titles(self, paths: 'List[PathLike]'):
readers = []
for path in paths:
self.log(f'Reading {path}')
try:
reader = self.get_reader(path)
except (CIAError, CDNError, TitleMetadataError):
self.log(f"Couldn't read {path}, likely corrupt or not a CIA or CDN title")
continue
if reader.tmd.title_id.startswith('00048'): # DSiWare if reader.tmd.title_id.startswith('00048'): # DSiWare
self.log(f'Skipping {reader.tmd.title_id} - DSiWare is not supported') self.log(f'Skipping {reader.tmd.title_id} - DSiWare is not supported')
continue continue