Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool open_in_file_manager(const std::string& path)
- {
- #if defined(_X11)
- #ifdef DE_USE_FORK_EXEC_WAIT
- LOG_DE << "open_in_file_manager(): on X11, will fork xdg-open\n";
- const pid_t child = fork();
- if(child == -1) {
- ERR_DE << "open_in_file_manager(): fork() failed\n";
- return false;
- } else if(child == 0) {
- execl("/usr/bin/xdg-open", "/usr/bin/xdg-open", path.c_str(), reinterpret_cast<char*>(NULL));
- execl("/bin/xdg-open", "/bin/xdg-open", path.c_str(), reinterpret_cast<char*>(NULL));
- // We shouldn't reach this point.
- exit(1);
- } else {
- if(waitpid(child, NULL, 0) == -1) {
- ERR_DE << "open_in_file_manager(): waitpid() failed\n";
- exit(1);
- }
- }
- // Doing further diagnostics would be a waste of time, let's pretend
- // xdg-open is always going to deliver rainbows and happiness to our
- // users.
- return true;
- #else // ! DE_USE_FORK_EXEC_WAIT
- LOG_DE << "open_in_file_manager(): on X11, will use xdg-open\n";
- const int res = system(("xdg-open " + path).c_str());
- if(res == -1) {
- ERR_DE << "open_in_file_manager(): system() failed\n";
- } else if(res != 0) {
- ERR_DE << "open_in_file_manager(): xdg-open returned " << res << '\n';
- } else {
- return true;
- }
- return false;
- #endif
- #elif defined(_WIN32) && defined(UNTESTED_DE_CODE_ON_WIN32)
- LOG_DE << "open_in_file_manager(): on Win32, will use ShellExecute()\n";
- std::wstring wpath = string_to_wstring(path);
- const int res = static_cast<int>(ShellExecute(NULL, L"open", wpath.data(), NULL, NULL, SW_SHOW));
- if(res <= 32) {
- ERR_DE << "open_in_file_manager(): ShellExecute() failed (" << res << ")\n";
- return false;
- }
- return true;
- #elif defined(__APPLE__) && defined(UNTESTED_DE_CODE_ON_OSX)
- #else
- ERR_DE << "open_in_file_manager(): unsupported platform\n";
- return false;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment