示例#1
0
def uninstall_content():
    retrieve_installed()
    installed = get_gamelist()
    print("  * Entering File Picker")
    title = 'Select content to uninstall: \n + Press space or right to select content \n + Press E to finish selection'
    options = installed
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    print("  * Starting uninstalling process...")
    counter = len(selected)
    for file in selected:
        process = subprocess.Popen([nscb_mtp, "DeleteID", "-ID", file[0]])
        while process.poll() == None:
            if process.poll() != None:
                process.terminate()
        counter -= 1
        print('...................................................')
        print('STILL ' + str(counter) + ' FILES TO PROCESS')
        print('...................................................')
示例#2
0
def delete_archived():
    retrieve_installed()
    installed = get_gamelist()
    registered = retrieve_registered()
    for game in installed:
        fileid, fileversion, cctag, nG, nU, nD, baseid = listmanager.parsetags(
            game)
        try:
            del registered[fileid]
        except:
            pass
    games = []
    # Name [version][title]
    for k in registered.keys():
        games.append(
            f"{(registered[k])[2]} [{(registered[k])[0]}][{(registered[k])[1]}]"
        )
    print("  * Entering File Picker")
    if not games:
        sys.exit("There isn't any archived games or placeholder on the device")
    title = 'Select registries to delete: \n + Press space or right to select entries \n + Press E to finish selection \n + Press A to select all entries'
    options = games
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    def select_all(picker):
        return "ALL", -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    picker.register_custom_handler(ord('a'), select_all)
    picker.register_custom_handler(ord('A'), select_all)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    print("  * Starting uninstalling process...")
    arch2delete = []
    if selected[0] == "ALL":
        for k in registered:
            g0 = (registered[k])[2]
            arch2delete.append(g0)
    else:
        for game in selected:
            g = game[0]
            g0 = [pos for pos, char in enumerate(g) if char == '[']
            g0 = (g[0:g0[0]]).strip()
            arch2delete.append(g0)
    counter = len(arch2delete)
    for file in arch2delete:
        process = subprocess.Popen([nscb_mtp, "DeleteRegistry", "-ID", file])
        while process.poll() == None:
            if process.poll() != None:
                process.terminate()
        counter -= 1
        print('...................................................')
        print('STILL ' + str(counter) + ' FILES TO PROCESS')
        print('...................................................')
def pick_libraries():
    from python_pick import Picker
    title = 'Select libraries to search:  \n + Press space or right to select content \n + Press E to finish selection'
    db = libraries(remote_lib_file)
    if db == False:
        return False, False
    options = [x for x in db.keys()]
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        return False, False
    # print(selected)
    paths = list()
    TDs = list()
    for entry in selected:
        paths.append((db[entry[0]])['path'])
        try:
            TDs.append((db[entry[0]])['TD_name'])
        except:
            TDs.append(None)
    # for p in range(len(paths)):
    # print(paths[p])
    # print(TDs[p])
    return paths, TDs
示例#4
0
def dump_content():
    retrieve_installed()
    installed = get_gamelist()
    print("  * Entering File Picker")
    title = 'Select content to dump_content: \n + Press space or right to select content \n + Press E to finish selection'
    options = installed
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    outfolder = pick_download_folder()
    if not os.path.exists(outfolder):
        os.makedirs(outfolder)
    print("  * Starting dumping process...")
    counter = len(selected)
    for file in selected:
        outputfile = os.path.join(outfolder, file[0])
        process = subprocess.Popen(
            [nscb_mtp, "Dump", "-sch", file[0], "-dst", outputfile])
        while process.poll() == None:
            if process.poll() != None:
                process.terminate()
        counter -= 1
        print('...................................................')
        print('STILL ' + str(counter) + ' FILES TO PROCESS')
        print('...................................................')
示例#5
0
def pick_folder(folders, previous):
    Recursive = False
    title = 'Pick folder:\n + Press space or right to select content \n + Press E to move to file selection fase (Shows files in current folder) \n + Press R to move to file selection fase (Shows files recursevely including subfolders) \n + Press X to exit selection'
    options = folders
    picker = Picker(options, title, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)

    def end_selection_recursive(picker):
        return True, -1

    picker.register_custom_handler(ord('r'), end_selection_recursive)
    picker.register_custom_handler(ord('R'), end_selection_recursive)

    def exit_selection(picker):
        return "EXIT", -1

    picker.register_custom_handler(ord('x'), exit_selection)
    picker.register_custom_handler(ord('X'), exit_selection)
    selected = picker.start()
    if selected[0] == False:
        return False, False
    if selected[0] == "EXIT":
        return "EXIT", False
    if selected[0] == True:
        return False, True
    folder = os.path.join(previous, selected[0])
    return folder, Recursive
示例#6
0
def remote_select_from_walker(tfile, types='all'):
    from workers import concurrent_scrapper
    from Drive import Private as DrivePrivate
    ext = []
    if types != 'all':
        items = types.split(' ')
        for x in items:
            ext.append(str(x).lower())
    folder, TeamDrive = DrivePrivate.folder_walker()
    if TeamDrive == "" or TeamDrive == False:
        TeamDrive = None
    if folder == False:
        return False
    filt = remote_interface_filter()
    order = pick_order()
    if order == False:
        return False
    print(f"- Checking {folder}")
    print("  * Parsing files from Google Drive. Please Wait...")
    db = {}
    db[folder] = {'path': folder, 'TD_name': TeamDrive}
    files = concurrent_scrapper(filter=filt,
                                order=order,
                                remotelib='all',
                                db=db)
    if files == False:
        return False
    print("  * Entering File Picker")
    title = 'Select content to install or transfer: \n + Press space or right to select content \n + Press Enter to confirm selection \n + Press E to exit selection'
    filenames = []
    for f in files:
        if types == 'all':
            filenames.append(f[0])
        else:
            for x in ext:
                if (str(f[0]).lower()).endswith(x):
                    filenames.append(f[0])
                    break
    if filenames == []:
        print("  * Request didn't retrieve any files")
        return False
    options = filenames
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    with open(tfile, 'a') as textfile:
        for f in selected:
            textfile.write((files[f[1]])[2] + '/' + (files[f[1]])[0] + '|' +
                           str(TeamDrive) + '\n')
示例#7
0
def pick_order():
	title = 'Select order to list the files: \n + Press enter or intro to select \n + Press E to scape back to menu'
	options = ['name_ascending','name_descending','size_ascending','size_descending','date_ascending','date_descending']
	picker = Picker(options, title, min_selection_count=1)	
	def end_selection(picker):
		return False,-1	
	picker.register_custom_handler(ord('e'),  end_selection)
	picker.register_custom_handler(ord('E'),  end_selection)		
	selected = picker.start()	
	if selected[0]==False:
		return False
	order=selected[0]
	return order			
示例#8
0
def remote_select_from_libraries(tfile):
    from workers import concurrent_scrapper
    db = libraries(remote_lib_file)
    if db == False:
        sys.exit(f"Missing {remote_lib_file}")
    paths, TDs = drive_pick_libraries()
    if paths == False:
        return False
    order = pick_order()
    if order == False:
        return False
    filter = remote_interface_filter()
    print("  * Parsing files from Google Drive. Please Wait...")
    if isinstance(paths, list):
        db = {}
        for i in range(len(paths)):
            db[paths[i]] = {'path': paths[i], 'TD_name': TDs[i]}
        files = concurrent_scrapper(filter=filter,
                                    order=order,
                                    remotelib='all',
                                    db=db)
    else:
        db = {}
        db[paths] = {'path': paths, 'TD_name': TDs}
        files = concurrent_scrapper(filter=filter,
                                    order=order,
                                    remotelib='all',
                                    db=db)
    print("  * Entering File Picker")
    title = 'Select content to install or transfer: \n + Press space or right to select content \n + Press Enter to confirm selection \n + Press E to exit selection'
    filenames = []
    for f in files:
        filenames.append(f[0])
    options = filenames
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    with open(tfile, 'a') as textfile:
        for f in selected:
            textfile.write((files[f[1]])[2] + '/' + (files[f[1]])[0] + '\n')
def get_disks():
	available_drives = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)]
	for d in available_drives:
		dsktotal, dskused, dskfree=disk_usage(str(d))	
		if int(dsktotal)==0:
			available_drives.remove(d)
	title = 'Pick drive: \n + Press enter or intro to select \n + Press E to scape back to menu'
	options = available_drives
	picker = Picker(options, title, min_selection_count=1)	
	def end_selection(picker):
		return False,-1	
	picker.register_custom_handler(ord('e'),  end_selection)
	picker.register_custom_handler(ord('E'),  end_selection)		
	selected = picker.start()	
	if selected[0]==False:
		return False
	drive=selected[0]
	return drive	
示例#10
0
def update_console(libraries="all",
                   destiny="SD",
                   exclude_xci=True,
                   prioritize_nsz=True,
                   tfile=None,
                   verification=True,
                   ch_medium=True,
                   ch_other=False,
                   autoupd_aut=True):
    if tfile == None:
        tfile = os.path.join(NSCB_dir, 'MTP1.txt')
    if os.path.exists(tfile):
        try:
            os.remove(tfile)
        except:
            pass
    libdict = get_libs("source")
    pths = {}
    if libraries == "all":
        for entry in libdict.keys():
            pths[entry] = ((libdict[entry])[0])
    else:
        for entry in libdict.keys():
            if (libdict[entry])[1] == True:
                pths[entry] = ((libdict[entry])[0])
    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. Parsing games in device. Please Wait...")
    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)
    installed = {}
    for g in gamelist:
        if exclude_xci == True:
            if g.endswith('xci') or g.endswith('xc0'):
                continue
        entry = listmanager.parsetags(g)
        entry = list(entry)
        entry.append(g)
        installed[entry[0]] = entry
    print("2. Parsing local libraries. Please Wait...")
    locallist = []
    for p in pths.keys():
        locallist += listmanager.folder_to_list(pths[p], ['nsp', 'nsz'])
        print(f'   Parsed Library: "{str(p).upper()}"')
    if prioritize_nsz == True:
        locallist = sorted(locallist, key=lambda x: x[-1])
        locallist.reverse()
    localgames = {}
    for g in locallist:
        entry = listmanager.parsetags(g)
        entry = list(entry)
        entry.append(g)
        if not entry[0] in localgames:
            localgames[entry[0]] = entry
        else:
            v = (localgames[entry[0]])[1]
            if int(entry[1]) > int(v):
                localgames[entry[0]] = entry
    print("3. Searching new updates. Please Wait...")
    gamestosend = {}
    for g in installed.keys():
        if g.endswith('000') or g.endswith('800'):
            try:
                updid = g[:-3] + '800'
                if updid in localgames:
                    if updid in installed:
                        if ((installed[updid])[1]) < ((localgames[updid])[1]):
                            if not updid in gamestosend:
                                gamestosend[updid] = localgames[updid]
                            else:
                                if ((gamestosend[updid])[1]) < (
                                    (localgames[updid])[1]):
                                    gamestosend[updid] = localgames[updid]
                    else:
                        if not updid in gamestosend:
                            gamestosend[updid] = localgames[updid]
                        else:
                            if ((gamestosend[updid])[1]) < (
                                (localgames[updid])[1]):
                                gamestosend[updid] = localgames[updid]
            except:
                pass
        else:
            try:
                if g in localgames:
                    if ((installed[g])[1]) < ((localgames[g])[1]):
                        if not g in gamestosend:
                            gamestosend[g] = localgames[g]
                        else:
                            if ((gamestosend[g])[1]) < ((localgames[g])[1]):
                                gamestosend[g] = localgames[g]
            except:
                pass
    print("4. Searching new dlcs. Please Wait...")
    for g in installed.keys():
        try:
            if g.endswith('000') or g.endswith('800'):
                baseid = g[:-3] + '000'
            else:
                baseid = (installed[g])[6]
            for k in localgames.keys():
                try:
                    if not (k.endswith('000')
                            or k.endswith('800')) and not k in installed:
                        test = get_dlc_baseid(k)
                        if baseid == test:
                            if not k in gamestosend:
                                gamestosend[k] = localgames[k]
                            else:
                                if ((gamestosend[k])[1]) < (
                                    (localgames[k])[1]):
                                    gamestosend[k] = localgames[k]
                except BaseException as e:
                    # Print.error('Exception: ' + str(e))
                    pass
        except BaseException as e:
            # Print.error('Exception: ' + str(e))
            pass
    print("5. List of content that will get installed...")
    gamepaths = []
    if len(gamestosend.keys()) > 0:
        if autoupd_aut == True:
            for i in sorted(gamestosend.keys()):
                fileid, fileversion, cctag, nG, nU, nD, baseid, path = gamestosend[
                    i]
                bname = os.path.basename(path)
                gamepaths.append(path)
                g0 = [pos for pos, char in enumerate(bname) if char == '[']
                g0 = (bname[0:g0[0]]).strip()
                print(
                    f"   * {g0} [{fileid}][{fileversion}] [{cctag}] - {(bname[-3:]).upper()}"
                )
        else:
            options = []
            for i in sorted(gamestosend.keys()):
                fileid, fileversion, cctag, nG, nU, nD, baseid, path = gamestosend[
                    i]
                bname = os.path.basename(path)
                gamepaths.append(path)
                g0 = [pos for pos, char in enumerate(bname) if char == '[']
                g0 = (bname[0:g0[0]]).strip()
                cstring = f"{g0} [{fileid}][{fileversion}] [{cctag}] - {(bname[-3:]).upper()}"
                options.append(cstring)
            if options:
                title = 'Select content to install: \n + Press space or right to select entries \n + Press E to finish selection \n + Press A to select all entries'
                picker = Picker(options,
                                title,
                                multi_select=True,
                                min_selection_count=1)

                def end_selection(picker):
                    return False, -1

                def select_all(picker):
                    return "ALL", -1

                picker.register_custom_handler(ord('e'), end_selection)
                picker.register_custom_handler(ord('E'), end_selection)
                picker.register_custom_handler(ord('a'), select_all)
                picker.register_custom_handler(ord('A'), select_all)
                selected = picker.start()
                if selected[0] == False:
                    print("    User didn't select any files")
                    return False
                if selected[0] == "ALL":
                    pass
                else:
                    newgpaths = []
                    for game in selected:
                        g = game[1]
                        g0 = gamepaths[g]
                        newgpaths.append(g0)
                    gamepaths = newgpaths
        print("6. Generating text file...")
        with open(tfile, 'w', encoding='utf8') as textfile:
            for i in gamepaths:
                textfile.write((i).strip() + "\n")
        print("7. Triggering installer on loop mode.")
        print(
            "   Note:If you interrupt the list use normal install mode to continue list"
        )
        loop_install(tfile,
                     destiny=destiny,
                     verification=verification,
                     ch_medium=ch_medium,
                     ch_other=ch_other,
                     checked=True)
    else:
        print("\n   --- DEVICE IS UP TO DATE ---")
示例#11
0
def select_from_local_libraries(tfile, mode='installer'):
    if not os.path.exists(mtp_source_lib):
        sys.exit("mtp_source_libraries.txt")
    db = get_libs()
    title = 'Select libraries to search:  \n + Press space or right to select content \n + Press E to finish selection \n + Press A to select all libraries'
    folder_paths = []
    options = []
    for k in db:
        options.append(k)
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    def select_all(picker):
        return True, options

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    picker.register_custom_handler(ord('a'), select_all)
    picker.register_custom_handler(ord('A'), select_all)
    selected = picker.start()
    if selected[0] == False:
        print("User didn't select any libraries")
        return False, False
    if selected[0] == True:
        for k in db.keys():
            folder_paths.append((db[k])[0])
    else:
        for entry in selected:
            folder_paths.append((db[entry[0]])[0])
    order = pick_order()
    if order == False:
        return False
    filepaths = search_with_filter(folder_paths, mode)
    filedata = {}
    for file in filepaths:
        try:
            fname = os.path.basename(file)
            fsize = os.path.getsize(file)
            fdate = os.path.getctime(file)
            entry = {
                'filepath': file,
                'filename': fname,
                'size': fsize,
                'date': fdate
            }
            if not fname in filedata:
                filedata[fname] = entry
        except:
            pass
    options = []
    if order == 'name_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['filename'])
    elif order == 'name_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['filename'])
        options.reverse()
    elif order == 'size_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['size'])
    elif order == 'size_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['size'])
        options.reverse()
    elif order == 'date_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['date'])
    elif order == 'date_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['date'])
        options.reverse()
    print("  * Entering File Picker")
    title = 'Select content to install or transfer: \n + Press space or right to select content \n + Press E to finish selection'
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    with open(tfile, 'a') as textfile:
        for f in selected:
            fpath = (filedata[f[0]])['filepath']
            textfile.write(fpath + '\n')
示例#12
0
def back_up_saves(backup_all=False,
                  inline=False,
                  tidandver=True,
                  romaji=True,
                  outfolder=None):
    import zipfile
    from datetime import datetime
    try:
        for f in os.listdir(cachefolder):
            fp = os.path.join(cachefolder, f)
            try:
                shutil.rmtree(fp)
            except OSError:
                os.remove(fp)
    except:
        pass
    if outfolder == None:
        outfolder = pick_download_folder()
    if not os.path.exists(outfolder):
        os.makedirs(outfolder)
    process = subprocess.Popen([
        nscb_mtp, "ShowSaveGames", "-saves", valid_saves_cache, "-show",
        "False"
    ])
    while process.poll() == None:
        if process.poll() != None:
            process.terminate()
    if not os.path.exists(valid_saves_cache):
        sys.exit("Savegames couldn't be retrieved")
    valid_saves = []
    with open(valid_saves_cache, 'rt', encoding='utf8') as tfile:
        for line in tfile:
            valid_saves.append(line.strip())
    if backup_all == False:
        title = 'Select saves to backup: \n + Press space or right to select content \n + Press E to finish selection'
        options = valid_saves
        picker = Picker(options,
                        title,
                        multi_select=True,
                        min_selection_count=1)

        def end_selection(picker):
            return False, -1

        picker.register_custom_handler(ord('e'), end_selection)
        picker.register_custom_handler(ord('E'), end_selection)
        selected = picker.start()
        if selected[0] == False:
            print("    User didn't select any games")
            return False
    else:
        selected = []
        for i in range(len(valid_saves)):
            selected.append([valid_saves[i], i])
    print("- Retrieving registered to get TitleIDs...")
    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")
    if tidandver == 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:
                version = 0
                try:
                    tid = (str(row[id]).upper())[2:]
                    tid = tid[:-3] + '000'
                    version = int(row[ver])
                    name = str(row[tname])
                    if name in dbi_dict:
                        if version < ((dbi_dict[name])['version']):
                            continue
                    dbi_dict[name] = {
                        'tid': tid,
                        'version': version,
                        'name': name
                    }
                except:
                    pass
    counter = len(selected)
    for file in selected:
        if tidandver == True:
            print(f'- Searching "{file[0]}" in registered data')
            titleid = ""
            version = ""
            name = file[0]
            try:
                titleid = ((dbi_dict[file[0]])['tid'])
                titleid = f'[{titleid}]'
                version = str((dbi_dict[file[0]])['version'])
                version = f'[v{version}]'
            except:
                pass
            game = f"{name} {titleid}{version}"
        else:
            game = f"{name}"
        game = sanitize(game, romaji)
        if inline == False:
            dmpfolder = os.path.join(outfolder, game)
        else:
            dmpfolder = outfolder
        tmpfolder = os.path.join(dmpfolder, 'tmp')
        if not os.path.exists(dmpfolder):
            os.makedirs(dmpfolder)
        if not os.path.exists(tmpfolder):
            os.makedirs(tmpfolder)
        process = subprocess.Popen(
            [nscb_mtp, "BackSaves", "-sch", file[0], "-dst", tmpfolder])
        while process.poll() == None:
            if process.poll() != None:
                process.terminate()
        counter -= 1
        subfolders = [f.path for f in os.scandir(tmpfolder) if f.is_dir()]
        for folder in subfolders:
            dname = os.path.basename(folder)
            timedate = datetime.now()
            timedate = timedate.strftime("[%Y.%m.%d @ %H.%M.%S]")
            zipname = f"{game}{timedate}[{dname}].zip"
            output = os.path.join(dmpfolder, zipname)
            print(f"- Zipping {folder} to {output}")
            file_list = listmanager.folder_to_list(folder, extlist='all')
            if not file_list:
                continue
            z = zipfile.ZipFile(output, "w", zipfile.ZIP_DEFLATED)
            basedir = os.path.dirname(folder)
            for dirpath, dirnames, filenames in os.walk(folder):
                for filename in filenames:
                    filePath = os.path.join(dirpath, filename)
                    dirname = filePath.replace(folder, '')
                    dirname = dirname[0:]
                    if os.path.isfile(filePath):
                        z.write(filePath, dirname)
            z.close()
        try:
            shutil.rmtree(tmpfolder, ignore_errors=True)
        except:
            pass
        print('...................................................')
        print('STILL ' + str(counter) + ' FILES TO PROCESS')
        print('...................................................')
示例#13
0
def search_folder(path,
                  TD=None,
                  ext=None,
                  filter=None,
                  order=None,
                  mime='files',
                  Pick=True,
                  Print=True,
                  pickmode='multi'):
    file_list = list()
    userfilter = filter
    isroot = False
    TDlist = False
    file_listv2 = list()
    if isinstance(path, list):
        paths = path
    else:
        paths = path.split('.+')
    if isinstance(TD, list):
        TDlist = TD
    index = 0
    for path in paths:
        # print(path)
        try:
            if userfilter == None or filter == "":
                filter = ""
            else:
                filter = " and name contains '{}'".format(userfilter)
            if TDlist != False:
                TD = TDlist[index]
                index += 1
            if TD == "pick":
                TD = TD_picker(path)
            if TD != None:
                remote = location(route=path, TD_Name=TD)
            else:
                remote = location(route=path)
            drive_service = remote.drive_service
            if drive_service == None:
                if remote.token_name == None:
                    auth = auth()
                else:
                    auth = auth(token=token_name)
                drive_service = auth.drive_service
            tk, fl = get_path_parameters(path)
            if not fl and TD == None:
                root = 'root'
                remote.root = root
                remote.ID = root
            elif not fl:
                root = remote.ID
                remote.root = root
                remote.ID = root
            else:
                root = remote.root
            # print(remote.ID)
            if mime == 'files':
                page_token = None
                pagesize = 1000
                while True:
                    if root != 'root':
                        results = drive_service.files().list(
                            q="mimeType!='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields=
                            "nextPageToken, files(id, name, size, createdTime)",
                            includeItemsFromAllDrives=True,
                            supportsAllDrives=True).execute()
                    else:
                        results = drive_service.files().list(
                            q="mimeType!='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields=
                            "nextPageToken, files(id, name, size, createdTime)"
                        ).execute()
                    items = results.get('files', [])
                    try:
                        page_token = results.get('nextPageToken', None)
                    except:
                        pass
                    for file in items:
                        try:
                            file_list.append([
                                file['name'], file['size'], path,
                                file['createdTime']
                            ])
                        except:
                            pass
                    if Print == True:
                        print(f'- {path}: Total Retrieved ' +
                              str(len(file_list)))
                    if page_token == None:
                        break
            elif mime == 'folders':
                page_token = None
                pagesize = 100
                while True:
                    if root != 'root':
                        results = drive_service.files().list(
                            q="mimeType='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields="nextPageToken, files(id, name)",
                            includeItemsFromAllDrives=True,
                            supportsAllDrives=True).execute()
                    else:
                        results = drive_service.files().list(
                            q="mimeType='application/vnd.google-apps.folder' and '{}' in parents{}"
                            .format(remote.ID, filter),
                            pageSize=pagesize,
                            pageToken=page_token,
                            fields="nextPageToken, files(id, name)").execute()
                    items = results.get('files', [])
                    try:
                        page_token = results.get('nextPageToken', None)
                    except:
                        pass
                    for file in items:
                        try:
                            file_list.append([file['name'], path])
                        except:
                            pass
                    if Print == True:
                        print(f'- {path}: Total Retrieved ' +
                              str(len(file_list)))
                    if page_token == None:
                        break
        except:
            print(f'- {path}: Retrieved 0')
            return False
    if not file_list:
        return False
    file_list.sort(key=lambda x: x[0])
    if Pick == True:
        if pickmode != 'single':
            title = 'Select results (press SPACE\RIGHT to mark\\unmark, ENTER to continue): '
        elif mime == "files":
            title = 'Select result:'
        else:
            title = 'Select result:\n + Press space or right to select content \n + Press E to finish selection'
        oplist = list()
        cleanlist = list()
        if mime == 'folders':
            for item in file_list:
                oplist.append(item[0])
                cleanlist.append(clean_name(item[0]))
        else:
            for item in file_list:
                sz = str(sq_tools.getSize(int(item[1])))
                oplist.append(item[0] + ' | ' + sz)
                cleanlist.append(clean_name(item[0]) + ' | ' + sz)
        options = cleanlist
        if pickmode != 'single':
            selected = pick(options,
                            title,
                            multi_select=True,
                            min_selection_count=0)
        elif mime == "files":
            selected = pick(options, title, min_selection_count=1)
            if selected[0] == False:
                return False
        else:
            picker = Picker(options, title, min_selection_count=1)

            def end_selection(picker):
                return False, -1

            picker.register_custom_handler(ord('e'), end_selection)
            picker.register_custom_handler(ord('E'), end_selection)
            selected = picker.start()
            if selected[0] == False:
                return False
        # print (selected)
        oplist = file_list
        file_list = list()
        if pickmode == 'single':
            if mime == 'folders':
                basepath = oplist[selected[1]][1]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[selected[1]][0]
            else:
                basepath = oplist[selected[1]][2]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[selected[1]][0]
            return pth
        if mime == 'folders':
            for file in selected:
                basepath = oplist[file[1]][1]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[file[1]][0]
                file_list.append(pth)
        else:
            for file in selected:
                basepath = oplist[file[1]][2]
                if basepath[-1] != "/" and basepath[-1] != "\\":
                    basepath = basepath + '/'
                pth = basepath + oplist[file[1]][0]
                file_list.append(pth)
        if not file_list:
            return False
        if Print == True:
            print("\n- User selected the following results: ")
            for file in file_list:
                print(file)
        else:
            print("- User selected {} files".format(str(len(file_list))))
        if TDlist != False and file_list:
            file_listv2.append([file_list, TD])
    if TDlist != False:
        return file_listv2
    return file_list
示例#14
0
def get_files_from_walk(tfile=None,
                        extlist=['nsp', 'nsz', 'xci', 'xcz'],
                        filter=False,
                        recursive=False,
                        doPrint=False):
    if not isinstance(extlist, list):
        if str(extlist).lower() != 'all':
            ext = extlist.split()
            extlist = []
            for x in ext:
                extlist.append(x)
    folder, rec = folder_walker()
    if folder == False:
        return False
    if rec == True:
        recursive = True
    print("Parsing files. Please wait...")
    title = 'Add a search filter?: '
    options = ['Yes', 'No']
    selected = pick(options, title, min_selection_count=1)
    response = selected[0]
    if response == 'No':
        pass
    else:
        clear_Screen()
        About()
        filter = input('INPUT SEARCH FILTER: ')
    if recursive == False:
        files = listmanager.nextfolder_to_list(folder,
                                               extlist=extlist,
                                               filter=filter)
    else:
        files = listmanager.folder_to_list(folder,
                                           extlist=extlist,
                                           filter=filter)
    if not files:
        sys.exit("Query didn't return any files")
    order = pick_order()
    if order == False:
        return False
    filedata = {}
    for file in files:
        try:
            fname = os.path.basename(file)
            fsize = os.path.getsize(file)
            fdate = os.path.getctime(file)
            entry = {
                'filepath': file,
                'filename': fname,
                'size': fsize,
                'date': fdate
            }
            if not fname in filedata:
                filedata[fname] = entry
        except:
            pass
    options = []
    if order == 'name_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['filename'])
    elif order == 'name_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['filename'])
        options.reverse()
    elif order == 'size_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['size'])
    elif order == 'size_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['size'])
        options.reverse()
    elif order == 'date_ascending':
        options = sorted(filedata, key=lambda x: filedata[x]['date'])
    elif order == 'date_descending':
        options = sorted(filedata, key=lambda x: filedata[x]['date'])
        options.reverse()
    title = 'Select content: \n + Press space or right to select entries \n + Press Enter to confirm selection \n + Press E to exit selection \n + Press A to select all entries'
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    def select_all(picker):
        return "ALL", -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    picker.register_custom_handler(ord('a'), select_all)
    picker.register_custom_handler(ord('A'), select_all)
    selected = picker.start()
    if selected[0] == False:
        print("User didn't select any files")
        return False
    newgpaths = []
    if selected[0] == "ALL":
        for game in options:
            newgpaths.append(os.path.join(folder, game))
    else:
        for game in selected:
            newgpaths.append(os.path.join(folder, game[0]))
    if tfile != None:
        with open(tfile, 'w', encoding='utf8') as textfile:
            for i in newgpaths:
                textfile.write((i).strip() + "\n")
    if doPrint != False:
        for i in newgpaths:
            print(i)
    return newgpaths
def update_console_from_gd(libraries="all",destiny="SD",exclude_xci=True,prioritize_nsz=True,tfile=None,verification=True,ch_medium=True,ch_other=False,autoupd_aut=True,use_archived=False):	
	check_connection()
	if use_archived==True:
		autoupd_aut=False	
	if tfile==None:
		tfile=os.path.join(NSCB_dir, 'MTP1.txt')
	if os.path.exists(tfile):
		try:
			os.remove(tfile)
		except: pass			
	libdict=get_libs_remote_source(remote_lib_file);
	if libdict==False:
		sys.exit("No libraries set up")
	pths={};TDs={};
	if libraries=="all":
		for entry in libdict.keys():
			pths[entry]=((libdict[entry])[0])
			TDs[entry]=((libdict[entry])[1])
	else:
		for entry in libdict.keys():
			if (libdict[entry])[2]==True:
				pths[entry]=((libdict[entry])[0])	
				TDs[entry]=((libdict[entry])[1])
	# print(pths);print(TDs);
	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)	
	if use_archived!=True:				
		print("1. Parsing games in device. Please Wait...")			
		if exclude_xci==True:
			process=subprocess.Popen([nscb_mtp,"ShowInstalled","-tfile",games_installed_cache,"-show","false","-exci","true"],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
		else:	
			process=subprocess.Popen([nscb_mtp,"ShowInstalled","-tfile",games_installed_cache,"-show","false","-exci","false","-xci_lc",xci_locations],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)
		installed={}		
		for g in gamelist:
			try:
				if exclude_xci==True:
					if g.endswith('xci') or g.endswith('xc0'):
						continue
				entry=listmanager.parsetags(g)
				entry=list(entry)		
				entry.append(g)
				installed[entry[0]]=entry	
			except:pass	
		# for i in pths:
			# print(i)
	else:
		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")					
			installed={}
			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])
						if version>0 and tid.endswith('000'):
							tid=tid[:-3]+'800'						
						name=str(row[tname])
						g=f"{name} [{tid}][v{version}].nsp"
						entry=listmanager.parsetags(g)
						entry=list(entry)		
						entry.append(g)
						if entry[0] in installed.keys():
							if int((intalled[entry[0]])[1])<version:
								installed[entry[0]]=entry
						else:
							installed[entry[0]]=entry							
					except:pass		
	print("2. Parsing files from Google Drive. Please Wait...")		
	# print(pths)
	if isinstance(pths, dict):
		db={}
		for i in pths.keys():
			db[i]={'path':pths[i],'TD_name':TDs[i]}	
		files=concurrent_scrapper(filter='',order='name_ascending',remotelib='all',db=db)
	else:
		db={}
		db[pths]={'path':pths,'TD_name':TDs}			
		files=concurrent_scrapper(filter=filter,order='name_ascending',remotelib='all',db=db)
	remotelist=[]		
	for f in files:
		remotelist.append(f[0])
	if prioritize_nsz==True:		
		remotelist=sorted(remotelist, key=lambda x: x[-1])	
		remotelist.reverse()	
	else:
		remotelist.reverse()
	# for f in remotelist:
		# print(f)
	remotegames={}		
	for g in remotelist:
		try:
			entry=listmanager.parsetags(g)
			entry=list(entry)
			entry.append(g)		
			if not entry[0] in remotegames:
				remotegames[entry[0]]=entry
			else:
				v=(remotegames[entry[0]])[1]
				if int(entry[1])>int(v):
					remotegames[entry[0]]=entry		
		except:pass							
	print("3. Searching new updates. Please Wait...")						
	gamestosend={}		
	for g in installed.keys():
		if g.endswith('000') or g.endswith('800'): 
			try:
				updid=g[:-3]+'800'
				if updid in remotegames:
					if updid in installed:
						if ((installed[updid])[1])<((remotegames[updid])[1]):
							if not updid in gamestosend:
								gamestosend[updid]=remotegames[updid]
							else:
								if ((gamestosend[updid])[1])<((remotegames[updid])[1]):
									gamestosend[updid]=remotegames[updid]
					else:
						if not updid in gamestosend:
							gamestosend[updid]=remotegames[updid]
						else:
							if ((gamestosend[updid])[1])<((remotegames[updid])[1]):
								gamestosend[updid]=remotegames[updid]								
			except:pass
		else:
			try:		
				if g in remotegames:
					if ((installed[g])[1])<((remotegames[g])[1]):
						if not g in gamestosend:
							gamestosend[g]=remotegames[g]
						else:
							if ((gamestosend[g])[1])<((remotegames[g])[1]):
								gamestosend[g]=remotegames[g]
			except:pass							
	print("4. Searching new dlcs. Please Wait...")	
	for g in installed.keys():	
		try:
			if g.endswith('000') or g.endswith('800'): 
				baseid=g[:-3]+'000'
			else:
				baseid=(installed[g])[6]
			for k in remotegames.keys():
				try:				
					if not (k.endswith('000') or k.endswith('800')) and not k in installed:
						test=get_dlc_baseid(k)
						if baseid ==test:
							if not k in gamestosend:
								gamestosend[k]=remotegames[k]
							else:
								if ((gamestosend[k])[1])<((remotegames[k])[1]):
									gamestosend[k]=remotegames[k]	
				except BaseException as e:
					# Print.error('Exception: ' + str(e))			
					pass								
		except BaseException as e:
			# Print.error('Exception: ' + str(e))			
			pass
	print("5. List of content that will get installed...")	
	gamepaths=[]
	if len(gamestosend.keys())>0:
		if autoupd_aut==True:	
			for i in sorted(gamestosend.keys()):
				fileid,fileversion,cctag,nG,nU,nD,baseid,path=gamestosend[i]
				bname=os.path.basename(path) 
				gamepaths.append(path)
				g0=[pos for pos, char in enumerate(bname) if char == '[']	
				g0=(bname[0:g0[0]]).strip()
				print(f"   * {g0} [{fileid}][{fileversion}] [{cctag}] - {(bname[-3:]).upper()}")
		else:
			options=[]
			for i in sorted(gamestosend.keys()):			
				fileid,fileversion,cctag,nG,nU,nD,baseid,path=gamestosend[i]
				bname=os.path.basename(path) 
				gamepaths.append(path)
				g0=[pos for pos, char in enumerate(bname) if char == '[']	
				g0=(bname[0:g0[0]]).strip()
				cstring=f"{g0} [{fileid}][{fileversion}] [{cctag}] - {(bname[-3:]).upper()}"
				options.append(cstring)
			if options:
				from python_pick import Picker
				title = 'Select content to install: \n + Press space or right to select entries \n + Press Enter to confirm selection \n + Press E to exit selection \n + Press A to select all entries'				
				picker = Picker(options, title, multi_select=True, min_selection_count=1)
				def end_selection(picker):
					return False,-1
				def select_all(picker):
					return "ALL",-1			
				picker.register_custom_handler(ord('e'),  end_selection)
				picker.register_custom_handler(ord('E'),  end_selection)
				picker.register_custom_handler(ord('a'),  select_all)
				picker.register_custom_handler(ord('A'),  select_all)	
				selected=picker.start()					
			if selected[0]==False:
				print("    User didn't select any files")
				return False					
			if selected[0]=="ALL":		
				pass
			else:
				newgpaths=[]
				for game in selected:
					g=game[1]
					g0=gamepaths[g]
					newgpaths.append(g0)
				gamepaths=newgpaths					
		print("6. Generating text file...")		
		with open(tfile,'w', encoding='utf8') as textfile:
			wpath=''
			for i in gamepaths:
				location=None
				for f in files:
					TD=None;ID=None
					if f[0]==i:	
						location=f[2]
						try:
							ID=f[4]
						except:pass	
						break
				if location==None:
					print(f"Can't find location for {i}")
					continue
				wpath=f"{location}/{i}"
				lib,TD,libpath=get_library_from_path(filename=wpath)
				if ID==None:
					textfile.write(f"{(wpath).strip()}|{TD}\n")
				else:		
					textfile.write(f"{(wpath).strip()}|{TD}|{ID}\n")	
		print("7. Triggering installer on loop mode.")
		print("   Note:If you interrupt the list use normal install mode to continue list")	
		loop_install(tfile,destiny=destiny,outfolder=None,ch_medium=ch_medium,check_fw=True,patch_keygen=False,ch_base=False,ch_other=False,checked=True)
	else:
		print("\n   --- DEVICE IS UP TO DATE ---")					
示例#16
0
def remote_select_from_cache(tfile):
    from workers import concurrent_scrapper
    cache_is_setup = False
    if not os.path.exists(remote_lib_cache):
        os.makedirs(remote_lib_cache)
    jsonlist = listmanager.folder_to_list(remote_lib_cache, extlist=['json'])
    if not jsonlist:
        print("Cache wasn't found. Generating cache up...")
        from workers import concurrent_cache
        concurrent_cache()
    jsonlist = listmanager.folder_to_list(remote_lib_cache, extlist=['json'])
    if not jsonlist:
        sys.exit("Can't setup remote cache. Are libraries set up?")
    libnames = []
    for j in jsonlist:
        bname = os.path.basename(j)
        bname = bname.replace('.json', '')
        libnames.append(bname)
    title = 'Select libraries to search:  \n + Press space or right to select content \n + Press Enter to confirm selection \n + Press E to exit selection \n + Press A to select all libraries'
    db = libraries(remote_lib_file)
    options = libnames
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    def select_all(picker):
        return True, libnames

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    picker.register_custom_handler(ord('a'), select_all)
    picker.register_custom_handler(ord('A'), select_all)
    selected = picker.start()
    if selected[0] == False:
        print("User didn't select any libraries")
        return False, False
    if selected[0] == True:
        cachefiles = jsonlist
    else:
        cachefiles = []
        for entry in selected:
            fname = entry[0] + '.json'
            fpath = os.path.join(remote_lib_cache, fname)
            cachefiles.append(fpath)
    cachedict = {}
    for cach in cachefiles:
        with open(cach) as json_file:
            data = json.load(json_file)
        for entry in data:
            if not entry in cachedict:
                cachedict[entry] = data[entry]
    # for k in cachedict.keys():
    # print(k)
    order = pick_order()
    if order == False:
        return False
    options = []
    if order == 'name_ascending':
        options = sorted(cachedict, key=lambda x: cachedict[x]['filepath'])
    elif order == 'name_descending':
        options = sorted(cachedict, key=lambda x: cachedict[x]['filepath'])
        options.reverse()
    elif order == 'size_ascending':
        options = sorted(cachedict, key=lambda x: cachedict[x]['size'])
    elif order == 'size_descending':
        options = sorted(cachedict, key=lambda x: cachedict[x]['size'])
        options.reverse()
    elif order == 'date_ascending':
        options = sorted(cachedict, key=lambda x: cachedict[x]['date'])
    elif order == 'date_descending':
        options = sorted(cachedict, key=lambda x: cachedict[x]['date'])
        options.reverse()
    options = remote_interface_filter_local(options)
    print("  * Entering File Picker")
    title = 'Select content to install or transfer: \n + Press space or right to select content \n + Press Enter to confirm selection \n + Press E to exit selection'
    picker = Picker(options, title, multi_select=True, min_selection_count=1)

    def end_selection(picker):
        return False, -1

    picker.register_custom_handler(ord('e'), end_selection)
    picker.register_custom_handler(ord('E'), end_selection)
    selected = picker.start()
    if selected[0] == False:
        print("    User didn't select any files")
        return False
    with open(tfile, 'a') as textfile:
        for f in selected:
            fpath = (cachedict[f[0]])['filepath']
            textfile.write(fpath + '\n')