desktopId

  1. string desktopId(string fileName, Range appsPaths)
    string
    desktopId
    (
    Range
    )
    (
    string fileName
    ,
    Range appsPaths
    )
    if (
    isInputRange!Range &&
    is(ElementType!Range : string)
    )
  2. string desktopId(string fileName)

Parameters

fileName
Type: string

Desktop file.

appsPaths
Type: Range

Range of base application paths.

Return Value

Type: string

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

Examples

1 string[] appPaths;
2 string filePath, nestedFilePath, wrongFilePath;
3 
4 version(Windows) {
5     appPaths = [`C:\ProgramData\KDE\share\applications`, `C:\Users\username\.kde\share\applications`];
6     filePath = `C:\ProgramData\KDE\share\applications\example.desktop`;
7     nestedFilePath = `C:\ProgramData\KDE\share\applications\kde\example.desktop`;
8     wrongFilePath = `C:\ProgramData\desktop\example.desktop`;
9 } else {
10     appPaths = ["/usr/share/applications", "/usr/local/share/applications"];
11     filePath = "/usr/share/applications/example.desktop";
12     nestedFilePath = "/usr/share/applications/kde/example.desktop";
13     wrongFilePath = "/etc/desktop/example.desktop";
14 }
15 
16 assert(desktopId(nestedFilePath, appPaths) == "kde-example.desktop");
17 assert(desktopId(filePath, appPaths) == "example.desktop");
18 assert(desktopId(wrongFilePath, appPaths).empty);
19 assert(desktopId("", appPaths).empty);

See Also

desktopfile.paths.applicationsPaths

Meta