-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.d
75 lines (63 loc) · 2.44 KB
/
app.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import std.stdio;
import std.algorithm;
import std.array;
import std.file;
import std.path;
import std.process;
import std.getopt;
import desktopfile.paths;
import desktopfile.file;
import isfreedesktop;
void main(string[] args)
{
string[] desktopDirs;
bool verbose;
getopt(args, "verbose", "Print name of each examined desktop file to standard output", &verbose);
if (args.length > 1) {
desktopDirs = args[1..$];
} else {
static if (isFreedesktop) {
import standardpaths;
string[] dataPaths = standardPaths(StandardPath.data);
desktopDirs = applicationsPaths() ~ dataPaths.map!(s => buildPath(s, "desktop-directories")).array ~ dataPaths.map!(s => buildPath(s, "templates")).array ~ standardPaths(StandardPath.startup) ~ writablePath(StandardPath.desktop);
}
version(Windows) {
try {
auto root = environment.get("SYSTEMDRIVE", "C:");
auto kdeDir = root ~ `\ProgramData\KDE\share`;
if (kdeDir.isDir) {
desktopDirs = [buildPath(kdeDir, `applications`), buildPath(kdeDir, `desktop-directories`), buildPath(kdeDir, `templates`), buildPath(kdeDir, `autostart`)];
}
} catch(Exception e) {
}
}
}
if (!desktopDirs.length) {
stderr.writeln("No desktop directories given nor could be detected");
stderr.writefln("Usage: %s [DIRECTORY]...", args[0]);
return;
}
writefln("Using directories: %-(%s, %)", desktopDirs);
foreach(dir; desktopDirs.filter!(s => s.exists && s.isDir())) {
foreach(entry; dir.dirEntries(SpanMode.depth).filter!(a => a.isFile() && (a.extension == ".desktop" || a.extension == ".directory"))) {
if (verbose) {
writeln(entry);
}
try {
auto df = new DesktopFile(entry);
if (!df.execValue().empty) {
auto execArgs = df.expandExecValue();
}
}
catch(IniLikeReadException e) {
stderr.writefln("Error reading %s: at %s: %s", entry, e.lineNumber, e.msg);
}
catch(DesktopExecException e) {
stderr.writefln("Error while expanding Exec value of %s: %s", entry, e.msg);
}
catch(Exception e) {
stderr.writefln("Error reading %s: %s", entry, e.msg);
}
}
}
}