Ejemplo n.º 1
0
def run_python_module(mod: str, mode):
    # clear both buffers
    imguihelper.clear()
    imguihelper.clear()
    _nx.gfx_set_mode(TILED_DOUBLE)
    clear_terminal()
    if not os.path.exists("data.arc"):
        print("Make sure you're running the script beside your data.arc")
        logger("Make sure you're running the script beside your data.arc")
        renderer.shutdown()
    else:
        with open('data.arc', 'r+b') as archive:
            if not os.path.exists(mod):
                print("'{}' not valid mod path".format(mod))
                logger("'{}' not valid mod path".format(mod))
                renderer.shutdown()
            fileName = getFileBaseName(mod)
            if not _isValidHex(fileName):
                print("Filename '{}' not valid hex number".format(fileName))
                logger("'{}' not valid mod path".format(mod))
                renderer.shutdown()

            if mode == 1:
                installMod(archive, mod)
            else:
                uninstallMod(archive, mod)
            global state
            state = "installed"
    imguihelper.initialize()
Ejemplo n.º 2
0
def run_python_module(path: str):
    # clear both buffers
    imguihelper.clear()
    imguihelper.clear()
    _nx.gfx_set_mode(TILED_DOUBLE)
    clear_terminal()
    runpy.run_path(path, run_name='__main__')
    # _nx.gfx_set_mode(LINEAR_DOUBLE)
    imguihelper.initialize()
Ejemplo n.º 3
0
def run_python_module(path: str):
    global ERROR
    # clear both buffers
    imguihelper.clear()
    imguihelper.clear()
    _nx.gfx_set_mode(TILED_DOUBLE)
    clear_terminal()
    try:
        runpy.run_path(path, run_name='__main__')
    except Exception as e:
        ERROR = traceback.format_exc()
    imguihelper.initialize()
Ejemplo n.º 4
0
def download(rom, consolefolder, extract):
    # clear both buffers
    imguihelper.clear()
    _nx.gfx_set_mode(TILED_DOUBLE)
    clear_terminal()

    filename = rom['title']
    zippath = os.path.splitext(filename)[0]

    print(
        "-------------------------------------------------------------------------------"
    )
    print(
        "\n            _   _ __   __     ______                _____      _   "
        +
        "\n           | \ | |\ \ / /     | ___ \              |  __ \    | |  "
        +
        "\n           |  \| | \ V /______| |_/ /___  _ __ ___ | |  \/ ___| |_ "
        +
        "\n           | . ` | /   \______|    // _ \| '_ ` _ \| | __ / _ \ __|"
        +
        "\n           | |\  |/ /^\ \     | |\ \ (_) | | | | | | |_\ \  __/ |_ "
        +
        "\n           \_| \_/\/   \/     \_| \_\___/|_| |_| |_|\____/\___|\__|"
    )
    print(
        "\n-------------------------------------------------------------------------------\n"
    )
    print("\n[Rom Selected]  " + filename)
    print("\n[Download Path] sdmc:/Roms/" + consolefolder + "/")
    print(
        "\n-------------------------------------------------------------------------------\n"
    )
    print("Download Progress:\n")
    urllib.request.urlretrieve(rom['link'],
                               "sdmc:/Roms/" + consolefolder + "/" + filename,
                               report_hook)
    print("\n\n File Downloaded")

    # TODO extraction info is not printed
    # Extraction Section
    if extract:
        print(
            "\n-------------------------------------------------------------------------------\n"
        )
        print("\n[Extraction Path] sdmc:/Roms/" + consolefolder + "/" +
              filename + "/")
        print("Extraction Progress:\n")
        path_to_extract = "sdmc:/Roms/" + consolefolder + "/" + zippath
        zf = zipfile.ZipFile("sdmc:/Roms/" + consolefolder + "/" + filename)
        uncompress_size = sum((file.file_size for file in zf.infolist()))
        extracted_size = 0

        i = len(zf.infolist())
        x = 1

        for file in zf.infolist():
            extracted_size += file.file_size
            print("Extracting " + str(x) + " of " + str(i) + ": " +
                  file.filename + " | Size: " +
                  str(file.file_size / 1000000)[0:5] + " MB | Progress: " +
                  str((extracted_size * 100 / uncompress_size))[0:3] + "%")
            zf.extractall(path_to_extract)
            x += 1

    imguihelper.initialize()
Ejemplo n.º 5
0
def rom_list(collections,
             console_selected,
             prefix='A',
             checkbox_extract=False):
    # clear both buffers
    imguihelper.clear()
    _nx.gfx_set_mode(TILED_DOUBLE)
    clear_terminal()
    imguihelper.initialize()

    renderer = NXRenderer()

    # TODO fetcing indicator
    roms = fetch_roms(collections[console_selected], prefix)

    # create collection rom folder
    directory = "Roms"
    parent_dir = "sdmc:/"
    path = os.path.join(parent_dir, directory, console_selected)
    try:
        os.makedirs(path, exist_ok=True)
    except OSError as error:
        print("Directory '%s' can not be created" % path)

    os.chdir(path)
    dir_content = os.listdir()

    while True:

        renderer.handleinputs()

        imgui.new_frame()

        width, height = renderer.io.display_size
        imgui.set_next_window_size(width, height)
        imgui.set_next_window_position(0, 0)
        imgui.begin("",
                    flags=imgui.WINDOW_NO_TITLE_BAR | imgui.WINDOW_NO_RESIZE
                    | imgui.WINDOW_NO_MOVE | imgui.WINDOW_NO_SAVED_SETTINGS)

        imgui.begin_group()

        imgui.push_style_color(imgui.COLOR_BUTTON, *MENU_BUTTON_COLOR_SELECTED)
        if imgui.button("< Back", width=70, height=50):
            main(collections)
        imgui.pop_style_color(1)

        imgui.same_line(spacing=50)
        _, checkbox_extract = imgui.checkbox("EXTRACT .ZIP AFTER DOWNLOAD",
                                             checkbox_extract)

        imgui.text("Collection: " + console_selected)

        imgui.new_line()

        for letter in '#' + string.ascii_uppercase:

            button_color = MENU_BUTTON_COLOR_SELECTED if prefix == letter else MENU_BUTTON_COLOR

            imgui.same_line()
            imgui.push_style_color(imgui.COLOR_BUTTON, *button_color)
            if imgui.button(letter, width=28, height=28):
                rom_list(collections, console_selected, letter,
                         checkbox_extract)
            imgui.pop_style_color(1)

        imgui.new_line()
        imgui.begin_child("region", -0, -0, border=True)

        for rom in roms:
            folder_name = os.path.splitext(rom['title'])[0]
            is_downloaded = any(x in dir_content
                                for x in [rom['title'], folder_name])
            button_color = ROM_COLOR_DOWNLOADED if is_downloaded else ROM_COLOR
            imgui.push_style_color(imgui.COLOR_BUTTON, *button_color)
            if imgui.button(rom['title'] + "  " + rom['size'],
                            width=1240,
                            height=30):
                download(rom, console_selected, checkbox_extract)
            imgui.pop_style_color(1)

        imgui.end_child()

        imgui.end_group()

        imgui.end()

        imgui.render()
        renderer.render()

    renderer.shutdown()
Ejemplo n.º 6
0
                ERROR = ""
            imgui.end()

        imgui.render()
        renderer.render()

    renderer.shutdown()


if __name__ == "__main__":

    # TODO: better exception error handling
    try:
        try:
            with open('collections.json') as json_file:
                try:
                    collections = json.load(json_file)
                except Exception:
                    collections = {
                        'Wrong JSON Format! Check collections.json': ''
                    }
        except Exception:
            collections = {'collections.json not found!': ''}
        main(collections)
    except Exception:
        imguihelper.clear()
        imguihelper.clear()
        _nx.gfx_set_mode(TILED_DOUBLE)
        clear_terminal()
        traceback.print_exc(file=open("sdmc:/switch/NX-Roms/errlog.txt", "a"))