From f0ac0dac1b2aca5cdab3d8f9cddf61417ae05bde Mon Sep 17 00:00:00 2001 From: FreeSlave Date: Wed, 8 Apr 2015 01:03:28 +0300 Subject: [PATCH] Move reading fonts.conf files to special version on Posix. Update README.md. Add License --- LICENSE_1_0.txt | 23 +++++++ README.md | 3 + dub.json | 16 +++++ examples/printdirs/dub.json | 18 +++-- source/standardpaths.d | 130 +++++++++++++++++++++--------------- 5 files changed, 132 insertions(+), 58 deletions(-) create mode 100644 LICENSE_1_0.txt diff --git a/LICENSE_1_0.txt b/LICENSE_1_0.txt new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/LICENSE_1_0.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index bb2be32..ba989c3 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ D library for getting standard paths (e.g. Pictures, Music, Documents). Inspired The library is in early development. API may change in future. Join discussions in Issues if you're interested. +## Compiler and platform support + +The library requires at least DMD v2.066 (or other compatible compiler) to compile. Currently works on Windows, Linux and FreeBSD. ## Examples diff --git a/dub.json b/dub.json index 79e2e96..5222b1b 100644 --- a/dub.json +++ b/dub.json @@ -9,4 +9,20 @@ "targetType" : "library", "subPackages" : ["./examples/printdirs", "./examples/findexecutable"], + + "configurations" : [ + { + "name" : "default" + }, + { + "name" : "linkedshell32", + "versions-windows":["LinkedShell32"], + "platforms" : ["windows"] + }, + { + "name" : "fontsconf", + "versions-posix" : ["fontsconf"], + "platforms" : ["posix"] + } + ] } diff --git a/examples/printdirs/dub.json b/examples/printdirs/dub.json index 4dc1019..d872bbf 100644 --- a/examples/printdirs/dub.json +++ b/examples/printdirs/dub.json @@ -1,9 +1,9 @@ { - "name": "printdirs", - "description": "A minimal D application.", - "copyright": "Copyright © 2015, freeslave", - "authors": ["freeslave"], - "targetPath" : "bin", + "name": "printdirs", + "description": "A minimal D application.", + "copyright": "Copyright © 2015, freeslave", + "authors": ["freeslave"], + "targetPath" : "bin", "targetType" : "executable", "targetName" : "printdirs", "dependencies" : {"standardpaths":"*"}, @@ -14,7 +14,13 @@ }, { "name" : "linkedshell32", - "versions-windows":["LinkedShell32"] + "versions-windows":["LinkedShell32"], + "platforms" : ["windows"] + }, + { + "name" : "fontsconf", + "versions-posix" : ["fontsconf"], + "platforms" : ["posix"] } ] } diff --git a/source/standardpaths.d b/source/standardpaths.d index ad9ecf0..eeaaf57 100644 --- a/source/standardpaths.d +++ b/source/standardpaths.d @@ -550,63 +550,94 @@ version(Windows) { return ["/usr/local/share", "/usr/share"]; } - private string[] readFontsConfig(string configFile) nothrow @trusted - { - //Should be changed in future since std.xml is deprecated - import std.xml; - - string[] paths; - try { - string contents = cast(string)read(configFile); - check(contents); - auto parser = new DocumentParser(contents); - parser.onEndTag["dir"] = (in Element xml) - { - string path = xml.text; - - if (path.length && path[0] == '~') { - path = maybeConcat(homeDir(), path[1..$]); - } else { - const(string)* prefix = "prefix" in xml.tag.attr; - if (prefix && *prefix == "xdg") { - string dataPath = writablePath(StandardPath.Data); - if (dataPath.length) { - path = buildPath(dataPath, path); + + version(fontsconf) { + private string[] readFontsConfig(string configFile) nothrow @trusted + { + //Should be changed in future since std.xml is deprecated + import std.xml; + + string[] paths; + try { + string contents = cast(string)read(configFile); + check(contents); + auto parser = new DocumentParser(contents); + parser.onEndTag["dir"] = (in Element xml) + { + string path = xml.text; + + if (path.length && path[0] == '~') { + path = maybeConcat(homeDir(), path[1..$]); + } else { + const(string)* prefix = "prefix" in xml.tag.attr; + if (prefix && *prefix == "xdg") { + string dataPath = writablePath(StandardPath.Data); + if (dataPath.length) { + path = buildPath(dataPath, path); + } } } - } - if (path.length) { - paths ~= path; - } - }; - parser.parse(); + if (path.length) { + paths ~= path; + } + }; + parser.parse(); + } + catch(Exception e) { + + } + return paths; } - catch(Exception e) { + + private string[] fontPaths() nothrow @trusted + { + string[] paths; + + string homeConfig = homeFontsConfig(); + if (homeConfig.length) { + paths ~= readFontsConfig(homeConfig); + } + enum configs = ["/etc/fonts/fonts.conf", //path on linux + "/usr/local/etc/fonts/fonts.conf"]; //path on freebsd + foreach(config; configs) { + paths ~= readFontsConfig(config); + } + return paths; } - return paths; - } - - private string[] fontPaths() nothrow @trusted - { - string[] paths; - string homeConfig = homeFontsConfig(); - if (homeConfig.length) { - paths ~= readFontsConfig(homeConfig); + private string homeFontsConfig() nothrow @trusted { + return maybeConcat(writablePath(StandardPath.Config), "/fontconfig/fonts.conf"); } - enum configs = ["/etc/fonts/fonts.conf", //path on linux - "/usr/local/etc/fonts/fonts.conf"]; //path on freebsd - foreach(config; configs) { - paths ~= readFontsConfig(config); + private string homeFontsPath() nothrow @trusted { + string[] paths = readFontsConfig(homeFontsConfig()); + if (paths.length) + return paths[0]; + return null; } - return paths; + + } else { + private string homeFontsPath() nothrow @trusted { + return maybeConcat(homeDir(), "/.fonts"); + } + + private string[] fontPaths() nothrow @trusted + { + enum localShare = "/usr/local/share/fonts"; + enum share = "/usr/share/fonts"; + + string homeFonts = homeFontsPath(); + if (homeFonts.length) { + return [homeFonts, localShare, share]; + } else { + return [localShare, share]; + } + } + } - private string homeFontsConfig() nothrow @trusted { - return maybeConcat(writablePath(StandardPath.Config), "/fontconfig/fonts.conf"); - } + /** * Returns user's runtime directory determined by $(B XDG_RUNTIME_DIR) environment variable. @@ -695,12 +726,7 @@ version(Windows) { case StandardPath.PublicShare: return xdgUserDir("PUBLICSHARE", "/Public"); case StandardPath.Fonts: - { - string[] paths = readFontsConfig(homeFontsConfig()); - if (paths.length) - return paths[0]; - return null; - } + return homeFontsPath(); case StandardPath.Applications: return maybeConcat(writablePath(StandardPath.Data), "/applications"); }