From 23e8e19f5c25c46a5e9543b26bc90de4e887584e Mon Sep 17 00:00:00 2001 From: Stefan Gartner Date: Mon, 12 May 2003 14:59:08 +0000 Subject: [PATCH] added function to get the full path to the application bundle on os x --- source/blender/blenlib/BLI_blenlib.h | 9 +++++++++ source/blender/blenlib/intern/util.c | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index b5dbf002b84..8d07c7668f8 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -203,6 +203,15 @@ void BLI_free_file_lines(struct LinkNode *lines); */ void BLI_where_am_i(char *fullname, char *name); + /** + * determines the full path to the application bundle on OS X + * + * @return path to application bundle + */ +#ifdef __APPLE__ +char* BLI_getbundle(void); +#endif + /* BLI_storage.h */ int BLI_filesize(int file); double BLI_diskfree(char *dir); diff --git a/source/blender/blenlib/intern/util.c b/source/blender/blenlib/intern/util.c index eb2109ba807..80813b1119e 100644 --- a/source/blender/blenlib/intern/util.c +++ b/source/blender/blenlib/intern/util.c @@ -69,6 +69,12 @@ #include #endif +#include + +#ifdef __APPLE__ +#include +#endif + /* local */ static int add_win32_extension(char *name); @@ -834,3 +840,21 @@ void BLI_where_am_i(char *fullname, char *name) } } +/* + * returns absolute path to the app bundle + * only useful on OS X + */ +#ifdef __APPLE__ +char* BLI_getbundle(void) { + CFURLRef bundleURL; + CFStringRef pathStr; + char path[MAXPATHLEN]; + CFBundleRef mainBundle = CFBundleGetMainBundle(); + + bundleURL = CFBundleCopyBundleURL(mainBundle); + pathStr = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle); + CFStringGetCString(pathStr, path, MAXPATHLEN, kCFStringEncodingASCII); + return path; +} +#endif +