diff --git a/libobs/CMakeLists.txt b/libobs/CMakeLists.txt index ce80cccff..346863e2a 100644 --- a/libobs/CMakeLists.txt +++ b/libobs/CMakeLists.txt @@ -5,7 +5,9 @@ if(WIN32) elseif(APPLE AND UNIX) set(libobs_platform_src obs-cocoa.c - util/platform-cocoa.c) + util/platform-cocoa.m) + set_source_files_properties(${libobs_platform_src} + PROPERTIES LANGUAGE C) add_definitions("-DHAVE_STRTOLL") find_library(COCOA Cocoa) mark_as_advanced(COCOA) diff --git a/libobs/util/platform-cocoa.c b/libobs/util/platform-cocoa.m similarity index 77% rename from libobs/util/platform-cocoa.c rename to libobs/util/platform-cocoa.m index f4bd80fe5..f741f7074 100644 --- a/libobs/util/platform-cocoa.c +++ b/libobs/util/platform-cocoa.m @@ -29,10 +29,14 @@ #include #include +#include + #include #include #include +#import + void *os_dlopen(const char *path) { struct dstr dylib_name; @@ -98,3 +102,39 @@ uint64_t os_gettime_ms(void) return os_gettime_ns()/1000000; } +char *os_get_home_path(void) +{ + NSArray *paths = NSSearchPathForDirectoriesInDomains( + NSApplicationSupportDirectory, NSUserDomainMask, YES); + + if([paths count] == 0) + bcrash("Could not get home directory (platform-cocoa)"); + + NSString *application_support = paths[0];// objectAtIndex:0]; + + NSUInteger len = [application_support + lengthOfBytesUsingEncoding:NSUTF8StringEncoding]; + + char *path = bmalloc(len+1); + + path[len] = 0; + + memcpy(path, [application_support UTF8String], len); + + [application_support release]; + + [paths release]; + + return path; +} + +int os_mkdir(const char *path) +{ + if(!mkdir(path, 0777)) + return MKDIR_SUCCESS; + + if(errno == EEXIST) + return MKDIR_EXISTS; + + return MKDIR_ERROR; +}