]>
Commit | Line | Data |
---|---|---|
9ce05555 | 1 | /* |
e588f561 | 2 | * Copyright (c) 2010 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 | */ | |
f64f9b69 | 23 | |
9ce05555 | 24 | /* CFBundle.h |
cf7d2af9 | 25 | Copyright (c) 1999-2009, Apple Inc. All rights reserved. |
9ce05555 A |
26 | */ |
27 | ||
28 | #if !defined(__COREFOUNDATION_CFBUNDLE__) | |
29 | #define __COREFOUNDATION_CFBUNDLE__ 1 | |
30 | ||
31 | #include <CoreFoundation/CFBase.h> | |
32 | #include <CoreFoundation/CFArray.h> | |
33 | #include <CoreFoundation/CFDictionary.h> | |
bd5b749c | 34 | #include <CoreFoundation/CFError.h> |
9ce05555 A |
35 | #include <CoreFoundation/CFString.h> |
36 | #include <CoreFoundation/CFURL.h> | |
37 | ||
bd5b749c | 38 | CF_EXTERN_C_BEGIN |
9ce05555 A |
39 | |
40 | typedef struct __CFBundle *CFBundleRef; | |
41 | typedef struct __CFBundle *CFPlugInRef; | |
42 | ||
43 | /* ===================== Standard Info.plist keys ===================== */ | |
44 | CF_EXPORT | |
45 | const CFStringRef kCFBundleInfoDictionaryVersionKey; | |
46 | /* The version of the Info.plist format */ | |
47 | CF_EXPORT | |
48 | const CFStringRef kCFBundleExecutableKey; | |
bd5b749c | 49 | /* The name of the executable in this bundle, if any */ |
9ce05555 A |
50 | CF_EXPORT |
51 | const CFStringRef kCFBundleIdentifierKey; | |
52 | /* The bundle identifier (for CFBundleGetBundleWithIdentifier()) */ | |
53 | CF_EXPORT | |
54 | const CFStringRef kCFBundleVersionKey; | |
bd5b749c A |
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. */ | |
9ce05555 A |
58 | CF_EXPORT |
59 | const CFStringRef kCFBundleDevelopmentRegionKey; | |
60 | /* The name of the development language of the bundle. */ | |
61 | CF_EXPORT | |
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. */ | |
9ce05555 | 64 | CF_EXPORT |
bd5b749c | 65 | const CFStringRef kCFBundleLocalizationsKey AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
9ce05555 | 66 | /* Allows an unbundled application that handles localization itself to specify which localizations it has available. */ |
9ce05555 A |
67 | |
68 | /* ===================== Finding Bundles ===================== */ | |
69 | ||
70 | CF_EXPORT | |
71 | CFBundleRef CFBundleGetMainBundle(void); | |
72 | ||
73 | CF_EXPORT | |
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. */ | |
81 | ||
82 | CF_EXPORT | |
83 | CFArrayRef CFBundleGetAllBundles(void); | |
cf7d2af9 A |
84 | /* This is potentially expensive, and not thread-safe. Use with care. */ |
85 | /* Best used for debuggging or other diagnostic purposes. */ | |
9ce05555 A |
86 | |
87 | /* ===================== Creating Bundles ===================== */ | |
88 | ||
89 | CF_EXPORT | |
bd5b749c | 90 | CFTypeID CFBundleGetTypeID(void); |
9ce05555 A |
91 | |
92 | CF_EXPORT | |
93 | CFBundleRef CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL); | |
94 | /* Might return an existing instance with the ref-count bumped. */ | |
95 | ||
96 | CF_EXPORT | |
97 | CFArrayRef CFBundleCreateBundlesFromDirectory(CFAllocatorRef allocator, CFURLRef directoryURL, CFStringRef bundleType); | |
bd5b749c A |
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. */ | |
9ce05555 A |
100 | |
101 | /* ==================== Basic Bundle Info ==================== */ | |
102 | ||
103 | CF_EXPORT | |
104 | CFURLRef CFBundleCopyBundleURL(CFBundleRef bundle); | |
105 | ||
106 | CF_EXPORT | |
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. */ | |
110 | ||
111 | CF_EXPORT | |
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. */ | |
115 | ||
116 | CF_EXPORT | |
117 | CFDictionaryRef CFBundleGetLocalInfoDictionary(CFBundleRef bundle); | |
118 | /* This is the localized info dictionary. */ | |
119 | ||
120 | CF_EXPORT | |
121 | void CFBundleGetPackageInfo(CFBundleRef bundle, UInt32 *packageType, UInt32 *packageCreator); | |
122 | ||
123 | CF_EXPORT | |
124 | CFStringRef CFBundleGetIdentifier(CFBundleRef bundle); | |
125 | ||
126 | CF_EXPORT | |
127 | UInt32 CFBundleGetVersionNumber(CFBundleRef bundle); | |
128 | ||
129 | CF_EXPORT | |
130 | CFStringRef CFBundleGetDevelopmentRegion(CFBundleRef bundle); | |
131 | ||
132 | CF_EXPORT | |
133 | CFURLRef CFBundleCopySupportFilesDirectoryURL(CFBundleRef bundle); | |
134 | ||
135 | CF_EXPORT | |
136 | CFURLRef CFBundleCopyResourcesDirectoryURL(CFBundleRef bundle); | |
137 | ||
138 | CF_EXPORT | |
139 | CFURLRef CFBundleCopyPrivateFrameworksURL(CFBundleRef bundle); | |
140 | ||
141 | CF_EXPORT | |
142 | CFURLRef CFBundleCopySharedFrameworksURL(CFBundleRef bundle); | |
143 | ||
144 | CF_EXPORT | |
145 | CFURLRef CFBundleCopySharedSupportURL(CFBundleRef bundle); | |
146 | ||
147 | CF_EXPORT | |
148 | CFURLRef CFBundleCopyBuiltInPlugInsURL(CFBundleRef bundle); | |
149 | ||
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. */ | |
155 | CF_EXPORT | |
156 | CFDictionaryRef CFBundleCopyInfoDictionaryInDirectory(CFURLRef bundleURL); | |
157 | ||
158 | CF_EXPORT | |
159 | Boolean CFBundleGetPackageInfoInDirectory(CFURLRef url, UInt32 *packageType, UInt32 *packageCreator); | |
bd5b749c | 160 | |
9ce05555 A |
161 | /* ==================== Resource Handling API ==================== */ |
162 | ||
163 | CF_EXPORT | |
164 | CFURLRef CFBundleCopyResourceURL(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName); | |
165 | ||
166 | CF_EXPORT | |
167 | CFArrayRef CFBundleCopyResourceURLsOfType(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName); | |
168 | ||
169 | CF_EXPORT | |
cf7d2af9 | 170 | CFStringRef CFBundleCopyLocalizedString(CFBundleRef bundle, CFStringRef key, CFStringRef value, CFStringRef tableName) CF_FORMAT_ARGUMENT(2); |
9ce05555 A |
171 | |
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)) | |
180 | ||
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. */ | |
186 | ||
187 | CF_EXPORT | |
188 | CFURLRef CFBundleCopyResourceURLInDirectory(CFURLRef bundleURL, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName); | |
189 | ||
190 | CF_EXPORT | |
191 | CFArrayRef CFBundleCopyResourceURLsOfTypeInDirectory(CFURLRef bundleURL, CFStringRef resourceType, CFStringRef subDirName); | |
192 | ||
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. */ | |
197 | ||
198 | CF_EXPORT | |
199 | CFArrayRef CFBundleCopyBundleLocalizations(CFBundleRef bundle); | |
200 | /* Lists the localizations that a bundle contains. */ | |
201 | ||
202 | CF_EXPORT | |
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 */ | |
bd5b749c | 208 | /* result of CFBundleCopyBundleLocalizations(). */ |
9ce05555 | 209 | |
9ce05555 | 210 | CF_EXPORT |
bd5b749c | 211 | CFArrayRef CFBundleCopyLocalizationsForPreferences(CFArrayRef locArray, CFArrayRef prefArray) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
9ce05555 A |
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 */ | |
bd5b749c | 216 | /* be used. This is not the same as CFBundleCopyPreferredLocalizationsFromArray(), */ |
9ce05555 A |
217 | /* because that function takes the current application context into account. */ |
218 | /* To determine the localizations that another application would use, apply */ | |
bd5b749c | 219 | /* this function to the result of CFBundleCopyBundleLocalizations(). */ |
9ce05555 A |
220 | |
221 | CF_EXPORT | |
222 | CFURLRef CFBundleCopyResourceURLForLocalization(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName); | |
223 | ||
224 | CF_EXPORT | |
225 | CFArrayRef CFBundleCopyResourceURLsOfTypeForLocalization(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName); | |
bd5b749c A |
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. */ | |
9ce05555 | 231 | |
9ce05555 A |
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. */ | |
235 | CF_EXPORT | |
bd5b749c A |
236 | CFDictionaryRef CFBundleCopyInfoDictionaryForURL(CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
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, */ | |
9ce05555 A |
240 | /* or from a 'plst' resource. */ |
241 | ||
242 | CF_EXPORT | |
bd5b749c A |
243 | CFArrayRef CFBundleCopyLocalizationsForURL(CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER; |
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, */ | |
9ce05555 A |
246 | /* this will attempt to determine its localizations using the CFBundleLocalizations and */ |
247 | /* CFBundleDevelopmentRegion keys in the dictionary returned by CFBundleCopyInfoDictionaryForURL,*/ | |
bd5b749c A |
248 | /* or from a 'vers' resource if those are not present. */ |
249 | ||
250 | CF_EXPORT | |
251 | CFArrayRef CFBundleCopyExecutableArchitecturesForURL(CFURLRef url) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; | |
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. */ | |
9ce05555 A |
255 | |
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. */ | |
9ce05555 A |
260 | |
261 | CF_EXPORT | |
262 | CFURLRef CFBundleCopyExecutableURL(CFBundleRef bundle); | |
263 | ||
cf7d2af9 | 264 | #if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED |
bd5b749c A |
265 | enum { |
266 | kCFBundleExecutableArchitectureI386 = 0x00000007, | |
267 | kCFBundleExecutableArchitecturePPC = 0x00000012, | |
268 | kCFBundleExecutableArchitectureX86_64 = 0x01000007, | |
269 | kCFBundleExecutableArchitecturePPC64 = 0x01000012 | |
270 | }; | |
cf7d2af9 | 271 | #endif /* MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED */ |
bd5b749c | 272 | |
9ce05555 | 273 | CF_EXPORT |
bd5b749c A |
274 | CFArrayRef CFBundleCopyExecutableArchitectures(CFBundleRef bundle) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; |
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. */ | |
279 | ||
280 | CF_EXPORT | |
281 | Boolean CFBundlePreflightExecutable(CFBundleRef bundle, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; | |
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. */ | |
287 | ||
288 | CF_EXPORT | |
289 | Boolean CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, CFErrorRef *error) AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; | |
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. */ | |
9ce05555 A |
294 | |
295 | CF_EXPORT | |
296 | Boolean CFBundleLoadExecutable(CFBundleRef bundle); | |
297 | ||
bd5b749c A |
298 | CF_EXPORT |
299 | Boolean CFBundleIsExecutableLoaded(CFBundleRef bundle); | |
300 | ||
9ce05555 A |
301 | CF_EXPORT |
302 | void CFBundleUnloadExecutable(CFBundleRef bundle); | |
303 | ||
304 | CF_EXPORT | |
305 | void *CFBundleGetFunctionPointerForName(CFBundleRef bundle, CFStringRef functionName); | |
306 | ||
307 | CF_EXPORT | |
308 | void CFBundleGetFunctionPointersForNames(CFBundleRef bundle, CFArrayRef functionNames, void *ftbl[]); | |
309 | ||
310 | CF_EXPORT | |
311 | void *CFBundleGetDataPointerForName(CFBundleRef bundle, CFStringRef symbolName); | |
312 | ||
313 | CF_EXPORT | |
314 | void CFBundleGetDataPointersForNames(CFBundleRef bundle, CFArrayRef symbolNames, void *stbl[]); | |
315 | ||
316 | CF_EXPORT | |
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. */ | |
325 | ||
326 | /* ==================== Getting a bundle's plugIn ==================== */ | |
327 | ||
328 | CF_EXPORT | |
329 | CFPlugInRef CFBundleGetPlugIn(CFBundleRef bundle); | |
330 | ||
331 | /* ==================== Resource Manager-Related API ==================== */ | |
332 | ||
bd5b749c A |
333 | #if __LP64__ |
334 | typedef int CFBundleRefNum; | |
335 | #else | |
336 | typedef SInt16 CFBundleRefNum; | |
337 | #endif | |
338 | ||
9ce05555 | 339 | CF_EXPORT |
bd5b749c | 340 | CFBundleRefNum CFBundleOpenBundleResourceMap(CFBundleRef bundle); |
9ce05555 A |
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. */ | |
346 | ||
347 | CF_EXPORT | |
bd5b749c A |
348 | SInt32 CFBundleOpenBundleResourceFiles(CFBundleRef bundle, CFBundleRefNum *refNum, CFBundleRefNum *localizedRefNum); |
349 | /* Similar to CFBundleOpenBundleResourceMap(), except that it creates two */ | |
9ce05555 A |
350 | /* separate resource maps and returns reference numbers for both. */ |
351 | ||
352 | CF_EXPORT | |
bd5b749c | 353 | void CFBundleCloseBundleResourceMap(CFBundleRef bundle, CFBundleRefNum refNum); |
9ce05555 | 354 | |
bd5b749c | 355 | CF_EXTERN_C_END |
9ce05555 A |
356 | |
357 | #endif /* ! __COREFOUNDATION_CFBUNDLE__ */ | |
358 |