Switch: Support file associations
Vicki Pfau vi@endrift.com
Mon, 24 Jun 2019 19:01:20 -0700
4 files changed,
45 insertions(+),
1 deletions(-)
M
CHANGES
→
CHANGES
@@ -64,6 +64,7 @@ - Vita: L2/R2 and L3/R3 can now be mapped on PSTV (fixes mgba.io/i/1292)
- mGUI: Remember name and position of last loaded game - Core: Create game-related paths if they don't exist (fixes mgba.io/i/1446) - Qt: Add option to pause on minimizing window (closes mgba.io/i/1379) + - Switch: Support file associations 0.7.2: (2019-05-25) Emulation fixes:
M
src/platform/switch/CMakeLists.txt
→
src/platform/switch/CMakeLists.txt
@@ -42,9 +42,10 @@
add_custom_command(OUTPUT romfs.bin COMMAND ${CMAKE_COMMAND} -E make_directory romfs COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/res/font-new.png" romfs/ + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/fileassoc.cfg.in" romfs/ COMMAND ${BUILD_ROMFS} romfs romfs.bin COMMAND ${CMAKE_COMMAND} -E remove_directory romfs - DEPENDS "${CMAKE_SOURCE_DIR}/res/font-new.png") + DEPENDS "${CMAKE_SOURCE_DIR}/res/font-new.png" "${CMAKE_CURRENT_SOURCE_DIR}/fileassoc.cfg.in") add_custom_target(${BINARY_NAME}.nro ALL ${ELF2NRO} ${BINARY_NAME}.elf ${BINARY_NAME}.nro --romfs=romfs.bin --nacp=control.nacp --icon="${CMAKE_CURRENT_SOURCE_DIR}/icon.jpg"
A
src/platform/switch/fileassoc.cfg.in
@@ -0,0 +1,18 @@
+fileassoc={ + app_path="%s"; + + targets=( + { + file_extension=".gba"; + }, + { + file_extension=".gb"; + }, + { + file_extension=".gbc"; + }, + { + file_extension=".sgb"; + } + ); +};
M
src/platform/switch/main.c
→
src/platform/switch/main.c
@@ -12,6 +12,7 @@ #include <mgba/internal/gba/input.h>
#include <mgba-util/gui.h> #include <mgba-util/gui/font.h> #include <mgba-util/gui/menu.h> +#include <mgba-util/vfs.h> #include <switch.h> #include <EGL/egl.h>@@ -920,6 +921,29 @@ _mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_DLEFT, GUI_INPUT_LEFT);
_mapKey(&runner.params.keyMap, AUTO_INPUT, KEY_DRIGHT, GUI_INPUT_RIGHT); audoutStartAudioOut(); + + if (argc > 0) { + struct VFile* vf = VFileOpen("romfs:/fileassoc.cfg.in", O_RDONLY); + if (vf) { + size_t size = vf->size(vf); + const char* arg0 = strchr(argv[0], '/'); + char* buffer[2] = { + calloc(size + 1, 1), + malloc(size + strlen(arg0) + 1) + }; + vf->read(vf, buffer[0], vf->size(vf)); + vf->close(vf); + snprintf(buffer[1], size + strlen(arg0), buffer[0], arg0); + mkdir("sdmc:/config/nx-hbmenu/fileassoc", 0755); + vf = VFileOpen("sdmc:/config/nx-hbmenu/fileassoc/mgba.cfg", O_CREAT | O_TRUNC | O_WRONLY); + if (vf) { + vf->write(vf, buffer[1], strlen(buffer[1])); + vf->close(vf); + } + free(buffer[0]); + free(buffer[1]); + } + } if (argc > 1) { size_t i;