]> git.saurik.com Git - apple/cf.git/blame - CFBundle.h
CF-550.43.tar.gz
[apple/cf.git] / CFBundle.h
CommitLineData
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 38CF_EXTERN_C_BEGIN
9ce05555
A
39
40typedef struct __CFBundle *CFBundleRef;
41typedef struct __CFBundle *CFPlugInRef;
42
43/* ===================== Standard Info.plist keys ===================== */
44CF_EXPORT
45const CFStringRef kCFBundleInfoDictionaryVersionKey;
46 /* The version of the Info.plist format */
47CF_EXPORT
48const CFStringRef kCFBundleExecutableKey;
bd5b749c 49 /* The name of the executable in this bundle, if any */
9ce05555
A
50CF_EXPORT
51const CFStringRef kCFBundleIdentifierKey;
52 /* The bundle identifier (for CFBundleGetBundleWithIdentifier()) */
53CF_EXPORT
54const 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
58CF_EXPORT
59const CFStringRef kCFBundleDevelopmentRegionKey;
60 /* The name of the development language of the bundle. */
61CF_EXPORT
62const 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 64CF_EXPORT
bd5b749c 65const 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
70CF_EXPORT
71CFBundleRef CFBundleGetMainBundle(void);
72
73CF_EXPORT
74CFBundleRef 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
82CF_EXPORT
83CFArrayRef 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
89CF_EXPORT
bd5b749c 90CFTypeID CFBundleGetTypeID(void);
9ce05555
A
91
92CF_EXPORT
93CFBundleRef CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL);
94 /* Might return an existing instance with the ref-count bumped. */
95
96CF_EXPORT
97CFArrayRef 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
103CF_EXPORT
104CFURLRef CFBundleCopyBundleURL(CFBundleRef bundle);
105
106CF_EXPORT
107CFTypeRef 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
111CF_EXPORT
112CFDictionaryRef 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
116CF_EXPORT
117CFDictionaryRef CFBundleGetLocalInfoDictionary(CFBundleRef bundle);
118 /* This is the localized info dictionary. */
119
120CF_EXPORT
121void CFBundleGetPackageInfo(CFBundleRef bundle, UInt32 *packageType, UInt32 *packageCreator);
122
123CF_EXPORT
124CFStringRef CFBundleGetIdentifier(CFBundleRef bundle);
125
126CF_EXPORT
127UInt32 CFBundleGetVersionNumber(CFBundleRef bundle);
128
129CF_EXPORT
130CFStringRef CFBundleGetDevelopmentRegion(CFBundleRef bundle);
131
132CF_EXPORT
133CFURLRef CFBundleCopySupportFilesDirectoryURL(CFBundleRef bundle);
134
135CF_EXPORT
136CFURLRef CFBundleCopyResourcesDirectoryURL(CFBundleRef bundle);
137
138CF_EXPORT
139CFURLRef CFBundleCopyPrivateFrameworksURL(CFBundleRef bundle);
140
141CF_EXPORT
142CFURLRef CFBundleCopySharedFrameworksURL(CFBundleRef bundle);
143
144CF_EXPORT
145CFURLRef CFBundleCopySharedSupportURL(CFBundleRef bundle);
146
147CF_EXPORT
148CFURLRef 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. */
155CF_EXPORT
156CFDictionaryRef CFBundleCopyInfoDictionaryInDirectory(CFURLRef bundleURL);
157
158CF_EXPORT
159Boolean CFBundleGetPackageInfoInDirectory(CFURLRef url, UInt32 *packageType, UInt32 *packageCreator);
bd5b749c 160
9ce05555
A
161/* ==================== Resource Handling API ==================== */
162
163CF_EXPORT
164CFURLRef CFBundleCopyResourceURL(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName);
165
166CF_EXPORT
167CFArrayRef CFBundleCopyResourceURLsOfType(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName);
168
169CF_EXPORT
cf7d2af9 170CFStringRef 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
187CF_EXPORT
188CFURLRef CFBundleCopyResourceURLInDirectory(CFURLRef bundleURL, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName);
189
190CF_EXPORT
191CFArrayRef 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
198CF_EXPORT
199CFArrayRef CFBundleCopyBundleLocalizations(CFBundleRef bundle);
200 /* Lists the localizations that a bundle contains. */
201
202CF_EXPORT
203CFArrayRef 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 210CF_EXPORT
bd5b749c 211CFArrayRef 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
221CF_EXPORT
222CFURLRef CFBundleCopyResourceURLForLocalization(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName);
223
224CF_EXPORT
225CFArrayRef 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. */
235CF_EXPORT
bd5b749c
A
236CFDictionaryRef 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
242CF_EXPORT
bd5b749c
A
243CFArrayRef 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
250CF_EXPORT
251CFArrayRef 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
261CF_EXPORT
262CFURLRef CFBundleCopyExecutableURL(CFBundleRef bundle);
263
cf7d2af9 264#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED
bd5b749c
A
265enum {
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 273CF_EXPORT
bd5b749c
A
274CFArrayRef 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
280CF_EXPORT
281Boolean 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
288CF_EXPORT
289Boolean 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
295CF_EXPORT
296Boolean CFBundleLoadExecutable(CFBundleRef bundle);
297
bd5b749c
A
298CF_EXPORT
299Boolean CFBundleIsExecutableLoaded(CFBundleRef bundle);
300
9ce05555
A
301CF_EXPORT
302void CFBundleUnloadExecutable(CFBundleRef bundle);
303
304CF_EXPORT
305void *CFBundleGetFunctionPointerForName(CFBundleRef bundle, CFStringRef functionName);
306
307CF_EXPORT
308void CFBundleGetFunctionPointersForNames(CFBundleRef bundle, CFArrayRef functionNames, void *ftbl[]);
309
310CF_EXPORT
311void *CFBundleGetDataPointerForName(CFBundleRef bundle, CFStringRef symbolName);
312
313CF_EXPORT
314void CFBundleGetDataPointersForNames(CFBundleRef bundle, CFArrayRef symbolNames, void *stbl[]);
315
316CF_EXPORT
317CFURLRef 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
328CF_EXPORT
329CFPlugInRef CFBundleGetPlugIn(CFBundleRef bundle);
330
331/* ==================== Resource Manager-Related API ==================== */
332
bd5b749c
A
333#if __LP64__
334typedef int CFBundleRefNum;
335#else
336typedef SInt16 CFBundleRefNum;
337#endif
338
9ce05555 339CF_EXPORT
bd5b749c 340CFBundleRefNum 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
347CF_EXPORT
bd5b749c
A
348SInt32 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
352CF_EXPORT
bd5b749c 353void CFBundleCloseBundleResourceMap(CFBundleRef bundle, CFBundleRefNum refNum);
9ce05555 354
bd5b749c 355CF_EXTERN_C_END
9ce05555
A
356
357#endif /* ! __COREFOUNDATION_CFBUNDLE__ */
358