Esempio n. 1
0
    def move(self, forceNsp=False):
        if not self.path:
            Print.error('no path set')
            return False

        if os.path.abspath(self.path).startswith(
                os.path.abspath(Config.paths.nspOut)
        ) and not self.path.endswith('.nsz') and not self.path.endswith(
                '.xcz') and Config.compression.auto:
            nszFile = nut.compress(self.path, Config.compression.level,
                                   os.path.abspath(Config.paths.nspOut))

            if nszFile:
                nsp = Nsps.registerFile(nszFile)
                nsp.hasValidTicket = True
                nsp.move(forceNsp=True)

        newPath = self.fileName(forceNsp=forceNsp)

        if not newPath:
            Print.error('could not get filename for ' + self.path)
            return False

        newPath = os.path.abspath(newPath)

        if newPath.lower().replace('\\', '/') == self.path.lower().replace(
                '\\', '/'):
            return False

        if os.path.isfile(newPath):
            Print.info('\nduplicate title: ')
            Print.info(os.path.abspath(self.path))
            Print.info(newPath)
            Print.info('\n')
            return False

        if self.isOpen():
            if not self.verifyNcaHeaders():
                Print.error('verification failed: could not move title for ' +
                            str(self.titleId) + ' or ' +
                            str(Title.getBaseId(self.titleId)))
                return False
        else:
            try:
                self.open(self.path)
                if not self.verifyNcaHeaders():
                    Print.error(
                        'verification failed: could not move title for ' +
                        str(self.titleId) + ' or ' +
                        str(Title.getBaseId(self.titleId)))
                    return False
            finally:
                self.close()

        try:
            Print.info(self.path + ' -> ' + newPath)

            if not Config.dryRun:
                os.makedirs(os.path.dirname(newPath), exist_ok=True)
            #newPath = self.fileName(forceNsp = forceNsp)

            if not Config.dryRun:
                if self.isOpen():
                    self.close()
                shutil.move(self.path, newPath)
                Nsps.moveFile(self.path, newPath)
                #Nsps.files[newPath] = self
                self.path = newPath
        except BaseException as e:
            Print.error('failed to rename file! %s -> %s  : %s' %
                        (self.path, newPath, e))
            if not Config.dryRun:
                self.moveDupe()

        return True
Esempio n. 2
0
def extractNcaMeta(files = []):
	initTitles()
	initFiles()

	loadNcaData()

	global ncaData
	q = {}

	if not files or len(files) == 0:
		for path, nsp in Nsps.files.items():
			if not nsp.path.endswith('.nsp'):  # and not nsp.path.endswith('.xci'):
				continue
			try:
				if hasattr(nsp, 'extractedNcaMeta') and (nsp.extractedNcaMeta or nsp.extractedNcaMeta == 1) or '0100000000000816' in path:
					# Print.info('skipping')
					continue

				if hasCnmt(nsp.titleId, nsp.version):
					continue

				q[path] = nsp
			except BaseException:
				Print.info('exception: %s' % (path))
				raise
	else:
		for path in files:
			try:
				nsp = Nsps.registerFile(path, registerLUT = False)

				if hasCnmt(nsp.titleId, nsp.version):
					continue

				q[path] = nsp
			except BaseException:
				Print.info('exception: %s' % (path))
				raise

	c = 0
	for path, nsp in tqdm(q.items()):
		if not nsp.path.endswith('.nsp'):  # and not nsp.path.endswith('.xci'):
			continue
		try:
			c += 1

			nsp.open(path, 'rb')

			if nsp.title().key == '':
				nsp.title().key = None

			if not nsp.title().key:
				Print.info('could not find title key for %s' % nsp.path)

			ncaDataMap = {}
			for n in nsp:
				if not isinstance(n, Nca):
					continue

				ncaId = n._path.split('.')[0]
				data = getNca(ncaId)

				data.contentType = int(n.header.contentType)
				data.isGameCard = n.header.isGameCard
				data.cryptoType = n.header.cryptoType
				data.keyIndex = n.header.keyIndex
				data.size = n.header.size
				data.titleId = n.header.titleId
				data.contentIndex = n.header.contentIndex
				data.sdkVersion = n.header.sdkVersion
				data.cryptoType2 = n.header.cryptoType2
				data.rightsId = n.header.rightsId

				data.buildId = n.buildId()

				if data.rightsId == b'00000000000000000000000000000000':
					data.rightsId = None
				else:
					data.rightsId = data.rightsId.decode()

				ncaDataMap[ncaId.upper()] = data

			# print(ncaDataMap)

			for n in nsp:
				if not isinstance(n, Nca):
					continue

				ncaId = n._path.split('.')[0]
				data = getNca(ncaId)

				data.contentType = int(n.header.contentType)
				data.isGameCard = n.header.isGameCard
				data.cryptoType = n.header.cryptoType
				data.keyIndex = n.header.keyIndex
				data.size = n.header.size
				data.titleId = n.header.titleId
				data.contentIndex = n.header.contentIndex
				data.sdkVersion = n.header.sdkVersion
				data.cryptoType2 = n.header.cryptoType2
				data.rightsId = n.header.rightsId

				if data.rightsId == b'00000000000000000000000000000000':
					data.rightsId = None
				else:
					data.rightsId = data.rightsId.decode()

				if data.contentType == 1:
					for p in n:
						for m in p:
							if not isinstance(m, Cnmt):
								continue

							cnmt = getCnmt(m.titleId, m.version)
							cnmt.contentEntries = []
							cnmt.metaEntries = []
							cnmt.titleType = m.titleType
							for e in m.contentEntries:
								if not e.ncaId.upper() in ncaDataMap:
									Print.info(ncaDataMap)
									Print.info('nca missing: ' + e.ncaId.upper())
									continue
								mapData = ncaDataMap[e.ncaId.upper()]
								if mapData is not None and (mapData.buildId is not None):
									cnmt.contentEntries.append({'ncaId': e.ncaId, 'type': e.type, 'buildId': mapData.buildId})
								else:
									cnmt.contentEntries.append({'ncaId': e.ncaId, 'type': e.type})

							for e in m.metaEntries:
								cnmt.metaEntries.append({'titleId': e.titleId, 'version': e.version, 'type': e.type, 'install': e.install})

							cnmt.requiredSystemVersion = m.requiredSystemVersion
							cnmt.requiredApplicationVersion = m.requiredApplicationVersion
							cnmt.otherApplicationId = m.otherApplicationId

				# print(str(data.__dict__))
			Print.info('processed %s' % nsp.path)
			nsp.extractedNcaMeta = True
		except BaseException as e:
			Print.info('exception: %s %s' % (path, str(e)))
		finally:
			nsp.close()

	# save remaining files
	saveNcaData()
Esempio n. 3
0
 def on_created(self, event):
     print('added: ' + event.src_path)
     Nsps.registerFile(event.src_path)