소스 검색

added os_get_home_path and os_mkdir to osx cocoa platform

Palana 12 년 전
부모
커밋
1bd2b9fd99
2개의 변경된 파일43개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      libobs/CMakeLists.txt
  2. 40 0
      libobs/util/platform-cocoa.m

+ 3 - 1
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)

+ 40 - 0
libobs/util/platform-cocoa.c → libobs/util/platform-cocoa.m

@@ -29,10 +29,14 @@
 #include <time.h>
 #include <unistd.h>
 
+#include <sys/stat.h>
+
 #include <CoreServices/CoreServices.h>
 #include <mach/mach.h>
 #include <mach/mach_time.h>
 
+#import <Cocoa/Cocoa.h>
+
 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;
+}