diff --git a/README.md b/README.md index 426eec7..7410857 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This functionality was moved to the separate library. See [findexecutable](http: ## Platform support -Currently works on Windows, Linux and FreeBSD. Mac OS X support is experimental. +Works on Windows, Linux, FreeBSD and Mac OS X. ## Running examples @@ -21,6 +21,10 @@ Prints some standard paths to stdout. dub run :printdirs --build=release +On OSX it also can be built to use Cocoa instead of Carbon (tested with ldc 1.0.0): + + dub run :printdirs --config=cocoa --compiler=ldc2 + ### [Get path](examples/getpath/source/app.d) Get path of given type, verify it exists or create if it does not. @@ -130,4 +134,5 @@ On Windows it utilizes [SHGetSpecialFolderPath](https://msdn.microsoft.com/en-us ### Mac OS X -Uses FSFindFolder from Carbon framework. It's deprecated now and should be replaced with Cocoa where possible. [See here](http://cocoadev.com/ApplicationSupportFolder). +Depending on configuration the library uses FSFindFolder from Carbon framework or URLForDirectory from Cocoa. +[See here](http://cocoadev.com/ApplicationSupportFolder). diff --git a/source/standardpaths.d b/source/standardpaths.d index 50823af..26c81ab 100644 --- a/source/standardpaths.d +++ b/source/standardpaths.d @@ -55,6 +55,11 @@ version(Windows) { return start.empty ? null : start ~ path; } + string maybeBuild(string start, string path) nothrow @safe + { + return start.empty ? null : buildPath(start, path); + } + string verifyIfNeeded(string path, bool shouldVerify) nothrow @trusted { if (path.length && shouldVerify) { @@ -739,7 +744,12 @@ version(Windows) { enum fileProtocol = "file://"; if (str.startsWith(fileProtocol)) { - return str.decode()[fileProtocol.length..$]; + str = str.decode()[fileProtocol.length..$]; + if (str.length > 1 && str[$-1] == '/') { + return str[0..$-1]; + } else { + return str; + } } } catch(Exception e) { @@ -882,7 +892,7 @@ version(Windows) { version(StandardPathsCocoa) { final switch(type) { case StandardPath.config: - return domainDir(NSLibraryDirectory, NSUserDomainMask, shouldCreate).maybeConcat("/Preferences").createIfNeeded(shouldCreate); + return domainDir(NSLibraryDirectory, NSUserDomainMask, shouldCreate).maybeBuild("Preferences").createIfNeeded(shouldCreate); case StandardPath.cache: return domainDir(NSCachesDirectory, NSUserDomainMask, shouldCreate); case StandardPath.data: @@ -904,7 +914,7 @@ version(Windows) { case StandardPath.publicShare: return domainDir(NSSharedPublicDirectory, NSUserDomainMask, shouldCreate); case StandardPath.fonts: - return domainDir(NSLibraryDirectory, NSUserDomainMask, shouldCreate).maybeConcat("/Fonts").createIfNeeded(shouldCreate); + return domainDir(NSLibraryDirectory, NSUserDomainMask, shouldCreate).maybeBuild("Fonts").createIfNeeded(shouldCreate); case StandardPath.applications: return domainDir(NSApplicationDirectory, NSUserDomainMask, shouldCreate); case StandardPath.startup: @@ -958,7 +968,7 @@ version(Windows) { version(StandardPathsCocoa) { switch(type) { case StandardPath.fonts: - commonPath = domainDir(NSLibraryDirectory, NSSystemDomainMask).maybeConcat("/Fonts"); + commonPath = domainDir(NSLibraryDirectory, NSSystemDomainMask).maybeBuild("Fonts"); break; case StandardPath.applications: commonPath = domainDir(NSApplicationDirectory, NSSystemDomainMask);