From bae3d1b03675a26c287866994cb62b7bcd9b6b17 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Fri, 3 Jan 2014 21:52:57 -0500 Subject: [PATCH] implement mac OS X version of get desktop path --- src/platform_osx.mm | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/platform_osx.mm b/src/platform_osx.mm index 41dc7be..e84f022 100644 --- a/src/platform_osx.mm +++ b/src/platform_osx.mm @@ -1,7 +1,35 @@ #include "config.h" +#include + +#import + +static void ensure_trailing_slash(std::string& path) +{ + if (path.size() && path[path.size()-1] != '/') { + path += "/"; + } +} + +static std::string get_desktop_dir() +{ + std::string ret; + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES); + NSString *path = [paths objectAtIndex: 0]; + + ret = [path fileSystemRepresentation]; + + [pool drain]; + + ensure_trailing_slash(ret); + return ret; +} + void Config::setupPaths() { - -} \ No newline at end of file + desktopPath = get_desktop_dir(); +} +