2 * Copyright (c) 2012 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 Copyright (c) 1999-2011, Apple Inc. All rights reserved.
28 #if !defined(__COREFOUNDATION_CFBUNDLE__)
29 #define __COREFOUNDATION_CFBUNDLE__ 1
31 #include <CoreFoundation/CFBase.h>
32 #include <CoreFoundation/CFArray.h>
33 #include <CoreFoundation/CFDictionary.h>
34 #include <CoreFoundation/CFError.h>
35 #include <CoreFoundation/CFString.h>
36 #include <CoreFoundation/CFURL.h>
40 typedef struct __CFBundle
*CFBundleRef
;
41 typedef struct __CFBundle
*CFPlugInRef
;
43 /* ===================== Standard Info.plist keys ===================== */
45 const CFStringRef kCFBundleInfoDictionaryVersionKey
;
46 /* The version of the Info.plist format */
48 const CFStringRef kCFBundleExecutableKey
;
49 /* The name of the executable in this bundle, if any */
51 const CFStringRef kCFBundleIdentifierKey
;
52 /* The bundle identifier (for CFBundleGetBundleWithIdentifier()) */
54 const CFStringRef kCFBundleVersionKey
;
55 /* The version number of the bundle. For Mac OS 9 style version numbers (for example "2.5.3d5"), */
56 /* clients can use CFBundleGetVersionNumber() instead of accessing this key directly since that */
57 /* function will properly convert the version string into its compact integer representation. */
59 const CFStringRef kCFBundleDevelopmentRegionKey
;
60 /* The name of the development language of the bundle. */
62 const CFStringRef kCFBundleNameKey
;
63 /* The human-readable name of the bundle. This key is often found in the InfoPlist.strings since it is usually localized. */
65 const CFStringRef kCFBundleLocalizationsKey
;
66 /* Allows an unbundled application that handles localization itself to specify which localizations it has available. */
68 /* ===================== Finding Bundles ===================== */
71 CFBundleRef
CFBundleGetMainBundle(void);
74 CFBundleRef
CFBundleGetBundleWithIdentifier(CFStringRef bundleID
);
75 /* A bundle can name itself by providing a key in the info dictionary. */
76 /* This facility is meant to allow bundle-writers to get hold of their */
77 /* bundle from their code without having to know where it was on the disk. */
78 /* This is meant to be a replacement mechanism for +bundleForClass: users. */
79 /* Note that this does not search for bundles on the disk; it will locate */
80 /* only bundles already loaded or otherwise known to the current process. */
83 CFArrayRef
CFBundleGetAllBundles(void);
84 /* This is potentially expensive, and not thread-safe. Use with care. */
85 /* Best used for debuggging or other diagnostic purposes. */
87 /* ===================== Creating Bundles ===================== */
90 CFTypeID
CFBundleGetTypeID(void);
93 CFBundleRef
CFBundleCreate(CFAllocatorRef allocator
, CFURLRef bundleURL
);
94 /* Might return an existing instance with the ref-count bumped. */
97 CFArrayRef
CFBundleCreateBundlesFromDirectory(CFAllocatorRef allocator
, CFURLRef directoryURL
, CFStringRef bundleType
);
98 /* Create instances for all bundles in the given directory matching the given type */
99 /* (or all of them if bundleType is NULL). Instances are created using CFBundleCreate() and are not released. */
101 /* ==================== Basic Bundle Info ==================== */
104 CFURLRef
CFBundleCopyBundleURL(CFBundleRef bundle
);
107 CFTypeRef
CFBundleGetValueForInfoDictionaryKey(CFBundleRef bundle
, CFStringRef key
);
108 /* Returns a localized value if available, otherwise the global value. */
109 /* This is the recommended function for examining the info dictionary. */
112 CFDictionaryRef
CFBundleGetInfoDictionary(CFBundleRef bundle
);
113 /* This is the global info dictionary. Note that CFBundle may add */
114 /* extra keys to the dictionary for its own use. */
117 CFDictionaryRef
CFBundleGetLocalInfoDictionary(CFBundleRef bundle
);
118 /* This is the localized info dictionary. */
121 void CFBundleGetPackageInfo(CFBundleRef bundle
, UInt32
*packageType
, UInt32
*packageCreator
);
124 CFStringRef
CFBundleGetIdentifier(CFBundleRef bundle
);
127 UInt32
CFBundleGetVersionNumber(CFBundleRef bundle
);
130 CFStringRef
CFBundleGetDevelopmentRegion(CFBundleRef bundle
);
133 CFURLRef
CFBundleCopySupportFilesDirectoryURL(CFBundleRef bundle
);
136 CFURLRef
CFBundleCopyResourcesDirectoryURL(CFBundleRef bundle
);
139 CFURLRef
CFBundleCopyPrivateFrameworksURL(CFBundleRef bundle
);
142 CFURLRef
CFBundleCopySharedFrameworksURL(CFBundleRef bundle
);
145 CFURLRef
CFBundleCopySharedSupportURL(CFBundleRef bundle
);
148 CFURLRef
CFBundleCopyBuiltInPlugInsURL(CFBundleRef bundle
);
150 /* ------------- Basic Bundle Info without a CFBundle instance ------------- */
151 /* This API is provided to enable developers to retrieve basic information */
152 /* about a bundle without having to create an instance of CFBundle. */
153 /* Because of caching behavior when a CFBundle instance exists, it will be faster */
154 /* to actually create a CFBundle if you need to retrieve multiple pieces of info. */
156 CFDictionaryRef
CFBundleCopyInfoDictionaryInDirectory(CFURLRef bundleURL
);
159 Boolean
CFBundleGetPackageInfoInDirectory(CFURLRef url
, UInt32
*packageType
, UInt32
*packageCreator
);
161 /* ==================== Resource Handling API ==================== */
164 CFURLRef
CFBundleCopyResourceURL(CFBundleRef bundle
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subDirName
);
167 CFArrayRef
CFBundleCopyResourceURLsOfType(CFBundleRef bundle
, CFStringRef resourceType
, CFStringRef subDirName
);
170 CFStringRef
CFBundleCopyLocalizedString(CFBundleRef bundle
, CFStringRef key
, CFStringRef value
, CFStringRef tableName
) CF_FORMAT_ARGUMENT(2);
172 #define CFCopyLocalizedString(key, comment) \
173 CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), NULL)
174 #define CFCopyLocalizedStringFromTable(key, tbl, comment) \
175 CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), (tbl))
176 #define CFCopyLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
177 CFBundleCopyLocalizedString((bundle), (key), (key), (tbl))
178 #define CFCopyLocalizedStringWithDefaultValue(key, tbl, bundle, value, comment) \
179 CFBundleCopyLocalizedString((bundle), (key), (value), (tbl))
181 /* ------------- Resource Handling without a CFBundle instance ------------- */
182 /* This API is provided to enable developers to use the CFBundle resource */
183 /* searching policy without having to create an instance of CFBundle. */
184 /* Because of caching behavior when a CFBundle instance exists, it will be faster */
185 /* to actually create a CFBundle if you need to access several resources. */
188 CFURLRef
CFBundleCopyResourceURLInDirectory(CFURLRef bundleURL
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subDirName
);
191 CFArrayRef
CFBundleCopyResourceURLsOfTypeInDirectory(CFURLRef bundleURL
, CFStringRef resourceType
, CFStringRef subDirName
);
193 /* =========== Localization-specific Resource Handling API =========== */
194 /* This API allows finer-grained control over specific localizations, */
195 /* as distinguished from the above API, which always uses the user's */
196 /* preferred localizations for the bundle in the current app context. */
199 CFArrayRef
CFBundleCopyBundleLocalizations(CFBundleRef bundle
);
200 /* Lists the localizations that a bundle contains. */
203 CFArrayRef
CFBundleCopyPreferredLocalizationsFromArray(CFArrayRef locArray
);
204 /* Given an array of possible localizations, returns the one or more */
205 /* of them that CFBundle would use in the current application context. */
206 /* To determine the localizations that would be used for a particular */
207 /* bundle in the current application context, apply this function to the */
208 /* result of CFBundleCopyBundleLocalizations(). */
211 CFArrayRef
CFBundleCopyLocalizationsForPreferences(CFArrayRef locArray
, CFArrayRef prefArray
);
212 /* Given an array of possible localizations, returns the one or more of */
213 /* them that CFBundle would use, without reference to the current application */
214 /* context, if the user's preferred localizations were given by prefArray. */
215 /* If prefArray is NULL, the current user's actual preferred localizations will */
216 /* be used. This is not the same as CFBundleCopyPreferredLocalizationsFromArray(), */
217 /* because that function takes the current application context into account. */
218 /* To determine the localizations that another application would use, apply */
219 /* this function to the result of CFBundleCopyBundleLocalizations(). */
222 CFURLRef
CFBundleCopyResourceURLForLocalization(CFBundleRef bundle
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subDirName
, CFStringRef localizationName
);
225 CFArrayRef
CFBundleCopyResourceURLsOfTypeForLocalization(CFBundleRef bundle
, CFStringRef resourceType
, CFStringRef subDirName
, CFStringRef localizationName
);
226 /* The localizationName argument to CFBundleCopyResourceURLForLocalization() or */
227 /* CFBundleCopyResourceURLsOfTypeForLocalization() must be identical to one of the */
228 /* localizations in the bundle, as returned by CFBundleCopyBundleLocalizations(). */
229 /* It is recommended that either CFBundleCopyPreferredLocalizationsFromArray() or */
230 /* CFBundleCopyLocalizationsForPreferences() be used to select the localization. */
232 /* =================== Unbundled application info ===================== */
233 /* This API is provided to enable developers to retrieve bundle-related */
234 /* information about an application that may be bundled or unbundled. */
236 CFDictionaryRef
CFBundleCopyInfoDictionaryForURL(CFURLRef url
);
237 /* For a directory URL, this is equivalent to CFBundleCopyInfoDictionaryInDirectory(). */
238 /* For a plain file URL representing an unbundled executable, this will attempt to read */
239 /* an info dictionary from the (__TEXT, __info_plist) section, if it is a Mach-o file, */
240 /* or from a 'plst' resource. */
243 CFArrayRef
CFBundleCopyLocalizationsForURL(CFURLRef url
);
244 /* For a directory URL, this is equivalent to calling CFBundleCopyBundleLocalizations() */
245 /* on the corresponding bundle. For a plain file URL representing an unbundled executable, */
246 /* this will attempt to determine its localizations using the CFBundleLocalizations and */
247 /* CFBundleDevelopmentRegion keys in the dictionary returned by CFBundleCopyInfoDictionaryForURL,*/
248 /* or from a 'vers' resource if those are not present. */
251 CFArrayRef
CFBundleCopyExecutableArchitecturesForURL(CFURLRef url
) CF_AVAILABLE(10_5
, 2_0
);
252 /* For a directory URL, this is equivalent to calling CFBundleCopyExecutableArchitectures() */
253 /* on the corresponding bundle. For a plain file URL representing an unbundled executable, */
254 /* this will return the architectures it provides, if it is a Mach-o file, or NULL otherwise. */
256 /* ==================== Primitive Code Loading API ==================== */
257 /* This API abstracts the various different executable formats supported on */
258 /* various platforms. It can load DYLD, CFM, or DLL shared libraries (on their */
259 /* appropriate platforms) and gives a uniform API for looking up functions. */
262 CFURLRef
CFBundleCopyExecutableURL(CFBundleRef bundle
);
264 #if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED
266 kCFBundleExecutableArchitectureI386
= 0x00000007,
267 kCFBundleExecutableArchitecturePPC
= 0x00000012,
268 kCFBundleExecutableArchitectureX86_64
= 0x01000007,
269 kCFBundleExecutableArchitecturePPC64
= 0x01000012
271 #endif /* MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED */
274 CFArrayRef
CFBundleCopyExecutableArchitectures(CFBundleRef bundle
) CF_AVAILABLE(10_5
, 2_0
);
275 /* If the bundle's executable exists and is a Mach-o file, this function will return an array */
276 /* of CFNumbers whose values are integers representing the architectures the file provides. */
277 /* The values currently in use are those listed in the enum above, but others may be added */
278 /* in the future. If the executable is not a Mach-o file, this function returns NULL. */
281 Boolean
CFBundlePreflightExecutable(CFBundleRef bundle
, CFErrorRef
*error
) CF_AVAILABLE(10_5
, 2_0
);
282 /* This function will return true if the bundle is loaded, or if the bundle appears to be */
283 /* loadable upon inspection. This does not mean that the bundle is definitively loadable, */
284 /* since it may fail to load due to link errors or other problems not readily detectable. */
285 /* If this function detects problems, it will return false, and return a CFError by reference. */
286 /* It is the responsibility of the caller to release the CFError. */
289 Boolean
CFBundleLoadExecutableAndReturnError(CFBundleRef bundle
, CFErrorRef
*error
) CF_AVAILABLE(10_5
, 2_0
);
290 /* If the bundle is already loaded, this function will return true. Otherwise, it will attempt */
291 /* to load the bundle, and it will return true if that attempt succeeds. If the bundle fails */
292 /* to load, this function will return false, and it will return a CFError by reference. */
293 /* It is the responsibility of the caller to release the CFError. */
296 Boolean
CFBundleLoadExecutable(CFBundleRef bundle
);
299 Boolean
CFBundleIsExecutableLoaded(CFBundleRef bundle
);
302 void CFBundleUnloadExecutable(CFBundleRef bundle
);
305 void *CFBundleGetFunctionPointerForName(CFBundleRef bundle
, CFStringRef functionName
);
308 void CFBundleGetFunctionPointersForNames(CFBundleRef bundle
, CFArrayRef functionNames
, void *ftbl
[]);
311 void *CFBundleGetDataPointerForName(CFBundleRef bundle
, CFStringRef symbolName
);
314 void CFBundleGetDataPointersForNames(CFBundleRef bundle
, CFArrayRef symbolNames
, void *stbl
[]);
317 CFURLRef
CFBundleCopyAuxiliaryExecutableURL(CFBundleRef bundle
, CFStringRef executableName
);
318 /* This function can be used to find executables other than your main */
319 /* executable. This is useful, for instance, for applications that have */
320 /* some command line tool that is packaged with and used by the application. */
321 /* The tool can be packaged in the various platform executable directories */
322 /* in the bundle and can be located with this function. This allows an */
323 /* app to ship versions of the tool for each platform as it does for the */
324 /* main app executable. */
326 /* ==================== Getting a bundle's plugIn ==================== */
329 CFPlugInRef
CFBundleGetPlugIn(CFBundleRef bundle
);
331 /* ==================== Resource Manager-Related API ==================== */
334 typedef int CFBundleRefNum
;
336 typedef SInt16 CFBundleRefNum
;
340 CFBundleRefNum
CFBundleOpenBundleResourceMap(CFBundleRef bundle
);
341 /* This function opens the non-localized and the localized resource files */
342 /* (if any) for the bundle, creates and makes current a single read-only */
343 /* resource map combining both, and returns a reference number for it. */
344 /* If it is called multiple times, it opens the files multiple times, */
345 /* and returns distinct reference numbers. */
348 SInt32
CFBundleOpenBundleResourceFiles(CFBundleRef bundle
, CFBundleRefNum
*refNum
, CFBundleRefNum
*localizedRefNum
);
349 /* Similar to CFBundleOpenBundleResourceMap(), except that it creates two */
350 /* separate resource maps and returns reference numbers for both. */
353 void CFBundleCloseBundleResourceMap(CFBundleRef bundle
, CFBundleRefNum refNum
);
357 #endif /* ! __COREFOUNDATION_CFBUNDLE__ */