diff --git a/README.md b/README.md index 0fc72fb..f7e48cd 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ Start desktoptest on specified directories: Example using cmd on Windows (KDE installed): - dub run desktopfile:desktoptest -- "%SYSTEMDRIVE%\ProgramData\KDE\share\applications" "%APPDATA%\.kde\share" + set KDE_SHARE="%SYSTEMDRIVE%\ProgramData\KDE\share" + dub run desktopfile:desktoptest -- %KDE_SHARE%\applications %KDE_SHARE%\templates" %KDE_SHARE%\desktop-directories %KDE_SHARE%\autostart \ No newline at end of file diff --git a/examples/desktoptest/source/app.d b/examples/desktoptest/source/app.d index 2766d80..bdf5d53 100644 --- a/examples/desktoptest/source/app.d +++ b/examples/desktoptest/source/app.d @@ -40,7 +40,7 @@ void main(string[] args) 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")) { + foreach(entry; dir.dirEntries(SpanMode.depth).filter!(a => a.isFile() && (a.extension == ".desktop" || a.extension == ".directory"))) { debug writeln(entry); try { new DesktopFile(entry); diff --git a/source/desktopfile.d b/source/desktopfile.d index 1ac424f..f52c89e 100644 --- a/source/desktopfile.d +++ b/source/desktopfile.d @@ -645,16 +645,30 @@ public: string contents = `[Desktop Entry] Name=Program -Type=Application`; +Type=Directory`; - auto appPaths = ["/usr/share/applications", "/usr/local/share/applications"]; - auto df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, "/usr/share/applications/de/example.desktop"); - assert(df.id(appPaths) == "de-example.desktop"); + string[] appPaths; + string filePath, nestedFilePath, wrongFilePath; - df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, "/usr/local/share/applications/example.desktop"); + 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"; + } + + auto df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, nestedFilePath); + assert(df.id(appPaths) == "kde-example.desktop"); + + df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, filePath); assert(df.id(appPaths) == "example.desktop"); - df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, "/etc/desktop/example.desktop"); + df = new DesktopFile(iniLikeStringReader(contents), DesktopFile.ReadOptions.noOptions, wrongFilePath); assert(df.id(appPaths).empty); }