Example #1
0
def after_install(data):
    extract_files = data["extract_files"]
    rom_path = data["rom_path"]
    game_to_install = data["game_to_install"]

    psx_bin_file = None
    psx_no_cue_file = True
    psx_ecm_file = None
    for file in extract_files:
        if file.lower().endswith(".bin"):
            psx_bin_file = file
        elif file.lower().endswith(".cue"):
            psx_no_cue_file = False
        elif file.lower().endswith(".ecm"):
            psx_ecm_file = file
    if psx_bin_file:
        if psx_no_cue_file:
            yesno_dialog = YesNoDialog(
                "Rename \".bin\"-file", "On the game: \"" + game_to_install +
                "\"\nThe downloaded ROM file has a \".bin\"-file without an \".cue\"-file. RetroPie don't support this! Do you want to rename the \".bin\"-file to \".iso\" and try that this will work?\nOn no, the \".bin\"-file will be deleted!"
            )
            if yesno_dialog.answer:
                os.rename(
                    rom_path + "/" + psx_bin_file, rom_path + "/" +
                    psx_bin_file[:len(psx_bin_file) - len(".bin")] + ".iso")
            else:
                os.remove(rom_path + "/" + psx_bin_file)
            InfoDialog(
                "Install Game...",
                "Installing Game \"" + game_to_install + "\"\nPlease wait...")
    if psx_ecm_file:
        convert_dialog = GaugeDialog("Convert File format",
                                     "Uncompress ECM file\nPlease Wait...",
                                     max_value=100)
        unecm.process(rom_path + "/" + psx_ecm_file,
                      update_callback=convert_dialog.set_progress)
        convert_dialog.close()
        os.remove(rom_path + "/" + psx_ecm_file)
def extract_files(archive, files_to_extract, path_to_extract):
    if type(files_to_extract) == str:
        files_to_extract = [files_to_extract]

    with tarfile.open(archive, mode="r") as tar_file:
        uncompress_size = 0.0
        for file in tar_file.getmembers():
            if file.name in files_to_extract:
                uncompress_size += float(file.size)
        current_size = 0
        block_size = 1024

        dialog_title = "Extracting Game..."
        dialog_description = "Extracting Game...\nPlease Wait!"

        extracting_dialog = GaugeDialog(dialog_title,
                                        dialog_description,
                                        max_value=uncompress_size)

        for file in files_to_extract:
            file_path_complete = path_to_extract + file
            if os.path.isfile(file_path_complete):
                os.remove(file_path_complete)
            file_path = os.path.dirname(os.path.abspath(file_path_complete))
            if not os.path.exists(file_path):
                os.makedirs(file_path)

            i = tar_file.extractfile(file)
            o = open(path_to_extract + file, "w+")
            while True:
                b = i.read(block_size)
                current_size += len(b)
                extracting_dialog.set_progress(current_size)
                if b == "":
                    break
                o.write(b)
            i.close()
            o.close()
        extracting_dialog.close()

    return True
Example #3
0
def extract_files(archive, files_to_extract, path_to_extract):
    files_to_extract2 = files_to_extract[:]

    uncompress_size = 0
    archive_process = Popen(
        [path + "/tools/" + unrar_file, "lt", "-y", archive], stdout=PIPE)
    file = ""
    for line in iter(archive_process.stdout.readline, b""):
        line = line.lstrip()
        if line.startswith("Name: "):
            file = line.replace("Name: ", "").replace("\r\n",
                                                      "").replace("\n", "")
        elif line.startswith("Size: "):
            if file in files_to_extract:
                uncompress_size += int(
                    line.replace("Size: ", "").replace("\r\n",
                                                       "").replace("\n", ""))

    dialog_title = "Extracting Game..."
    dialog_description = "Extracting Game...\nPlease Wait!"

    extracting_dialog = GaugeDialog(dialog_title,
                                    dialog_description,
                                    max_value=uncompress_size)

    for file in files_to_extract:
        file_path_complete = path_to_extract + file
        if os.path.isfile(file_path_complete):
            os.remove(file_path_complete)
        file_path = os.path.dirname(os.path.abspath(file_path_complete))
        if not os.path.exists(file_path):
            os.makedirs(file_path)

    cmd = [path + "/tools/" + unrar_file, "p", "-y", "-idcdp", archive]

    cmd.extend(files_to_extract)
    cmd.append(path_to_extract)

    archive_process = Popen(cmd, stdout=PIPE, bufsize=-1)

    indicator = "------ "
    current_size = 0
    current_file = None
    current_file_changed = False
    first_line = False
    for line in iter(archive_process.stdout.readline, b""):
        line = line.rstrip("\n")
        if line[:1] == "-":
            if line[:len(indicator)] == indicator:
                for current_file_path in files_to_extract2:
                    if current_file_path in line:
                        if current_file:
                            current_file.close()
                        current_file = open(
                            path_to_extract + current_file_path, "w+")
                        files_to_extract2.remove(current_file_path)
                        current_file_changed = True
                        first_line = True
                        break
                if current_file_changed:
                    continue
        if current_file_changed:
            current_file_changed = False
            continue
        if current_file:
            if first_line:
                first_line = False
            else:
                line = "\n" + line
            current_size += len(line)
            extracting_dialog.set_progress(current_size)
            current_file.write(line)
    if current_file:
        current_file.close()
    extracting_dialog.close()

    return True
        total_size = 0
        if "content-length" in r.headers:
            total_size = int(r.headers["content-length"])
        else:
            if "x-varnish" in r.headers:
                if r.headers["x-varnish"].isdigit():
                    total_size = int(r.headers["x-varnish"])

        dialog_title = "Downloading UPDATE..."

        download_dialog = None
        if total_size > 0:
            dialog_description = "Downloading RetroPie-Marketplace v%s\nNeed to downloading %s Bytes\nPlease wait..." % (
                newest_version, str("{:,}".format(total_size)))
            download_dialog = GaugeDialog(dialog_title,
                                          dialog_description,
                                          max_value=total_size)
        else:
            InfoDialog(
                dialog_title,
                "Downloading RetroPie-Marketplace v%s\nPlease wait..." %
                newest_version)

        with open("/tmp/" + fname, 'wb') as f:
            current_size = 0
            for chunk in r.iter_content(chunk_size=1024):
                if chunk:
                    current_size += len(chunk)
                    f.write(chunk)
                    if download_dialog:
                        download_dialog.set_progress(current_size)
Example #5
0
def extract_files(archive, files_to_extract, path_to_extract):
    if type(files_to_extract) == str:
        files_to_extract = [files_to_extract]

    uncompress_size = 0
    archive_file = Popen(
        [path + "/tools/" + sevenz_file, "l", "-ba", "-slt", archive],
        stdout=PIPE)
    out, err = archive_file.communicate()
    if out:
        file = None
        for line in out.split("\n"):
            if line.startswith("Path = "):
                file = line.replace("Path = ", "")
            elif line.startswith("Size = "):
                if file in files_to_extract:
                    uncompress_size += int(line.replace("Size = ", ""))

    dialog_title = "Extracting Game..."
    dialog_description = "Extracting Game...\nPlease Wait!"

    extracting_dialog = GaugeDialog(dialog_title,
                                    dialog_description,
                                    max_value=uncompress_size)

    for file in files_to_extract:
        file_path_complete = path_to_extract + file
        if os.path.isfile(file_path_complete):
            os.remove(file_path_complete)
        file_path = os.path.dirname(os.path.abspath(file_path_complete))
        if not os.path.exists(file_path):
            os.makedirs(file_path)

    cmd = [
        path + "/tools/" + sevenz_file, "x", "-y", "-ba", "-so", archive,
        "-o" + path_to_extract
    ]
    cmd.extend(files_to_extract)
    archive_process = Popen(cmd, stdout=PIPE, stderr=STDOUT, bufsize=-1)

    files_to_extract2 = files_to_extract[:]
    current_size = 0
    end_indicator = "Everything is Ok"
    indicator = "Extracting  "
    current_file = None
    empty_line = 0
    first_line = False
    for line in iter(archive_process.stdout.readline, b''):
        line = line.rstrip("\n")
        if current_file and line == "":
            empty_line += 1
            if empty_line > 2:
                empty_line -= 1
                current_size += len("\n")
                extracting_dialog.set_progress(current_size)
                current_file.write("\n")
            continue
        else:
            if line[:1] == indicator[:1]:
                if line[:len(end_indicator)] == end_indicator:
                    empty_line -= 1
                    if current_file and empty_line > 0:
                        for l in range(empty_line):
                            current_size += len("\n")
                            extracting_dialog.set_progress(current_size)
                            current_file.write("\n")
                    break
                if line[:len(indicator)] == indicator:
                    line_temp = line[len(indicator):]
                    for file in files_to_extract2:
                        if line_temp[:len(file)] == file:
                            if current_file:
                                if empty_line > 0:
                                    for l in range(empty_line):
                                        current_size += len("\n")
                                        extracting_dialog.set_progress(
                                            current_size)
                                        current_file.write("\n")
                                    empty_line = 0
                                current_file.close()
                            files_to_extract2.remove(file)
                            current_file = open(path_to_extract + file, "w+")
                            line = line_temp[len(file):]
                            first_line = True
                            break
        if current_file:
            if empty_line > 0:
                for l in range(empty_line):
                    line = "\n" + line
                empty_line = 0
            if first_line:
                first_line = False
            else:
                line = "\n" + line
            current_size += len(line)
            extracting_dialog.set_progress(current_size)
            current_file.write(line)
    if current_file:
        current_file.close()
    extracting_dialog.close()

    return True