desktopId - multiple declarations

Function desktopId

See Desktop File ID

string desktopId(Range) (
  string fileName,
  Range appsPaths
)
if (isInputRange!Range && is(ElementType!Range : string));

Parameters

NameDescription
fileName Desktop file.
appsPaths Range of base application paths.

Returns

Desktop file ID or empty string if file does not have an ID.

See Also

applicationsPaths

Example

string[] appPaths;
string filePath, nestedFilePath, wrongFilePath;

version(Windows) {
    appPaths = [`C:\ProgramData\KDE\share\applications`, `C:\Users\username\.kde\share\applications`];
    filePath = `C:\ProgramData\KDE\share\applications\example.desktop`;
    nestedFilePath = `C:\ProgramData\KDE\share\applications\kde\example.desktop`;
    wrongFilePath = `C:\ProgramData\desktop\example.desktop`;
} else {
    appPaths = ["/usr/share/applications", "/usr/local/share/applications"];
    filePath = "/usr/share/applications/example.desktop";
    nestedFilePath = "/usr/share/applications/kde/example.desktop";
    wrongFilePath = "/etc/desktop/example.desktop";
}

assert(desktopId(nestedFilePath, appPaths) == "kde-example.desktop");
assert(desktopId(filePath, appPaths) == "example.desktop");
assert(desktopId(wrongFilePath, appPaths).empty);
assert(desktopId("", appPaths).empty);

Function desktopId

See Desktop File ID

string desktopId (
  string fileName
) nothrow @trusted;

Returns

Desktop file ID or empty string if file does not have an ID.

Parameters

NameDescription
fileName Desktop file.

Note

This function retrieves applications paths each time it's called and therefore can impact performance. To avoid this issue use the overload with argument.

See Also

applicationsPaths