diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 2569630f..6cdfeb9d 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -19,6 +19,7 @@ #if defined(_WIN32) #include #include +#include int mkdir(char* path, int mode) { WCHAR utf16_path[MAX_PATH]; @@ -33,6 +34,9 @@ int mkdir(char* path, int mode) /* These are needed for PLATFORM_* crap */ #include #include +#include +#include +#include #define MAX_PATH PATH_MAX #endif @@ -465,3 +469,49 @@ void PLATFORM_copyFile(const char *oldLocation, const char *newLocation) /* WTF did we just do */ printf("Copied:\n\tOld: %s\n\tNew: %s\n", oldLocation, newLocation); } + +#ifdef _WIN32 +bool FILESYSTEM_openDirectoryEnabled() +{ + return true; +} + +bool FILESYSTEM_openDirectory(const char *dname) +{ + ShellExecute(NULL, "open", dname, NULL, NULL, SW_SHOWMINIMIZED); + return true; +} +#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__HAIKU__) +bool FILESYSTEM_openDirectoryEnabled() +{ + return true; +} + #ifdef __linux__ +const char* open_cmd = "xdg-open"; + #else +const char* open_cmd = "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_openDirectoryEnabled() +{ + return false; +} + +bool FILESYSTEM_openDirectory(const char *dname) +{ + return false; +} +#endif diff --git a/desktop_version/src/FileSystemUtils.h b/desktop_version/src/FileSystemUtils.h index 88f2b2d4..ddf44d0d 100644 --- a/desktop_version/src/FileSystemUtils.h +++ b/desktop_version/src/FileSystemUtils.h @@ -20,4 +20,7 @@ bool FILESYSTEM_loadTiXmlDocument(const char *name, TiXmlDocument *doc); std::vector FILESYSTEM_getLevelDirFileNames(); +bool FILESYSTEM_openDirectoryEnabled(); +bool FILESYSTEM_openDirectory(const char *dname); + #endif /* FILESYSTEMUTILS_H */