Skip to content

Commit

Permalink
Update for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
FreeSlave committed Apr 28, 2016
1 parent 4879b2d commit de11545
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
45 changes: 33 additions & 12 deletions examples/util/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import std.process;
import std.path;

import desktopfile.file;
import findexecutable;
import isfreedesktop;

@safe string currentLocale() nothrow
Expand All @@ -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 <read|exec|open|start|write> <desktop-file> <optional arguments>", args[0]);
return;
Expand All @@ -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);

Expand All @@ -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) {
Expand All @@ -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());
Expand Down
9 changes: 7 additions & 2 deletions source/desktopfile/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ package {

static if( __VERSION__ < 2066 ) enum nogc = 1;

import findexecutable;
import isfreedesktop;
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -579,8 +586,6 @@ string[] getTerminalCommand() nothrow @trusted
}
}

import findexecutable;

string[] paths;
collectException(binPaths().array, paths);

Expand Down

0 comments on commit de11545

Please sign in to comment.