]>
Commit | Line | Data |
---|---|---|
9ce05555 | 1 | /* |
bd5b749c | 2 | * Copyright (c) 2008 Apple Inc. All rights reserved. |
9ce05555 A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
9ce05555 A |
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 | |
11 | * file. | |
12 | * | |
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. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* CFBundle.h | |
bd5b749c | 24 | Copyright (c) 1999-2007, Apple Inc. All rights reserved. |
9ce05555 A |
25 | */ |
26 | ||
27 | #if !defined(__COREFOUNDATION_CFBUNDLE__) | |
28 | #define __COREFOUNDATION_CFBUNDLE__ 1 | |
29 | ||
30 | #include <CoreFoundation/CFBase.h> | |
31 | #include <CoreFoundation/CFArray.h> | |
32 | #include <CoreFoundation/CFDictionary.h> | |
bd5b749c | 33 | #include <CoreFoundation/CFError.h> |
9ce05555 A |
34 | #include <CoreFoundation/CFString.h> |
35 | #include <CoreFoundation/CFURL.h> | |
36 | ||
bd5b749c | 37 | CF_EXTERN_C_BEGIN |
9ce05555 A |
38 | |
39 | typedef struct __CFBundle *CFBundleRef; | |
40 | typedef struct __CFBundle *CFPlugInRef; | |
41 | ||
42 | /* ===================== Standard Info.plist keys ===================== */ | |
43 | CF_EXPORT | |
44 | const CFStringRef kCFBundleInfoDictionaryVersionKey; | |
45 | /* The version of the Info.plist format */ | |
46 | CF_EXPORT | |
47 | const CFStringRef kCFBundleExecutableKey; | |
bd5b749c | 48 | /* The name of the executable in this bundle, if any */ |
9ce05555 A |
49 | CF_EXPORT |
50 | const CFStringRef kCFBundleIdentifierKey; | |
51 | /* The bundle identifier (for CFBundleGetBundleWithIdentifier()) */ | |
52 | CF_EXPORT | |
53 | const CFStringRef kCFBundleVersionKey; | |
bd5b749c A |
54 | /* The version number of the bundle. For Mac OS 9 style version numbers (for example "2.5.3d5"), */ |
55 | /* clients can use CFBundleGetVersionNumber() instead of accessing this key directly since that */ | |
56 | /* function will properly convert the version string into its compact integer representation. */ | |
9ce05555 A |
57 | CF_EXPORT |
58 | const CFStringRef kCFBundleDevelopmentRegionKey; | |
59 | /* The name of the development language of the bundle. */ | |
60 | CF_EXPORT | |
61 | const CFStringRef kCFBundleNameKey; | |
62 | /* The human-readable name of the bundle. This key is often found in the InfoPlist.strings since it is usually localized. */ | |
9ce05555 | 63 | CF_EXPORT |
bd5b749c | 64 | const CFStringRef kCFBundleLocalizationsKey AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
9ce05555 | 65 | /* Allows an unbundled application that handles localization itself to specify which localizations it has available. */ |
9ce05555 A |
66 | |
67 | /* ===================== Finding Bundles ===================== */ | |
68 | ||
69 | CF_EXPORT | |
70 | CFBundleRef CFBundleGetMainBundle(void); | |
71 | ||
72 | CF_EXPORT | |
73 | CFBundleRef CFBundleGetBundleWithIdentifier(CFStringRef bundleID); | |
74 | /* A bundle can name itself by providing a key in the info dictionary. */ | |
75 | /* This facility is meant to allow bundle-writers to get hold of their */ | |
76 | /* bundle from their code without having to know where it was on the disk. */ | |
77 | /* This is meant to be a replacement mechanism for +bundleForClass: users. */ | |
78 | /* Note that this does not search for bundles on the disk; it will locate */ | |
79 | /* only bundles already loaded or otherwise known to the current process. */ | |
80 | ||
81 | CF_EXPORT | |
82 | CFArrayRef CFBundleGetAllBundles(void); | |
83 | /* This is potentially expensive. Use with care. */ | |
84 | ||
85 | /* ===================== Creating Bundles ===================== */ | |
86 | ||
87 | CF_EXPORT | |
bd5b749c | 88 | CFTypeID CFBundleGetTypeID(void); |
9ce05555 A |
89 | |
90 | CF_EXPORT | |
91 | CFBundleRef CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL); | |
92 | /* Might return an existing instance with the ref-count bumped. */ | |
93 | ||
94 | CF_EXPORT | |
95 | CFArrayRef CFBundleCreateBundlesFromDirectory(CFAllocatorRef allocator, CFURLRef directoryURL, CFStringRef bundleType); | |
bd5b749c A |
96 | /* Create instances for all bundles in the given directory matching the given type */ |
97 | /* (or all of them if bundleType is NULL). Instances are created using CFBundleCreate() and are not released. */ | |
9ce05555 A |
98 | |
99 | /* ==================== Basic Bundle Info ==================== */ | |
100 | ||
101 | CF_EXPORT | |
102 | CFURLRef CFBundleCopyBundleURL(CFBundleRef bundle); | |
103 | ||
104 | CF_EXPORT | |
105 | CFTypeRef CFBundleGetValueForInfoDictionaryKey(CFBundleRef bundle, CFStringRef key); | |
106 | /* Returns a localized value if available, otherwise the global value. */ | |
107 | /* This is the recommended function for examining the info dictionary. */ | |
108 | ||
109 | CF_EXPORT | |
110 | CFDictionaryRef CFBundleGetInfoDictionary(CFBundleRef bundle); | |
111 | /* This is the global info dictionary. Note that CFBundle may add */ | |
112 | /* extra keys to the dictionary for its own use. */ | |
113 | ||
114 | CF_EXPORT | |
115 | CFDictionaryRef CFBundleGetLocalInfoDictionary(CFBundleRef bundle); | |
116 | /* This is the localized info dictionary. */ | |
117 | ||
118 | CF_EXPORT | |
119 | void CFBundleGetPackageInfo(CFBundleRef bundle, UInt32 *packageType, UInt32 *packageCreator); | |
120 | ||
121 | CF_EXPORT | |
122 | CFStringRef CFBundleGetIdentifier(CFBundleRef bundle); | |
123 | ||
124 | CF_EXPORT | |
125 | UInt32 CFBundleGetVersionNumber(CFBundleRef bundle); | |
126 | ||
127 | CF_EXPORT | |
128 | CFStringRef CFBundleGetDevelopmentRegion(CFBundleRef bundle); | |
129 | ||
130 | CF_EXPORT | |
131 | CFURLRef CFBundleCopySupportFilesDirectoryURL(CFBundleRef bundle); | |
132 | ||
133 | CF_EXPORT | |
134 | CFURLRef CFBundleCopyResourcesDirectoryURL(CFBundleRef bundle); | |
135 | ||
136 | CF_EXPORT | |
137 | CFURLRef CFBundleCopyPrivateFrameworksURL(CFBundleRef bundle); | |
138 | ||
139 | CF_EXPORT | |
140 | CFURLRef CFBundleCopySharedFrameworksURL(CFBundleRef bundle); | |
141 | ||
142 | CF_EXPORT | |
143 | CFURLRef CFBundleCopySharedSupportURL(CFBundleRef bundle); | |
144 | ||
145 | CF_EXPORT | |
146 | CFURLRef CFBundleCopyBuiltInPlugInsURL(CFBundleRef bundle); | |
147 | ||
148 | /* ------------- Basic Bundle Info without a CFBundle instance ------------- */ | |
149 | /* This API is provided to enable developers to retrieve basic information */ | |
150 | /* about a bundle without having to create an instance of CFBundle. */ | |
151 | /* Because of caching behavior when a CFBundle instance exists, it will be faster */ | |
152 | /* to actually create a CFBundle if you need to retrieve multiple pieces of info. */ | |
153 | CF_EXPORT | |
154 | CFDictionaryRef CFBundleCopyInfoDictionaryInDirectory(CFURLRef bundleURL); | |
155 | ||
156 | CF_EXPORT | |
157 | Boolean CFBundleGetPackageInfoInDirectory(CFURLRef url, UInt32 *packageType, UInt32 *packageCreator); | |
bd5b749c | 158 | |
9ce05555 A |
159 | /* ==================== Resource Handling API ==================== */ |
160 | ||
161 | CF_EXPORT | |
162 | CFURLRef CFBundleCopyResourceURL(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName); | |
163 | ||
164 | CF_EXPORT | |
165 | CFArrayRef CFBundleCopyResourceURLsOfType(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName); | |
166 | ||
167 | CF_EXPORT | |
168 | CFStringRef CFBundleCopyLocalizedString(CFBundleRef bundle, CFStringRef key, CFStringRef value, CFStringRef tableName); | |
169 | ||
170 | #define CFCopyLocalizedString(key, comment) \ | |
171 | CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), NULL) | |
172 | #define CFCopyLocalizedStringFromTable(key, tbl, comment) \ | |
173 | CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), (tbl)) | |
174 | #define CFCopyLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \ | |
175 | CFBundleCopyLocalizedString((bundle), (key), (key), (tbl)) | |
176 | #define CFCopyLocalizedStringWithDefaultValue(key, tbl, bundle, value, comment) \ | |
177 | CFBundleCopyLocalizedString((bundle), (key), (value), (tbl)) | |
178 | ||
179 | /* ------------- Resource Handling without a CFBundle instance ------------- */ | |
180 | /* This API is provided to enable developers to use the CFBundle resource */ | |
181 | /* searching policy without having to create an instance of CFBundle. */ | |
182 | /* Because of caching behavior when a CFBundle instance exists, it will be faster */ | |
183 | /* to actually create a CFBundle if you need to access several resources. */ | |
184 | ||
185 | CF_EXPORT | |
186 | CFURLRef CFBundleCopyResourceURLInDirectory(CFURLRef bundleURL, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName); | |
187 | ||
188 | CF_EXPORT | |
189 | CFArrayRef CFBundleCopyResourceURLsOfTypeInDirectory(CFURLRef bundleURL, CFStringRef resourceType, CFStringRef subDirName); | |
190 | ||
191 | /* =========== Localization-specific Resource Handling API =========== */ | |
192 | /* This API allows finer-grained control over specific localizations, */ | |
193 | /* as distinguished from the above API, which always uses the user's */ | |
194 | /* preferred localizations for the bundle in the current app context. */ | |
195 | ||
196 | CF_EXPORT | |
197 | CFArrayRef CFBundleCopyBundleLocalizations(CFBundleRef bundle); | |
198 | /* Lists the localizations that a bundle contains. */ | |
199 | ||
200 | CF_EXPORT | |
201 | CFArrayRef CFBundleCopyPreferredLocalizationsFromArray(CFArrayRef locArray); | |
202 | /* Given an array of possible localizations, returns the one or more */ | |
203 | /* of them that CFBundle would use in the current application context. */ | |
204 | /* To determine the localizations that would be used for a particular */ | |
205 | /* bundle in the current application context, apply this function to the */ | |
bd5b749c | 206 | /* result of CFBundleCopyBundleLocalizations(). */ |
9ce05555 | 207 | |
9ce05555 | 208 | CF_EXPORT |
bd5b749c | 209 | CFArrayRef CFBundleCopyLocalizationsForPreferences(CFArrayRef locArray, CFArrayRef prefArray) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
9ce05555 A |
210 | /* Given an array of possible localizations, returns the one or more of */ |
211 | /* them that CFBundle would use, without reference to the current application */ | |
212 | /* context, if the user's preferred localizations were given by prefArray. */ | |
213 | /* If prefArray is NULL, the current user's actual preferred localizations will */ | |
bd5b749c | 214 | /* be used. This is not the same as CFBundleCopyPreferredLocalizationsFromArray(), */ |
9ce05555 A |
215 | /* because that function takes the current application context into account. */ |
216 | /* To determine the localizations that another application would use, apply */ | |
bd5b749c | 217 | /* this function to the result of CFBundleCopyBundleLocalizations(). */ |
9ce05555 A |
218 | |
219 | CF_EXPORT | |
220 | CFURLRef CFBundleCopyResourceURLForLocalization(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName); | |
221 | ||
222 | CF_EXPORT | |
223 | CFArrayRef CFBundleCopyResourceURLsOfTypeForLocalization(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName); | |
bd5b749c A |
224 | /* The localizationName argument to CFBundleCopyResourceURLForLocalization() or */ |
225 | /* CFBundleCopyResourceURLsOfTypeForLocalization() must be identical to one of the */ | |
226 | /* localizations in the bundle, as returned by CFBundleCopyBundleLocalizations(). */ | |
227 | /* It is recommended that either CFBundleCopyPreferredLocalizationsFromArray() or */ | |
228 | /* CFBundleCopyLocalizationsForPreferences() be used to select the localization. */ | |
9ce05555 | 229 | |
9ce05555 A |
230 | /* =================== Unbundled application info ===================== */ |
231 | /* This API is provided to enable developers to retrieve bundle-related */ | |
232 | /* information about an application that may be bundled or unbundled. */ | |
233 | CF_EXPORT | |
bd5b749c A |
234 | CFDictionaryRef CFBundleCopyInfoDictionaryForURL(CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
235 | /* For a directory URL, this is equivalent to CFBundleCopyInfoDictionaryInDirectory(). */ | |
236 | /* For a plain file URL representing an unbundled executable, this will attempt to read */ | |
237 | /* an info dictionary from the (__TEXT, __info_plist) section, if it is a Mach-o file, */ | |
9ce05555 A |
238 | /* or from a 'plst' resource. */ |
239 | ||
240 | CF_EXPORT | |
bd5b749c A |
241 | CFArrayRef CFBundleCopyLocalizationsForURL(CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
242 | /* For a directory URL, this is equivalent to calling CFBundleCopyBundleLocalizations() */ | |
243 | /* on the corresponding bundle. For a plain file URL representing an unbundled executable, */ | |
9ce05555 A |
244 | /* this will attempt to determine its localizations using the CFBundleLocalizations and */ |
245 | /* CFBundleDevelopmentRegion keys in the dictionary returned by CFBundleCopyInfoDictionaryForURL,*/ | |
bd5b749c A |
246 | /* or from a 'vers' resource if those are not present. */ |
247 | ||
248 | CF_EXPORT | |
249 | CFArrayRef CFBundleCopyExecutableArchitecturesForURL(CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; | |
250 | /* For a directory URL, this is equivalent to calling CFBundleCopyExecutableArchitectures() */ | |
251 | /* on the corresponding bundle. For a plain file URL representing an unbundled executable, */ | |
252 | /* this will return the architectures it provides, if it is a Mach-o file, or NULL otherwise. */ | |
9ce05555 A |
253 | |
254 | /* ==================== Primitive Code Loading API ==================== */ | |
255 | /* This API abstracts the various different executable formats supported on */ | |
256 | /* various platforms. It can load DYLD, CFM, or DLL shared libraries (on their */ | |
257 | /* appropriate platforms) and gives a uniform API for looking up functions. */ | |
9ce05555 A |
258 | |
259 | CF_EXPORT | |
260 | CFURLRef CFBundleCopyExecutableURL(CFBundleRef bundle); | |
261 | ||
bd5b749c A |
262 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
263 | enum { | |
264 | kCFBundleExecutableArchitectureI386 = 0x00000007, | |
265 | kCFBundleExecutableArchitecturePPC = 0x00000012, | |
266 | kCFBundleExecutableArchitectureX86_64 = 0x01000007, | |
267 | kCFBundleExecutableArchitecturePPC64 = 0x01000012 | |
268 | }; | |
269 | #endif /* MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 */ | |
270 | ||
9ce05555 | 271 | CF_EXPORT |
bd5b749c A |
272 | CFArrayRef CFBundleCopyExecutableArchitectures(CFBundleRef bundle) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; |
273 | /* If the bundle's executable exists and is a Mach-o file, this function will return an array */ | |
274 | /* of CFNumbers whose values are integers representing the architectures the file provides. */ | |
275 | /* The values currently in use are those listed in the enum above, but others may be added */ | |
276 | /* in the future. If the executable is not a Mach-o file, this function returns NULL. */ | |
277 | ||
278 | CF_EXPORT | |
279 | Boolean CFBundlePreflightExecutable(CFBundleRef bundle, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; | |
280 | /* This function will return true if the bundle is loaded, or if the bundle appears to be */ | |
281 | /* loadable upon inspection. This does not mean that the bundle is definitively loadable, */ | |
282 | /* since it may fail to load due to link errors or other problems not readily detectable. */ | |
283 | /* If this function detects problems, it will return false, and return a CFError by reference. */ | |
284 | /* It is the responsibility of the caller to release the CFError. */ | |
285 | ||
286 | CF_EXPORT | |
287 | Boolean CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; | |
288 | /* If the bundle is already loaded, this function will return true. Otherwise, it will attempt */ | |
289 | /* to load the bundle, and it will return true if that attempt succeeds. If the bundle fails */ | |
290 | /* to load, this function will return false, and it will return a CFError by reference. */ | |
291 | /* It is the responsibility of the caller to release the CFError. */ | |
9ce05555 A |
292 | |
293 | CF_EXPORT | |
294 | Boolean CFBundleLoadExecutable(CFBundleRef bundle); | |
295 | ||
bd5b749c A |
296 | CF_EXPORT |
297 | Boolean CFBundleIsExecutableLoaded(CFBundleRef bundle); | |
298 | ||
9ce05555 A |
299 | CF_EXPORT |
300 | void CFBundleUnloadExecutable(CFBundleRef bundle); | |
301 | ||
302 | CF_EXPORT | |
303 | void *CFBundleGetFunctionPointerForName(CFBundleRef bundle, CFStringRef functionName); | |
304 | ||
305 | CF_EXPORT | |
306 | void CFBundleGetFunctionPointersForNames(CFBundleRef bundle, CFArrayRef functionNames, void *ftbl[]); | |
307 | ||
308 | CF_EXPORT | |
309 | void *CFBundleGetDataPointerForName(CFBundleRef bundle, CFStringRef symbolName); | |
310 | ||
311 | CF_EXPORT | |
312 | void CFBundleGetDataPointersForNames(CFBundleRef bundle, CFArrayRef symbolNames, void *stbl[]); | |
313 | ||
314 | CF_EXPORT | |
315 | CFURLRef CFBundleCopyAuxiliaryExecutableURL(CFBundleRef bundle, CFStringRef executableName); | |
316 | /* This function can be used to find executables other than your main */ | |
317 | /* executable. This is useful, for instance, for applications that have */ | |
318 | /* some command line tool that is packaged with and used by the application. */ | |
319 | /* The tool can be packaged in the various platform executable directories */ | |
320 | /* in the bundle and can be located with this function. This allows an */ | |
321 | /* app to ship versions of the tool for each platform as it does for the */ | |
322 | /* main app executable. */ | |
323 | ||
324 | /* ==================== Getting a bundle's plugIn ==================== */ | |
325 | ||
326 | CF_EXPORT | |
327 | CFPlugInRef CFBundleGetPlugIn(CFBundleRef bundle); | |
328 | ||
329 | /* ==================== Resource Manager-Related API ==================== */ | |
330 | ||
bd5b749c A |
331 | #if __LP64__ |
332 | typedef int CFBundleRefNum; | |
333 | #else | |
334 | typedef SInt16 CFBundleRefNum; | |
335 | #endif | |
336 | ||
9ce05555 | 337 | CF_EXPORT |
bd5b749c | 338 | CFBundleRefNum CFBundleOpenBundleResourceMap(CFBundleRef bundle); |
9ce05555 A |
339 | /* This function opens the non-localized and the localized resource files */ |
340 | /* (if any) for the bundle, creates and makes current a single read-only */ | |
341 | /* resource map combining both, and returns a reference number for it. */ | |
342 | /* If it is called multiple times, it opens the files multiple times, */ | |
343 | /* and returns distinct reference numbers. */ | |
344 | ||
345 | CF_EXPORT | |
bd5b749c A |
346 | SInt32 CFBundleOpenBundleResourceFiles(CFBundleRef bundle, CFBundleRefNum *refNum, CFBundleRefNum *localizedRefNum); |
347 | /* Similar to CFBundleOpenBundleResourceMap(), except that it creates two */ | |
9ce05555 A |
348 | /* separate resource maps and returns reference numbers for both. */ |
349 | ||
350 | CF_EXPORT | |
bd5b749c | 351 | void CFBundleCloseBundleResourceMap(CFBundleRef bundle, CFBundleRefNum refNum); |
9ce05555 | 352 | |
bd5b749c | 353 | CF_EXTERN_C_END |
9ce05555 A |
354 | |
355 | #endif /* ! __COREFOUNDATION_CFBUNDLE__ */ | |
356 |