示例#1
0
def get_installed_info(tfile=None, search_new=True, excludehb=True):
    if not os.path.exists(cachefolder):
        os.makedirs(cachefolder)
    forecombo = Style.BRIGHT + Back.GREEN + Fore.WHITE
    if tfile == "":
        tfile = None
    if os.path.exists(games_installed_cache):
        try:
            os.remove(games_installed_cache)
        except:
            pass
    if tfile == None:
        for f in os.listdir(cachefolder):
            fp = os.path.join(cachefolder, f)
            try:
                shutil.rmtree(fp)
            except OSError:
                os.remove(fp)
        process = subprocess.Popen([
            nscb_mtp, "ShowInstalled", "-tfile", games_installed_cache,
            "-show", "false"
        ],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        print("Parsing games in device. Please Wait...")
        while process.poll() == None:
            if process.poll() != None:
                process.terminate()
    if os.path.exists(games_installed_cache):
        gamelist = listmanager.read_lines_to_list(games_installed_cache,
                                                  all=True)
        gamelist.sort()
        print("..........................................................")
        print("CONTENT FOUND ON DEVICE")
        print("..........................................................")
        installed = {}
        for g in gamelist:
            fileid, fileversion, cctag, nG, nU, nD, baseid = listmanager.parsetags(
                g)
            g0 = [pos for pos, char in enumerate(g) if char == '[']
            g0 = (g[0:g0[0]]).strip()
            installed[fileid] = [
                fileid, fileversion, cctag, nG, nU, nD, baseid, g0, g
            ]
            if len(g0) > 33:
                g0 = g0[0:30] + '...'
            else:
                g0 = g0 + ((33 - len(g0)) * ' ')
            verprint = str(fileversion)
            if len(verprint) < 9:
                verprint = verprint + ((9 - len(verprint)) * ' ')
            if excludehb == True:
                if not fileid.startswith('05') and not fileid.startswith(
                        '04') and not str(fileid).lower() == 'unknown':
                    if g.endswith('.xci') or g.endswith('.xc0'):
                        print(
                            f"{g0}|{fileid}|{verprint}|XCI|{nG}G|{nU}U|{nD}D")
                    else:
                        print(f"{g0}|{fileid}|{verprint}|{cctag}")
            else:
                if g.endswith('.xci') or g.endswith('.xc0'):
                    print(f"{g0}|{fileid}|{verprint}|XCI|{nG}G|{nU}U|{nD}D")
                else:
                    print(f"{g0}|{fileid}|{verprint}|{cctag}")
        if search_new == True:
            import nutdb
            nutdb.check_other_file(urlconfig, 'versions_txt')
            f = 'nutdb_' + 'versions' + '.txt'
            DATABASE_folder = nutdb.get_DBfolder()
            _dbfile_ = os.path.join(DATABASE_folder, f)
            versiondict = {}
            with open(_dbfile_, 'rt', encoding='utf8') as csvfile:
                readCSV = csv.reader(csvfile, delimiter='|')
                i = 0
                for row in readCSV:
                    if i == 0:
                        csvheader = row
                        i = 1
                        if 'id' and 'version' in csvheader:
                            id = csvheader.index('id')
                            ver = csvheader.index('version')
                        else:
                            break
                    else:
                        try:
                            tid = str(row[id]).upper()
                            version = str(row[ver]).upper()
                            if tid.endswith('800'):
                                baseid = tid[:-3] + '000'
                            if baseid in versiondict.keys():
                                v = versiondict[baseid]
                                if v < int(version):
                                    versiondict[baseid] = int(version)
                            else:
                                versiondict[tid] = int(version)
                        except:
                            pass
            print("..........................................................")
            print("NEW UPDATES")
            print("..........................................................")
            for k in installed.keys():
                fileid, fileversion, cctag, nG, nU, nD, baseid, g0, g = installed[
                    k]
                if len(g0) > 33:
                    g0 = g0[0:30] + '...'
                else:
                    g0 = g0 + ((33 - len(g0)) * ' ')
                verprint = str(fileversion)
                fillver = ''
                if len(verprint) < 6:
                    fillver = (6 - len(verprint)) * ' '
                v = 0
                updateid = fileid[:-3] + '800'
                if updateid in installed.keys() and fileid.endswith('000'):
                    continue
                if fileid.endswith('800'):
                    try:
                        v = versiondict[baseid]
                    except:
                        pass
                else:
                    try:
                        v = versiondict[fileid]
                    except:
                        pass
                if int(v) > int(fileversion):
                    if fileid.endswith('000') or fileid.endswith('800'):
                        updid = fileid[:-3] + '800'
                        print(f"{g0} [{baseid}][{verprint}]{fillver} -> " +
                              forecombo + f"[{updid}] [v{v}]" +
                              Style.RESET_ALL)
                    else:
                        print(f"{g0} [{fileid}][{verprint}]{fillver} -> " +
                              forecombo + f"[{fileid}] [v{v}]" +
                              Style.RESET_ALL)
            check_xcis = False
            xci_dlcs = {}
            print("..........................................................")
            print("NEW DLCS")
            print("..........................................................")
            for k in versiondict.keys():
                if k in installed.keys() or k.endswith('000') or k.endswith(
                        '800'):
                    continue
                else:
                    baseid = get_dlc_baseid(k)
                    updid = baseid[:-3] + '800'
                    if baseid in installed.keys() or updid in installed.keys():
                        fileid, fileversion, cctag, nG, nU, nD, baseid, g0, g = installed[
                            baseid]
                        if nD > 0:
                            if check_xcis == False:
                                check_xcis = True
                            if not baseid in xci_dlcs.keys():
                                entry = list()
                                entry.append(k)
                                xci_dlcs[baseid] = entry
                            else:
                                entry = xci_dlcs[baseid]
                                entry.append(k)
                                xci_dlcs[baseid] = entry
                            continue
                        if len(g0) > 33:
                            g0 = g0[0:30] + '...'
                        else:
                            g0 = g0 + ((33 - len(g0)) * ' ')
                        print(f"{g0} [{baseid}] -> " + forecombo +
                              f"[{k}] [v{versiondict[k]}]" + Style.RESET_ALL)
            t = 0
            if check_xcis == True:
                for bid in xci_dlcs.keys():
                    fileid, fileversion, cctag, nG, nU, nD, baseid, g0, g = installed[
                        bid]
                    entry = xci_dlcs[bid]
                    test = len(entry)
                    if test > nD:
                        if t == 0:
                            print(
                                ".........................................................."
                            )
                            print("XCI MAY HAVE NEW DLCS. LISTING AVAILABLE")
                            print(
                                ".........................................................."
                            )
                            t += 1
                        if len(g0) > 33:
                            g0 = g0[0:30] + '...'
                        else:
                            g0 = g0 + ((33 - len(g0)) * ' ')
                        for k in xci_dlcs[baseid]:
                            print(f"{g0} [{baseid}] -> " + forecombo +
                                  f"[{k}] [v{versiondict[k]}]" +
                                  Style.RESET_ALL)
示例#2
0
def get_archived_info(search_new=True, excludehb=True):
    forecombo = Style.BRIGHT + Back.GREEN + Fore.WHITE
    if not os.path.exists(cachefolder):
        os.makedirs(cachefolder)
    for f in os.listdir(cachefolder):
        fp = os.path.join(cachefolder, f)
        try:
            shutil.rmtree(fp)
        except OSError:
            os.remove(fp)
    print("1. Retrieving registered...")
    dbicsv = os.path.join(cachefolder, "registered.csv")
    process = subprocess.Popen([
        nscb_mtp, "Download", "-ori",
        "4: Installed games\\InstalledApplications.csv", "-dst", dbicsv
    ],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    while process.poll() == None:
        if process.poll() != None:
            process.terminate()
    if os.path.exists(dbicsv):
        print("   Success")
    print("2. Checking Installed...")
    process = subprocess.Popen([
        nscb_mtp, "ShowInstalled", "-tfile", games_installed_cache, "-show",
        "false"
    ],
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    while process.poll() == None:
        if process.poll() != None:
            process.terminate()
    if os.path.exists(games_installed_cache):
        print("   Success")
    gamelist = listmanager.read_lines_to_list(games_installed_cache, all=True)
    dbi_dict = {}
    with open(dbicsv, 'rt', encoding='utf8') as csvfile:
        readCSV = csv.reader(csvfile, delimiter=',')
        id = 0
        ver = 1
        tname = 2
        for row in readCSV:
            try:
                tid = (str(row[id]).upper())[2:]
                version = int(row[ver])
                name = str(row[tname])
                dbi_dict[tid] = [tid, version, name]
            except:
                pass
    installed = {}
    for g in gamelist:
        entry = listmanager.parsetags(g)
        installed[entry[0]] = entry
    print("..........................................................")
    print("ARCHIVED|REGISTERED GAMES")
    print("..........................................................")
    for g in dbi_dict.keys():
        if not g in installed.keys():
            tid, version, name = dbi_dict[g]
            if len(name) > 33:
                name = name[0:30] + '...'
            print(f"{name} [{tid}][{version}]")
    if search_new == True:
        import nutdb
        nutdb.check_other_file(urlconfig, 'versions_txt')
        f = 'nutdb_' + 'versions' + '.txt'
        DATABASE_folder = nutdb.get_DBfolder()
        _dbfile_ = os.path.join(DATABASE_folder, f)
        versiondict = {}
        with open(_dbfile_, 'rt', encoding='utf8') as csvfile:
            readCSV = csv.reader(csvfile, delimiter='|')
            i = 0
            for row in readCSV:
                if i == 0:
                    csvheader = row
                    i = 1
                    if 'id' and 'version' in csvheader:
                        id = csvheader.index('id')
                        ver = csvheader.index('version')
                    else:
                        break
                else:
                    try:
                        tid = str(row[id]).upper()
                        version = str(row[ver]).upper()
                        if tid.endswith('800'):
                            baseid = tid[:-3] + '000'
                        if baseid in versiondict.keys():
                            v = versiondict[baseid]
                            if v < int(version):
                                versiondict[baseid] = int(version)
                        else:
                            versiondict[tid] = int(version)
                    except:
                        pass
        print("..........................................................")
        print("NEW UPDATES")
        print("..........................................................")
        for k in dbi_dict.keys():
            fileid, fileversion, g0 = dbi_dict[k]
            if len(g0) > 33:
                g0 = g0[0:30] + '...'
            else:
                g0 = g0 + (33 - len(g0)) * ' '
            v = 0
            updateid = fileid[:-3] + '800'
            if updateid in dbi_dict.keys() and fileid.endswith('000'):
                continue
            if fileid.endswith('800'):
                try:
                    v = versiondict[baseid]
                except:
                    pass
            else:
                try:
                    v = versiondict[fileid]
                except:
                    pass
            if int(v) > int(fileversion):
                if fileid.endswith('000') or fileid.endswith('800'):
                    updid = fileid[:-3] + '800'
                    print(f"{g0} [{baseid}][{fileversion}] -> " + forecombo +
                          f"[{updid}] [v{v}]" + Style.RESET_ALL)
                else:
                    print(f"{g0} [{fileid}][{fileversion}] -> " + forecombo +
                          f"[{fileid}] [v{v}]" + Style.RESET_ALL)
        print("..........................................................")
        print("NEW DLCS")
        print("..........................................................")
        for k in versiondict.keys():
            if k in dbi_dict.keys() or k.endswith('000') or k.endswith('800'):
                continue
            else:
                baseid = get_dlc_baseid(k)
                updid = baseid[:-3] + '800'
                if baseid in dbi_dict.keys() or updid in dbi_dict.keys():
                    fileid, fileversion, g0 = dbi_dict[baseid]
                    if len(g0) > 33:
                        g0 = g0[0:30] + '...'
                    else:
                        g0 = g0 + ((33 - len(g0)) * ' ')
                    print(f"{g0} [{baseid}] -> " + forecombo +
                          f"[{k}] [v{versiondict[k]}]" + Style.RESET_ALL)
示例#3
0
	def detect_xci_fw(filepath,doprint=True,remote=False):
		import sq_tools	
		import nutdb
		nutdb.check_other_file(urlconfig,'fw',nutdb=False)
		FW=None;dump={}
		if remote==False:
			xcifw=sq_tools.ret_xci_offsets_fw(filepath)
		else:
			from Drive import DriveTools
			xcifw=DriveTools.get_files_from_head_xci_fw(filepath)
		# print(xcifw)
		fwfiles=list()
		if len(xcifw)>0:
			for i in xcifw:
				entry=i
				fwfiles.append(entry[0])
		else: 
			if doprint==True:
				print('- Firmware was deleted from file')		
			return 'Deleted'
		# print(fwfiles)
		if os.path.exists(fwdb):
			with open(fwdb) as json_file:	
				data = json.load(json_file)	
				for i in data:	
					dict=data[i]
					if len(dict.items())>0:
						dump[i]=dict
					else: return False	
		for i in fwfiles:
			for j in dump:
				entry=dump[j]
				try:
					files=entry['specific']
					if i in files:
						FW=j
						if doprint==True:
							print('- Xci includes firmware: '+FW)
						return FW
				except:
					try:
						RSVcnmt=entry['RSVcnmt']
						if str(RSVcnmt).lower()==str(i).lower():
							FW=j
							if doprint==True:
								print('- Xci includes firmware: '+FW)
							return FW
					except:pass		
		fwfiles.sort()
		for j in dump:
			entry=dump[j]
			files=entry['files']
			files.sort()
			if fwfiles==files:
				FW=j
				if doprint==True:
					print('- Xci includes firmware: '+FW)
				return FW
		try:
			FW,fwver,unique=FWDB.read_fw(filepath,add=True,doprint=False)
			if doprint==True:
				print('- Xci includes firmware: '+FW)
			return FWnumber
		except:pass
		if doprint==True:
			print('- Unknown firmware')
		return 'UNKNOWN'