From c1950037c2154bea15724245c555c4206e93c1f3 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Fri, 19 Feb 2021 21:16:19 -0500 Subject: [PATCH] Use SDL_OpenURL in FILESYSTEM_openDirectory (#623) The recently released SDL 2.0.14 adds a native function for opening URIs from the host system, superseding the OS-specific implementations of FILESYSTEM_openDirectory. --- desktop_version/src/FileSystemUtils.cpp | 43 ++++--------------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index ec2a9473..a97ac084 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -16,15 +16,11 @@ #if defined(_WIN32) #include #include -#include #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) #include #include #include #include -#include -#include -#include #define MAX_PATH PATH_MAX #endif @@ -561,42 +557,17 @@ bool FILESYSTEM_openDirectoryEnabled() return !SDL_GetHintBoolean("SteamTenfoot", SDL_FALSE); } -#ifdef _WIN32 bool FILESYSTEM_openDirectory(const char *dname) { - ShellExecute(NULL, "open", dname, NULL, NULL, SW_SHOWMINIMIZED); + char url[MAX_PATH]; + SDL_snprintf(url, sizeof(url), "file://%s", dname); + if (SDL_OpenURL(url) == -1) + { + printf("Error opening directory: %s\n", SDL_GetError()); + return false; + } return true; } -#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) || defined(__DragonFly__) - #if defined(__APPLE__) || defined(__HAIKU__) -const char* open_cmd = "open"; - #else -const char* open_cmd = "xdg-open"; - #endif - -extern "C" char** environ; - -bool FILESYSTEM_openDirectory(const char *dname) -{ - pid_t child; - // This const_cast is legal (ctrl-f "The statement" at https://pubs.opengroup.org/onlinepubs/9699919799/functions/exec.html - char* argv[3] = - { - const_cast(open_cmd), - const_cast(dname), - NULL - }; - posix_spawnp(&child, open_cmd, NULL, NULL, argv, environ); - int status = 0; - waitpid(child, &status, 0); - return WIFEXITED(status) && WEXITSTATUS(status) == 0; -} -#else -bool FILESYSTEM_openDirectory(const char *dname) -{ - return false; -} -#endif bool FILESYSTEM_delete(const char *name) {