diff --git a/src/dlangui/core/files.d b/src/dlangui/core/files.d index aa48789f..479a74c3 100644 --- a/src/dlangui/core/files.d +++ b/src/dlangui/core/files.d @@ -385,3 +385,4 @@ string findExecutablePath(string executableName) { } return null; } + diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 8915e0ed..ba6706ef 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -1169,20 +1169,66 @@ class SDLPlatform : Platform { /// show directory or file in OS file manager (explorer, finder, etc...) override bool showInFileManager(string pathName) { import std.process; + import std.path; + import std.file; string normalized = buildNormalizedPath(pathName); - version (OSX) { - string exe = "/usr/bin/osascript"; - string[] args; - args ~= "-e"; - args ~= "tell application \"Finder\" to reveal POSIX file \" ~ normalized ~ \""; - auto pid = spawnProcess(exe, args, Config.none); - wait(pid); - args[1] = "tell application \"Finder\" to activate"; - pid = spawnProcess(exe, args, Config.none); - wait(pid); - return true; - } else { - // TODO: implement for POSIX + if (!normalized.exists) { + Log.e("showInFileManager failed - file or directory does not exist"); + return false; + } + import std.string; + try { + version (Windows) { + Log.i("showInFileManager(", pathName, ")"); + import win32.windows; + import dlangui.core.files; + + string explorerPath = findExecutablePath("explorer.exe"); + if (!explorerPath.length) { + Log.e("showInFileManager failed - cannot find explorer.exe"); + return false; + } + string arg = "/select,\"" ~ normalized ~ "\""; + STARTUPINFO si; + si.cb = si.sizeof; + PROCESS_INFORMATION pi; + Log.d("showInFileManager: ", explorerPath, " ", arg); + arg = "\"" ~ explorerPath ~ "\" " ~ arg; + auto res = CreateProcessW(null, //explorerPath.toUTF16z, + cast(wchar*)arg.toUTF16z, + null, null, false, DETACHED_PROCESS, + null, null, &si, &pi); + if (!res) { + Log.e("showInFileManager failed to run explorer.exe"); + return false; + } + return true; + } else version (OSX) { + string exe = "/usr/bin/osascript"; + string[] args; + args ~= exe; + args ~= "-e"; + args ~= "tell application \"Finder\" to reveal POSIX file \" ~ normalized ~ \""; + auto pid = spawnProcess(args); + wait(pid); + args[2] = "tell application \"Finder\" to activate"; + pid = spawnProcess(args); + wait(pid); + return true; + } else { + // TODO: implement for POSIX + if (normalized.isFile) + normalized = normalized.basePath; + string exe = "xdg-open"; + string[] args; + args ~= exe; + args ~= normalized; + auto pid = spawnProcess(args); + wait(pid); + return true; + } + } catch (Exception e) { + Log.e("showInFileManager -- exception while trying to open file browser"); } return false; } diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index 4b724f13..ddc16157 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -867,7 +867,6 @@ class Win32Platform : Platform { override bool showInFileManager(string pathName) { Log.i("showInFileManager(", pathName, ")"); import dlangui.core.files; - //import std.process; import std.path; import std.string; @@ -881,7 +880,7 @@ class Win32Platform : Platform { STARTUPINFO si; si.cb = si.sizeof; PROCESS_INFORMATION pi; - Log.i("showInFileManager: ", explorerPath, " ", arg); + Log.d("showInFileManager: ", explorerPath, " ", arg); arg = "\"" ~ explorerPath ~ "\" " ~ arg; auto res = CreateProcessW(null, //explorerPath.toUTF16z, cast(wchar*)arg.toUTF16z, @@ -891,8 +890,6 @@ class Win32Platform : Platform { Log.e("showInFileManager failed to run explorer.exe"); return false; } - - //auto pid = spawnProcess(explorerPath, [arg], ); return true; }