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