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) || defined(__APPLE__)
- #ifndef __APPLE__
- LOG_DE << "open_in_file_manager(): on X11, will use xdg-open\n";
- const char launcher[] = "xdg-open";
- #else
- LOG_DE << "open_in_file_manager(): on OS X, will use open\n";
- const char launcher[] = "open";
- #endif
- int child_status = 0;
- const pid_t child = fork();
- if(child == -1) {
- ERR_DE << "open_in_file_manager(): fork() failed\n";
- return false;
- } else if(child == 0) {
- execlp(launcher, launcher, path.c_str(), reinterpret_cast<char*>(NULL));
- _exit(1); // This shouldn't happen.
- } else if(waitpid(child, &child_status, 0) == -1) {
- ERR_DE << "open_in_file_manager(): waitpid() failed\n";
- return false;
- }
- if(child_status) {
- if(WIFEXITED(child_status)) {
- ERR_DE << "open_in_file_manager(): " << launcher << " returned "
- << WEXITSTATUS(child_status) << '\n';
- } else {
- ERR_DE << "open_in_file_manager(): " << launcher << " failed\n";
- }
- return false;
- }
- return true;
- #elif defined(_WIN32)
- LOG_DE << "open_in_file_manager(): on Win32, will use ShellExecute()\n";
- const wide_string& wpath = utils::string_to_wstring(path);
- const int res = reinterpret_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;
- #else
- ERR_DE << "open_in_file_manager(): unsupported platform\n";
- return false;
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment