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()
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()
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()
def run_python_module(path: str): _nx.gfx_set_mode(TILED_DOUBLE) runpy.run_path(path, run_name='__main__') _nx.gfx_set_mode(LINEAR_DOUBLE)
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()
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()
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"))
palette_b = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 24, 45, 70, 97, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 202, 168, 130, 90, 46 ] def mandel(x0, y0): x, y = (0.0, 0.0) for i in range(MAX_ITER): x, y = ((x * x - y * y + x0), (2 * x * y + y0)) if (x * x + y * y) >= 4: return i return 0 _nx.gfx_set_mode(GfxMode_LinearDouble) fb = bytearray([0] * WIDTH * HEIGHT * 4) # RGBA8888 for y in range(HEIGHT): y0 = (y / HEIGHT * 2) - 1 for x in range(WIDTH): x0 = (x / HEIGHT * 2) - 2.5 iterations = mandel(x0, y0) fb[(y * WIDTH + x) * 4] = palette_r[iterations] fb[(y * WIDTH + x) * 4 + 1] = palette_g[iterations] fb[(y * WIDTH + x) * 4 + 2] = palette_b[iterations] _nx.gfx_set_framebuffer(fb) _nx.gfx_flush_and_sync()
def run_python_module(path: str): runpy.run_path(path, run_name='__main__') _nx.gfx_set_mode(TILED_DOUBLE) print("{} exited.".format(selected))
HEIGHT = 720 MAX_ITER = 32 palette_r = [0, 8, 16, 24, 32, 40, 42, 38, 32, 22, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 57, 96, 137, 182, 216, 224, 232, 240, 248] palette_g = [0, 1, 6, 13, 24, 37, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 110, 90, 66, 40, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] palette_b = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 24, 45, 70, 97, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 202, 168, 130, 90, 46] def mandel(x0, y0): x, y = (0.0, 0.0) for i in range(MAX_ITER): x, y = ( (x*x - y*y + x0), (2*x*y + y0) ) if (x*x + y*y) >= 4: return i return 0 _nx.gfx_set_mode(GfxMode_LinearDouble) fb = bytearray([0]*WIDTH*HEIGHT*4) # RGBA8888 for y in range(HEIGHT): y0 = (y/HEIGHT*2)-1 for x in range(WIDTH): x0 = (x/HEIGHT*2)-2.5 iterations = mandel(x0, y0) fb[(y*WIDTH+x)*4] = palette_r[iterations] fb[(y*WIDTH+x)*4+1] = palette_g[iterations] fb[(y*WIDTH+x)*4+2] = palette_b[iterations] _nx.gfx_set_framebuffer(fb) _nx.gfx_flush_and_sync()