+static void _CFBundleCheckSupportedPlatform(CFMutableArrayRef mutableArray, UniChar *buff, CFIndex startLen, CFStringRef platformName, CFStringRef platformIdentifier) {
+ CFIndex buffLen = startLen, platformLen = CFStringGetLength(platformName), extLen = CFStringGetLength(_CFBundleInfoExtension);
+ CFMutableStringRef str;
+ Boolean isDir;
+ if (buffLen + platformLen + extLen < CFMaxPathSize) {
+ CFStringGetCharacters(platformName, CFRangeMake(0, platformLen), buff + buffLen);
+ buffLen += platformLen;
+ buff[buffLen++] = (UniChar)'.';
+ CFStringGetCharacters(_CFBundleInfoExtension, CFRangeMake(0, extLen), buff + buffLen);
+ buffLen += extLen;
+ str = CFStringCreateMutable(kCFAllocatorSystemDefault, 0);
+ CFStringAppendCharacters(str, buff, buffLen);
+ if (_CFIsResourceAtPath(str, &isDir) && !isDir && CFArrayGetFirstIndexOfValue(mutableArray, CFRangeMake(0, CFArrayGetCount(mutableArray)), platformIdentifier) < 0) CFArrayAppendValue(mutableArray, platformIdentifier);
+ CFRelease(str);
+ }
+}
+
+CF_EXPORT CFArrayRef _CFBundleGetSupportedPlatforms(CFBundleRef bundle) {
+ CFDictionaryRef infoDict = CFBundleGetInfoDictionary(bundle);
+ CFArrayRef platformArray = infoDict ? (CFArrayRef)CFDictionaryGetValue(infoDict, _kCFBundleSupportedPlatformsKey) : NULL;
+ if (platformArray && CFGetTypeID(platformArray) != CFArrayGetTypeID()) {
+ platformArray = NULL;
+ CFDictionaryRemoveValue((CFMutableDictionaryRef)infoDict, _kCFBundleSupportedPlatformsKey);
+ }
+ if (!platformArray) {
+ CFURLRef infoPlistURL = infoDict ? (CFURLRef)CFDictionaryGetValue(infoDict, _kCFBundleInfoPlistURLKey) : NULL, absoluteURL;
+ CFStringRef infoPlistPath;
+ UniChar buff[CFMaxPathSize];
+ CFIndex buffLen, infoLen = CFStringGetLength(_CFBundleInfoURLFromBaseNoExtension3), startLen, extLen = CFStringGetLength(_CFBundleInfoExtension);
+ if (infoPlistURL) {
+ CFMutableArrayRef mutableArray = CFArrayCreateMutable(CFGetAllocator(bundle), 0, &kCFTypeArrayCallBacks);
+ absoluteURL = CFURLCopyAbsoluteURL(infoPlistURL);
+ infoPlistPath = CFURLCopyFileSystemPath(absoluteURL, PLATFORM_PATH_STYLE);
+ CFRelease(absoluteURL);
+ buffLen = CFStringGetLength(infoPlistPath);
+ if (buffLen > CFMaxPathSize) buffLen = CFMaxPathSize;
+ CFStringGetCharacters(infoPlistPath, CFRangeMake(0, buffLen), buff);
+ CFRelease(infoPlistPath);
+ if (buffLen > 0) {
+ buffLen = _CFStartOfLastPathComponent(buff, buffLen);
+ if (buffLen > 0 && buffLen + infoLen + extLen < CFMaxPathSize) {
+ CFStringGetCharacters(_CFBundleInfoURLFromBaseNoExtension3, CFRangeMake(0, infoLen), buff + buffLen);
+ buffLen += infoLen;
+ buff[buffLen++] = (UniChar)'-';
+ startLen = buffLen;
+ _CFBundleCheckSupportedPlatform(mutableArray, buff, startLen, CFSTR("macos"), CFSTR("MacOS"));
+ _CFBundleCheckSupportedPlatform(mutableArray, buff, startLen, CFSTR("macosx"), CFSTR("MacOS"));
+ _CFBundleCheckSupportedPlatform(mutableArray, buff, startLen, CFSTR("iphoneos"), CFSTR("iPhoneOS"));
+ _CFBundleCheckSupportedPlatform(mutableArray, buff, startLen, CFSTR("windows"), CFSTR("Windows"));
+ }
+ }
+ if (CFArrayGetCount(mutableArray) > 0) {
+ platformArray = (CFArrayRef)mutableArray;
+ CFDictionarySetValue((CFMutableDictionaryRef)infoDict, _kCFBundleSupportedPlatformsKey, platformArray);
+ }
+ CFRelease(mutableArray);
+ }
+ }
+ return platformArray;
+}
+
+CF_EXPORT CFStringRef _CFBundleGetCurrentPlatform(void) {