range of base application paths to check if this file belongs to one of them.
Desktop file ID or empty string if file does not have an ID.
1 string contents = 2 `[Desktop Entry] 3 Name=Program 4 Type=Directory`; 5 6 string[] appPaths; 7 string filePath, nestedFilePath, wrongFilePath; 8 9 version(Windows) { 10 appPaths = [`C:\ProgramData\KDE\share\applications`, `C:\Users\username\.kde\share\applications`]; 11 filePath = `C:\ProgramData\KDE\share\applications\example.desktop`; 12 nestedFilePath = `C:\ProgramData\KDE\share\applications\kde\example.desktop`; 13 wrongFilePath = `C:\ProgramData\desktop\example.desktop`; 14 } else { 15 appPaths = ["/usr/share/applications", "/usr/local/share/applications"]; 16 filePath = "/usr/share/applications/example.desktop"; 17 nestedFilePath = "/usr/share/applications/kde/example.desktop"; 18 wrongFilePath = "/etc/desktop/example.desktop"; 19 } 20 21 auto df = new DesktopFile(iniLikeStringReader(contents), nestedFilePath); 22 assert(df.id(appPaths) == "kde-example.desktop"); 23 24 df = new DesktopFile(iniLikeStringReader(contents), filePath); 25 assert(df.id(appPaths) == "example.desktop"); 26 27 df = new DesktopFile(iniLikeStringReader(contents), wrongFilePath); 28 assert(df.id(appPaths).empty); 29 30 df = new DesktopFile(iniLikeStringReader(contents)); 31 assert(df.id(appPaths).empty); 32
desktopfile.paths.applicationsPaths, desktopfile.utils.desktopId
See Desktop File ID