]> git.saurik.com Git - apple/cf.git/blame - CFBundle.h
CF-476.18.tar.gz
[apple/cf.git] / CFBundle.h
CommitLineData
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 37CF_EXTERN_C_BEGIN
9ce05555
A
38
39typedef struct __CFBundle *CFBundleRef;
40typedef struct __CFBundle *CFPlugInRef;
41
42/* ===================== Standard Info.plist keys ===================== */
43CF_EXPORT
44const CFStringRef kCFBundleInfoDictionaryVersionKey;
45 /* The version of the Info.plist format */
46CF_EXPORT
47const CFStringRef kCFBundleExecutableKey;
bd5b749c 48 /* The name of the executable in this bundle, if any */
9ce05555
A
49CF_EXPORT
50const CFStringRef kCFBundleIdentifierKey;
51 /* The bundle identifier (for CFBundleGetBundleWithIdentifier()) */
52CF_EXPORT
53const 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
57CF_EXPORT
58const CFStringRef kCFBundleDevelopmentRegionKey;
59 /* The name of the development language of the bundle. */
60CF_EXPORT
61const 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 63CF_EXPORT
bd5b749c 64const 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
69CF_EXPORT
70CFBundleRef CFBundleGetMainBundle(void);
71
72CF_EXPORT
73CFBundleRef 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
81CF_EXPORT
82CFArrayRef CFBundleGetAllBundles(void);
83 /* This is potentially expensive. Use with care. */
84
85/* ===================== Creating Bundles ===================== */
86
87CF_EXPORT
bd5b749c 88CFTypeID CFBundleGetTypeID(void);
9ce05555
A
89
90CF_EXPORT
91CFBundleRef CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL);
92 /* Might return an existing instance with the ref-count bumped. */
93
94CF_EXPORT
95CFArrayRef 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
101CF_EXPORT
102CFURLRef CFBundleCopyBundleURL(CFBundleRef bundle);
103
104CF_EXPORT
105CFTypeRef 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
109CF_EXPORT
110CFDictionaryRef 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
114CF_EXPORT
115CFDictionaryRef CFBundleGetLocalInfoDictionary(CFBundleRef bundle);
116 /* This is the localized info dictionary. */
117
118CF_EXPORT
119void CFBundleGetPackageInfo(CFBundleRef bundle, UInt32 *packageType, UInt32 *packageCreator);
120
121CF_EXPORT
122CFStringRef CFBundleGetIdentifier(CFBundleRef bundle);
123
124CF_EXPORT
125UInt32 CFBundleGetVersionNumber(CFBundleRef bundle);
126
127CF_EXPORT
128CFStringRef CFBundleGetDevelopmentRegion(CFBundleRef bundle);
129
130CF_EXPORT
131CFURLRef CFBundleCopySupportFilesDirectoryURL(CFBundleRef bundle);
132
133CF_EXPORT
134CFURLRef CFBundleCopyResourcesDirectoryURL(CFBundleRef bundle);
135
136CF_EXPORT
137CFURLRef CFBundleCopyPrivateFrameworksURL(CFBundleRef bundle);
138
139CF_EXPORT
140CFURLRef CFBundleCopySharedFrameworksURL(CFBundleRef bundle);
141
142CF_EXPORT
143CFURLRef CFBundleCopySharedSupportURL(CFBundleRef bundle);
144
145CF_EXPORT
146CFURLRef 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. */
153CF_EXPORT
154CFDictionaryRef CFBundleCopyInfoDictionaryInDirectory(CFURLRef bundleURL);
155
156CF_EXPORT
157Boolean CFBundleGetPackageInfoInDirectory(CFURLRef url, UInt32 *packageType, UInt32 *packageCreator);
bd5b749c 158
9ce05555
A
159/* ==================== Resource Handling API ==================== */
160
161CF_EXPORT
162CFURLRef CFBundleCopyResourceURL(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName);
163
164CF_EXPORT
165CFArrayRef CFBundleCopyResourceURLsOfType(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName);
166
167CF_EXPORT
168CFStringRef 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
185CF_EXPORT
186CFURLRef CFBundleCopyResourceURLInDirectory(CFURLRef bundleURL, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName);
187
188CF_EXPORT
189CFArrayRef 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
196CF_EXPORT
197CFArrayRef CFBundleCopyBundleLocalizations(CFBundleRef bundle);
198 /* Lists the localizations that a bundle contains. */
199
200CF_EXPORT
201CFArrayRef 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 208CF_EXPORT
bd5b749c 209CFArrayRef 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
219CF_EXPORT
220CFURLRef CFBundleCopyResourceURLForLocalization(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName);
221
222CF_EXPORT
223CFArrayRef 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. */
233CF_EXPORT
bd5b749c
A
234CFDictionaryRef 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
240CF_EXPORT
bd5b749c
A
241CFArrayRef 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
248CF_EXPORT
249CFArrayRef 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
259CF_EXPORT
260CFURLRef CFBundleCopyExecutableURL(CFBundleRef bundle);
261
bd5b749c
A
262#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
263enum {
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 271CF_EXPORT
bd5b749c
A
272CFArrayRef 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
278CF_EXPORT
279Boolean 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
286CF_EXPORT
287Boolean 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
293CF_EXPORT
294Boolean CFBundleLoadExecutable(CFBundleRef bundle);
295
bd5b749c
A
296CF_EXPORT
297Boolean CFBundleIsExecutableLoaded(CFBundleRef bundle);
298
9ce05555
A
299CF_EXPORT
300void CFBundleUnloadExecutable(CFBundleRef bundle);
301
302CF_EXPORT
303void *CFBundleGetFunctionPointerForName(CFBundleRef bundle, CFStringRef functionName);
304
305CF_EXPORT
306void CFBundleGetFunctionPointersForNames(CFBundleRef bundle, CFArrayRef functionNames, void *ftbl[]);
307
308CF_EXPORT
309void *CFBundleGetDataPointerForName(CFBundleRef bundle, CFStringRef symbolName);
310
311CF_EXPORT
312void CFBundleGetDataPointersForNames(CFBundleRef bundle, CFArrayRef symbolNames, void *stbl[]);
313
314CF_EXPORT
315CFURLRef 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
326CF_EXPORT
327CFPlugInRef CFBundleGetPlugIn(CFBundleRef bundle);
328
329/* ==================== Resource Manager-Related API ==================== */
330
bd5b749c
A
331#if __LP64__
332typedef int CFBundleRefNum;
333#else
334typedef SInt16 CFBundleRefNum;
335#endif
336
9ce05555 337CF_EXPORT
bd5b749c 338CFBundleRefNum 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
345CF_EXPORT
bd5b749c
A
346SInt32 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
350CF_EXPORT
bd5b749c 351void CFBundleCloseBundleResourceMap(CFBundleRef bundle, CFBundleRefNum refNum);
9ce05555 352
bd5b749c 353CF_EXTERN_C_END
9ce05555
A
354
355#endif /* ! __COREFOUNDATION_CFBUNDLE__ */
356