Simplify OS X bundle resource discovery, fix a sigsegv

This commit is contained in:
yoshibot 2016-05-17 22:56:49 -05:00
parent a12733f480
commit 928c6acf4b
1 changed files with 13 additions and 15 deletions

View File

@ -9,23 +9,21 @@ void OSX_GetResourcesPath(char * buffer)
mainBundle = CFBundleGetMainBundle(); mainBundle = CFBundleGetMainBundle();
if (mainBundle) if (mainBundle)
{ {
const int BUF_SIZE = 256; // because we somehow always know that
CFURLRef appUrlRef = CFBundleCopyBundleURL(mainBundle); CFURLRef appUrlRef = CFBundleCopyBundleURL(mainBundle);
CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle); CFStringRef macPath = CFURLCopyFileSystemPath(appUrlRef, kCFURLPOSIXPathStyle);
CFStringRef resources = CFStringCreateWithCString(kCFAllocatorMalloc, "/Contents/Resources", kCFStringEncodingASCII);
const void* rawarray[2] = {macPath, resources}; const char* rawPath = CFStringGetCStringPtr(macPath, kCFStringEncodingASCII);
CFArrayRef array = CFArrayCreate(kCFAllocatorMalloc, rawarray, 2, NULL);
CFStringRef separator = CFStringCreateWithCString(kCFAllocatorMalloc, "", kCFStringEncodingASCII); if (CFStringGetLength(macPath) + strlen("/Contents/Resources") < BUF_SIZE)
CFStringRef fullPath = CFStringCreateByCombiningStrings(kCFAllocatorMalloc, array, separator); {
const char * path = CFStringGetCStringPtr(fullPath, kCFStringEncodingASCII); strcpy(buffer, rawPath);
strcpy(buffer, path); strcat(buffer, "/Contents/Resources");
CFRelease(fullPath); }
path = NULL;
CFRelease(array);
CFRelease(resources);
CFRelease(macPath); CFRelease(macPath);
CFRelease(appUrlRef); CFRelease(appUrlRef);
//CFRelease(mainBundle);
CFRelease(separator);
} }
CFRelease(mainBundle);
} }