diff --git a/README.md b/README.md index 0cbfd8c..4eaf24e 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,12 @@ When passing base name of desktop file instead of path it's treated like desktop dub run :util -- exec python2.7.desktop dub run :util -- exec kde4-kate.desktop - + +On non-freedesktop systems appPath should be passed and PATH variable prepared. Example using cmd on Windows (KDE installed): + + set PATH=C:\ProgramData\KDE\bin + dub run :util -- --appPath=C:\ProgramData\KDE\share\applications exec kde4-gwenview.desktop + ### [Desktop test](examples/test/source/app.d) Parses all .desktop files in system's applications paths (usually /usr/local/share/applicatons and /usr/share/applications) and on the user's Desktop. @@ -183,3 +188,7 @@ Uses the alternative way of starting desktop file. Instead of constructing Deskt dub run :shoot -- $HOME/Desktop/vlc.desktop dub run :shoot -- /usr/share/applications/python2.7.desktop + +On Windows (KDE installed): + + dub run :shoot -- C:\ProgramData\KDE\share\applications\kde4\gwenview.desktop \ No newline at end of file diff --git a/examples/util/source/app.d b/examples/util/source/app.d index 3ff3424..4a407fd 100644 --- a/examples/util/source/app.d +++ b/examples/util/source/app.d @@ -4,6 +4,7 @@ import std.process; import std.path; import desktopfile.file; +import findexecutable; import isfreedesktop; @safe string currentLocale() nothrow @@ -18,6 +19,13 @@ import isfreedesktop; void main(string[] args) { + string action; + string[] appPaths; + getopt(args, + "action", "Action to run", &action, + "appPath", "Path of applications directory", &appPaths + ); + if (args.length < 3) { writefln("Usage: %s ", args[0]); return; @@ -27,17 +35,33 @@ void main(string[] args) string inFile = args[2]; string locale = currentLocale(); - static if (isFreedesktop) { - if (inFile == inFile.baseName && inFile.extension == ".desktop") { - string desktopId = inFile; - inFile = findDesktopFile(desktopId); - if (inFile is null) { - stderr.writeln("Could not find desktop file with such id: ", desktopId); - return; + if (appPaths.length == 0) { + static if (isFreedesktop) { + import desktopfile.paths; + appPaths = applicationsPaths(); + } + version(Windows) { + try { + auto root = environment.get("SYSTEMDRIVE", "C:"); + auto kdeAppDir = root ~ `\ProgramData\KDE\share\applications`; + if (kdeAppDir.isDir) { + appPaths = [kdeAppDir]; + } + } catch(Exception e) { + } } } + if (inFile == inFile.baseName && inFile.extension == ".desktop") { + string desktopId = inFile; + inFile = findDesktopFile(desktopId, appPaths); + if (inFile is null) { + stderr.writeln("Could not find desktop file with such id: ", desktopId); + return; + } + } + if (command == "read") { auto df = new DesktopFile(inFile); @@ -63,8 +87,6 @@ void main(string[] args) } } else if (command == "exec") { auto df = new DesktopFile(inFile); - string action; - getopt(args, "action", "Action to run", &action); if (action.length) { auto desktopAction = df.action(action); if (desktopAction is null) { @@ -74,11 +96,10 @@ void main(string[] args) } } else { string[] urls = args[3..$]; - writefln("Exec: %(%s %)", df.expandExecString(urls, locale)); + string[] appArgs = df.expandExecString(urls, locale); + writefln("Exec: %(%s %)", appArgs); df.startApplication(urls, locale); } - - } else if (command == "open") { auto df = new DesktopFile(inFile); writeln("Link: ", df.url()); diff --git a/source/desktopfile/utils.d b/source/desktopfile/utils.d index ae6b8df..163bcb7 100644 --- a/source/desktopfile/utils.d +++ b/source/desktopfile/utils.d @@ -31,6 +31,7 @@ package { static if( __VERSION__ < 2066 ) enum nogc = 1; + import findexecutable; import isfreedesktop; } @@ -81,6 +82,12 @@ package @trusted File getNullStderr() package @trusted Pid execProcess(string[] args, string workingDirectory = null) { + version(Windows) { + if (args.length && args[0].baseName == args[0]) { + args[0] = findExecutable(args[0]); + } + } + static if( __VERSION__ < 2066 ) { return spawnProcess(args, getNullStdin(), getNullStdout(), getNullStderr(), null, Config.none); } else { @@ -579,8 +586,6 @@ string[] getTerminalCommand() nothrow @trusted } } - import findexecutable; - string[] paths; collectException(binPaths().array, paths);