Skip to content

Commit

Permalink
Some fixes regarding Cocoa support
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlade authored and Vlade committed May 20, 2016
1 parent 9c8a8b1 commit d575f3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down Expand Up @@ -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).
18 changes: 14 additions & 4 deletions source/standardpaths.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d575f3c

Please sign in to comment.