mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-28 13:21:10 +00:00
Simplify OS X bundle resource discovery, fix a sigsegv
This commit is contained in:
parent
a12733f480
commit
928c6acf4b
1 changed files with 13 additions and 15 deletions
|
@ -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);
|
||||||
}
|
}
|
Loading…
Reference in a new issue