2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 Copyright (c) 1999-2003, Apple, Inc. All rights reserved.
29 #if !defined(__COREFOUNDATION_CFBUNDLE__)
30 #define __COREFOUNDATION_CFBUNDLE__ 1
32 #include <CoreFoundation/CFBase.h>
33 #include <CoreFoundation/CFArray.h>
34 #include <CoreFoundation/CFDictionary.h>
35 #include <CoreFoundation/CFString.h>
36 #include <CoreFoundation/CFURL.h>
38 #if defined(__cplusplus)
42 typedef struct __CFBundle
*CFBundleRef
;
43 typedef struct __CFBundle
*CFPlugInRef
;
45 /* ===================== Standard Info.plist keys ===================== */
47 const CFStringRef kCFBundleInfoDictionaryVersionKey
;
48 /* The version of the Info.plist format */
50 const CFStringRef kCFBundleExecutableKey
;
51 /* The name of the executable in this bundle (if any) */
53 const CFStringRef kCFBundleIdentifierKey
;
54 /* The bundle identifier (for CFBundleGetBundleWithIdentifier()) */
56 const CFStringRef kCFBundleVersionKey
;
57 /* The version number of the bundle. Clients should use CFBundleGetVersionNumber() instead of accessing this key directly
58 since that function will properly convert a version number in string format into its interger representation. */
60 const CFStringRef kCFBundleDevelopmentRegionKey
;
61 /* The name of the development language of the bundle. */
63 const CFStringRef kCFBundleNameKey
;
64 /* The human-readable name of the bundle. This key is often found in the InfoPlist.strings since it is usually localized. */
65 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
67 const CFStringRef kCFBundleLocalizationsKey
;
68 /* Allows an unbundled application that handles localization itself to specify which localizations it has available. */
71 /* ===================== Finding Bundles ===================== */
74 CFBundleRef
CFBundleGetMainBundle(void);
77 CFBundleRef
CFBundleGetBundleWithIdentifier(CFStringRef bundleID
);
78 /* A bundle can name itself by providing a key in the info dictionary. */
79 /* This facility is meant to allow bundle-writers to get hold of their */
80 /* bundle from their code without having to know where it was on the disk. */
81 /* This is meant to be a replacement mechanism for +bundleForClass: users. */
82 /* Note that this does not search for bundles on the disk; it will locate */
83 /* only bundles already loaded or otherwise known to the current process. */
86 CFArrayRef
CFBundleGetAllBundles(void);
87 /* This is potentially expensive. Use with care. */
89 /* ===================== Creating Bundles ===================== */
92 UInt32
CFBundleGetTypeID(void);
95 CFBundleRef
CFBundleCreate(CFAllocatorRef allocator
, CFURLRef bundleURL
);
96 /* Might return an existing instance with the ref-count bumped. */
99 CFArrayRef
CFBundleCreateBundlesFromDirectory(CFAllocatorRef allocator
, CFURLRef directoryURL
, CFStringRef bundleType
);
100 /* Create instances for all bundles in the given directory matching the given */
101 /* type (or all of them if bundleType is NULL) */
103 /* ==================== Basic Bundle Info ==================== */
106 CFURLRef
CFBundleCopyBundleURL(CFBundleRef bundle
);
109 CFTypeRef
CFBundleGetValueForInfoDictionaryKey(CFBundleRef bundle
, CFStringRef key
);
110 /* Returns a localized value if available, otherwise the global value. */
111 /* This is the recommended function for examining the info dictionary. */
114 CFDictionaryRef
CFBundleGetInfoDictionary(CFBundleRef bundle
);
115 /* This is the global info dictionary. Note that CFBundle may add */
116 /* extra keys to the dictionary for its own use. */
119 CFDictionaryRef
CFBundleGetLocalInfoDictionary(CFBundleRef bundle
);
120 /* This is the localized info dictionary. */
123 void CFBundleGetPackageInfo(CFBundleRef bundle
, UInt32
*packageType
, UInt32
*packageCreator
);
126 CFStringRef
CFBundleGetIdentifier(CFBundleRef bundle
);
129 UInt32
CFBundleGetVersionNumber(CFBundleRef bundle
);
132 CFStringRef
CFBundleGetDevelopmentRegion(CFBundleRef bundle
);
135 CFURLRef
CFBundleCopySupportFilesDirectoryURL(CFBundleRef bundle
);
138 CFURLRef
CFBundleCopyResourcesDirectoryURL(CFBundleRef bundle
);
141 CFURLRef
CFBundleCopyPrivateFrameworksURL(CFBundleRef bundle
);
144 CFURLRef
CFBundleCopySharedFrameworksURL(CFBundleRef bundle
);
147 CFURLRef
CFBundleCopySharedSupportURL(CFBundleRef bundle
);
150 CFURLRef
CFBundleCopyBuiltInPlugInsURL(CFBundleRef bundle
);
152 /* ------------- Basic Bundle Info without a CFBundle instance ------------- */
153 /* This API is provided to enable developers to retrieve basic information */
154 /* about a bundle without having to create an instance of CFBundle. */
155 /* Because of caching behavior when a CFBundle instance exists, it will be faster */
156 /* to actually create a CFBundle if you need to retrieve multiple pieces of info. */
158 CFDictionaryRef
CFBundleCopyInfoDictionaryInDirectory(CFURLRef bundleURL
);
161 Boolean
CFBundleGetPackageInfoInDirectory(CFURLRef url
, UInt32
*packageType
, UInt32
*packageCreator
);
163 /* ==================== Resource Handling API ==================== */
166 CFURLRef
CFBundleCopyResourceURL(CFBundleRef bundle
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subDirName
);
169 CFArrayRef
CFBundleCopyResourceURLsOfType(CFBundleRef bundle
, CFStringRef resourceType
, CFStringRef subDirName
);
172 CFStringRef
CFBundleCopyLocalizedString(CFBundleRef bundle
, CFStringRef key
, CFStringRef value
, CFStringRef tableName
);
174 #define CFCopyLocalizedString(key, comment) \
175 CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), NULL)
176 #define CFCopyLocalizedStringFromTable(key, tbl, comment) \
177 CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), (tbl))
178 #define CFCopyLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
179 CFBundleCopyLocalizedString((bundle), (key), (key), (tbl))
180 #define CFCopyLocalizedStringWithDefaultValue(key, tbl, bundle, value, comment) \
181 CFBundleCopyLocalizedString((bundle), (key), (value), (tbl))
183 /* ------------- Resource Handling without a CFBundle instance ------------- */
184 /* This API is provided to enable developers to use the CFBundle resource */
185 /* searching policy without having to create an instance of CFBundle. */
186 /* Because of caching behavior when a CFBundle instance exists, it will be faster */
187 /* to actually create a CFBundle if you need to access several resources. */
190 CFURLRef
CFBundleCopyResourceURLInDirectory(CFURLRef bundleURL
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subDirName
);
193 CFArrayRef
CFBundleCopyResourceURLsOfTypeInDirectory(CFURLRef bundleURL
, CFStringRef resourceType
, CFStringRef subDirName
);
195 /* =========== Localization-specific Resource Handling API =========== */
196 /* This API allows finer-grained control over specific localizations, */
197 /* as distinguished from the above API, which always uses the user's */
198 /* preferred localizations for the bundle in the current app context. */
201 CFArrayRef
CFBundleCopyBundleLocalizations(CFBundleRef bundle
);
202 /* Lists the localizations that a bundle contains. */
205 CFArrayRef
CFBundleCopyPreferredLocalizationsFromArray(CFArrayRef locArray
);
206 /* Given an array of possible localizations, returns the one or more */
207 /* of them that CFBundle would use in the current application context. */
208 /* To determine the localizations that would be used for a particular */
209 /* bundle in the current application context, apply this function to the */
210 /* result of CFBundleCopyBundleLocalizations. */
212 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
214 CFArrayRef
CFBundleCopyLocalizationsForPreferences(CFArrayRef locArray
, CFArrayRef prefArray
);
215 /* Given an array of possible localizations, returns the one or more of */
216 /* them that CFBundle would use, without reference to the current application */
217 /* context, if the user's preferred localizations were given by prefArray. */
218 /* If prefArray is NULL, the current user's actual preferred localizations will */
219 /* be used. This is not the same as CFBundleCopyPreferredLocalizationsFromArray, */
220 /* because that function takes the current application context into account. */
221 /* To determine the localizations that another application would use, apply */
222 /* this function to the result of CFBundleCopyBundleLocalizations. */
226 CFURLRef
CFBundleCopyResourceURLForLocalization(CFBundleRef bundle
, CFStringRef resourceName
, CFStringRef resourceType
, CFStringRef subDirName
, CFStringRef localizationName
);
229 CFArrayRef
CFBundleCopyResourceURLsOfTypeForLocalization(CFBundleRef bundle
, CFStringRef resourceType
, CFStringRef subDirName
, CFStringRef localizationName
);
231 #if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED
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. */
236 CFDictionaryRef
CFBundleCopyInfoDictionaryForURL(CFURLRef url
);
237 /* For a directory URL, this is equivalent to CFBundleCopyInfoDictionaryInDirectory. */
238 /* For a plain file URL representing an unbundled application, this will attempt to read */
239 /* an info dictionary either from the (__TEXT, __info_plist) section (for a Mach-o file) */
240 /* or from a 'plst' resource. */
243 CFArrayRef
CFBundleCopyLocalizationsForURL(CFURLRef url
);
244 /* For a directory URL, this is equivalent to calling CFBundleCopyBundleLocalizations */
245 /* on the corresponding bundle. For a plain file URL representing an unbundled application, */
246 /* this will attempt to determine its localizations using the CFBundleLocalizations and */
247 /* CFBundleDevelopmentRegion keys in the dictionary returned by CFBundleCopyInfoDictionaryForURL,*/
248 /* or a 'vers' resource if those are not present. */
251 /* ==================== Primitive Code Loading API ==================== */
252 /* This API abstracts the various different executable formats supported on */
253 /* various platforms. It can load DYLD, CFM, or DLL shared libraries (on their */
254 /* appropriate platforms) and gives a uniform API for looking up functions. */
255 /* Note that Cocoa-based bundles containing Objective-C or Java code must */
256 /* be loaded with NSBundle, not CFBundle. Once they are loaded, however, */
257 /* either CFBundle or NSBundle can be used. */
260 CFURLRef
CFBundleCopyExecutableURL(CFBundleRef bundle
);
263 Boolean
CFBundleIsExecutableLoaded(CFBundleRef bundle
);
266 Boolean
CFBundleLoadExecutable(CFBundleRef bundle
);
269 void CFBundleUnloadExecutable(CFBundleRef bundle
);
272 void *CFBundleGetFunctionPointerForName(CFBundleRef bundle
, CFStringRef functionName
);
275 void CFBundleGetFunctionPointersForNames(CFBundleRef bundle
, CFArrayRef functionNames
, void *ftbl
[]);
278 void *CFBundleGetDataPointerForName(CFBundleRef bundle
, CFStringRef symbolName
);
281 void CFBundleGetDataPointersForNames(CFBundleRef bundle
, CFArrayRef symbolNames
, void *stbl
[]);
284 CFURLRef
CFBundleCopyAuxiliaryExecutableURL(CFBundleRef bundle
, CFStringRef executableName
);
285 /* This function can be used to find executables other than your main */
286 /* executable. This is useful, for instance, for applications that have */
287 /* some command line tool that is packaged with and used by the application. */
288 /* The tool can be packaged in the various platform executable directories */
289 /* in the bundle and can be located with this function. This allows an */
290 /* app to ship versions of the tool for each platform as it does for the */
291 /* main app executable. */
293 /* ==================== Getting a bundle's plugIn ==================== */
296 CFPlugInRef
CFBundleGetPlugIn(CFBundleRef bundle
);
298 /* ==================== Resource Manager-Related API ==================== */
301 short CFBundleOpenBundleResourceMap(CFBundleRef bundle
);
302 /* This function opens the non-localized and the localized resource files */
303 /* (if any) for the bundle, creates and makes current a single read-only */
304 /* resource map combining both, and returns a reference number for it. */
305 /* If it is called multiple times, it opens the files multiple times, */
306 /* and returns distinct reference numbers. */
309 SInt32
CFBundleOpenBundleResourceFiles(CFBundleRef bundle
, short *refNum
, short *localizedRefNum
);
310 /* Similar to CFBundleOpenBundleResourceMap, except that it creates two */
311 /* separate resource maps and returns reference numbers for both. */
314 void CFBundleCloseBundleResourceMap(CFBundleRef bundle
, short refNum
);
316 #if defined(__cplusplus)
320 #endif /* ! __COREFOUNDATION_CFBUNDLE__ */