diff --git a/src/util/platform.cpp b/src/util/platform.cpp index b749718d..b1c5362c 100644 --- a/src/util/platform.cpp +++ b/src/util/platform.cpp @@ -7,12 +7,11 @@ #include #include "typedefs.hpp" +#include "stringutil.hpp" #ifdef _WIN32 #include -#include "stringutil.hpp" - void platform::configure_encoding() { // set utf-8 encoding to console output SetConsoleOutputCP(CP_UTF8); @@ -35,7 +34,6 @@ std::string platform::detect_locale() { .replace(2, 1, "_") .substr(0, 5); } - #else void platform::configure_encoding() { @@ -49,5 +47,19 @@ std::string platform::detect_locale() { return preferredLocaleName.substr(0, 5); } - #endif + + +void platform::open_folder(const std::filesystem::path& folder) { + if (!std::filesystem::is_directory(folder)) { + return; + } +#ifdef __APPLE__ + auto cmd = "open "+util::quote(folder.u8string()); +#elif defined(_WIN32) + auto cmd = "start "+util::quote(folder.u8string()); +#else + auto cmd = "xdg-open "+util::quote(folder.u8string()); +#endif + system(cmd.c_str()); +} diff --git a/src/util/platform.hpp b/src/util/platform.hpp index a620acad..973c0ebd 100644 --- a/src/util/platform.hpp +++ b/src/util/platform.hpp @@ -1,9 +1,13 @@ #pragma once #include +#include namespace platform { void configure_encoding(); - // @return environment locale in ISO format ll_CC + /// @return environment locale in ISO format ll_CC std::string detect_locale(); + /// @brief Open folder using system file manager application + /// @param folder target folder + void open_folder(const std::filesystem::path& folder); }