From 43b6004cea5aacf62a61d92ef190f3b3a24911d0 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Mon, 24 Jun 2019 19:01:20 -0700 Subject: [PATCH] Switch: Support file associations --- CHANGES | 1 + src/platform/switch/CMakeLists.txt | 3 ++- src/platform/switch/fileassoc.cfg.in | 18 ++++++++++++++++++ src/platform/switch/main.c | 24 ++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/platform/switch/fileassoc.cfg.in diff --git a/CHANGES b/CHANGES index 4aad6498f..d47dfe64f 100644 --- a/CHANGES +++ b/CHANGES @@ -64,6 +64,7 @@ Misc: - 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: diff --git a/src/platform/switch/CMakeLists.txt b/src/platform/switch/CMakeLists.txt index 6666b8a01..2d98ad0a5 100644 --- a/src/platform/switch/CMakeLists.txt +++ b/src/platform/switch/CMakeLists.txt @@ -42,9 +42,10 @@ add_custom_command(OUTPUT control.nacp 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" diff --git a/src/platform/switch/fileassoc.cfg.in b/src/platform/switch/fileassoc.cfg.in new file mode 100644 index 000000000..cbf5be1a4 --- /dev/null +++ b/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"; + } + ); +}; \ No newline at end of file diff --git a/src/platform/switch/main.c b/src/platform/switch/main.c index c0624423d..f87caf667 100644 --- a/src/platform/switch/main.c +++ b/src/platform/switch/main.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -921,6 +922,29 @@ int main(int argc, char* argv[]) { 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; for (i = 0; runner.keySources[i].id; ++i) {