CFBundle.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. { CFBundle.h
  2. Copyright (c) 1999-2005, Apple, Inc. All rights reserved.
  3. }
  4. { Pascal Translation Updated: Peter N Lewis, <[email protected]>, September 2005 }
  5. {
  6. Modified for use with Free Pascal
  7. Version 200
  8. Please report any bugs to <[email protected]>
  9. }
  10. {$mode macpas}
  11. {$packenum 1}
  12. {$macro on}
  13. {$inline on}
  14. {$CALLING MWPASCAL}
  15. unit CFBundle;
  16. interface
  17. {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
  18. {$setc GAP_INTERFACES_VERSION := $0200}
  19. {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
  20. {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
  21. {$endc}
  22. {$ifc defined CPUPOWERPC and defined CPUI386}
  23. {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
  24. {$endc}
  25. {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
  26. {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
  27. {$endc}
  28. {$ifc not defined __ppc__ and defined CPUPOWERPC}
  29. {$setc __ppc__ := 1}
  30. {$elsec}
  31. {$setc __ppc__ := 0}
  32. {$endc}
  33. {$ifc not defined __i386__ and defined CPUI386}
  34. {$setc __i386__ := 1}
  35. {$elsec}
  36. {$setc __i386__ := 0}
  37. {$endc}
  38. {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
  39. {$error Conflicting definitions for __ppc__ and __i386__}
  40. {$endc}
  41. {$ifc defined __ppc__ and __ppc__}
  42. {$setc TARGET_CPU_PPC := TRUE}
  43. {$setc TARGET_CPU_X86 := FALSE}
  44. {$elifc defined __i386__ and __i386__}
  45. {$setc TARGET_CPU_PPC := FALSE}
  46. {$setc TARGET_CPU_X86 := TRUE}
  47. {$elsec}
  48. {$error Neither __ppc__ nor __i386__ is defined.}
  49. {$endc}
  50. {$setc TARGET_CPU_PPC_64 := FALSE}
  51. {$ifc defined FPC_BIG_ENDIAN}
  52. {$setc TARGET_RT_BIG_ENDIAN := TRUE}
  53. {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
  54. {$elifc defined FPC_LITTLE_ENDIAN}
  55. {$setc TARGET_RT_BIG_ENDIAN := FALSE}
  56. {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
  57. {$elsec}
  58. {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
  59. {$endc}
  60. {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
  61. {$setc CALL_NOT_IN_CARBON := FALSE}
  62. {$setc OLDROUTINENAMES := FALSE}
  63. {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
  64. {$setc OPAQUE_UPP_TYPES := TRUE}
  65. {$setc OTCARBONAPPLICATION := TRUE}
  66. {$setc OTKERNEL := FALSE}
  67. {$setc PM_USE_SESSION_APIS := TRUE}
  68. {$setc TARGET_API_MAC_CARBON := TRUE}
  69. {$setc TARGET_API_MAC_OS8 := FALSE}
  70. {$setc TARGET_API_MAC_OSX := TRUE}
  71. {$setc TARGET_CARBON := TRUE}
  72. {$setc TARGET_CPU_68K := FALSE}
  73. {$setc TARGET_CPU_MIPS := FALSE}
  74. {$setc TARGET_CPU_SPARC := FALSE}
  75. {$setc TARGET_OS_MAC := TRUE}
  76. {$setc TARGET_OS_UNIX := FALSE}
  77. {$setc TARGET_OS_WIN32 := FALSE}
  78. {$setc TARGET_RT_MAC_68881 := FALSE}
  79. {$setc TARGET_RT_MAC_CFM := FALSE}
  80. {$setc TARGET_RT_MAC_MACHO := TRUE}
  81. {$setc TYPED_FUNCTION_POINTERS := TRUE}
  82. {$setc TYPE_BOOL := FALSE}
  83. {$setc TYPE_EXTENDED := FALSE}
  84. {$setc TYPE_LONGLONG := TRUE}
  85. uses MacTypes,CFBase,CFArray,CFDictionary,CFString,CFURL;
  86. {$ALIGN POWER}
  87. type
  88. CFBundleRef = ^SInt32; { an opaque 32-bit type }
  89. CFBundleRefPtr = ^CFBundleRef;
  90. CFPlugInRef = ^SInt32; { an opaque 32-bit type }
  91. CFPlugInRefPtr = ^CFPlugInRef;
  92. { ===================== Standard Info.plist keys ===================== }
  93. var kCFBundleInfoDictionaryVersionKey: CFStringRef; external name '_kCFBundleInfoDictionaryVersionKey'; (* attribute const *)
  94. { The version of the Info.plist format }
  95. var kCFBundleExecutableKey: CFStringRef; external name '_kCFBundleExecutableKey'; (* attribute const *)
  96. { The name of the executable in this bundle (if any) }
  97. var kCFBundleIdentifierKey: CFStringRef; external name '_kCFBundleIdentifierKey'; (* attribute const *)
  98. { The bundle identifier (for CFBundleGetBundleWithIdentifier()) }
  99. var kCFBundleVersionKey: CFStringRef; external name '_kCFBundleVersionKey'; (* attribute const *)
  100. { The version number of the bundle. For Mac OS 9 style version numbers (for example "2.5.3d5"), clients can use CFBundleGetVersionNumber() instead of accessing this key directly since that function will properly convert the version string into its compact integer representation. }
  101. var kCFBundleDevelopmentRegionKey: CFStringRef; external name '_kCFBundleDevelopmentRegionKey'; (* attribute const *)
  102. { The name of the development language of the bundle. }
  103. var kCFBundleNameKey: CFStringRef; external name '_kCFBundleNameKey'; (* attribute const *)
  104. { The human-readable name of the bundle. This key is often found in the InfoPlist.strings since it is usually localized. }
  105. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  106. var kCFBundleLocalizationsKey: CFStringRef; external name '_kCFBundleLocalizationsKey'; (* attribute const *)
  107. { Allows an unbundled application that handles localization itself to specify which localizations it has available. }
  108. {#endif}
  109. { ===================== Finding Bundles ===================== }
  110. function CFBundleGetMainBundle: CFBundleRef; external name '_CFBundleGetMainBundle';
  111. function CFBundleGetBundleWithIdentifier( bundleID: CFStringRef ): CFBundleRef; external name '_CFBundleGetBundleWithIdentifier';
  112. { A bundle can name itself by providing a key in the info dictionary. }
  113. { This facility is meant to allow bundle-writers to get hold of their }
  114. { bundle from their code without having to know where it was on the disk. }
  115. { This is meant to be a replacement mechanism for +bundleForClass: users. }
  116. { Note that this does not search for bundles on the disk; it will locate }
  117. { only bundles already loaded or otherwise known to the current process. }
  118. function CFBundleGetAllBundles: CFArrayRef; external name '_CFBundleGetAllBundles';
  119. { This is potentially expensive. Use with care. }
  120. { ===================== Creating Bundles ===================== }
  121. function CFBundleGetTypeID: UInt32; external name '_CFBundleGetTypeID';
  122. function CFBundleCreate( allocator: CFAllocatorRef; bundleURL: CFURLRef ): CFBundleRef; external name '_CFBundleCreate';
  123. { Might return an existing instance with the ref-count bumped. }
  124. function CFBundleCreateBundlesFromDirectory( allocator: CFAllocatorRef; directoryURL: CFURLRef; bundleType: CFStringRef ): CFArrayRef; external name '_CFBundleCreateBundlesFromDirectory';
  125. { Create instances for all bundles in the given directory matching the given }
  126. { type (or all of them if bundleType is NULL) }
  127. { ==================== Basic Bundle Info ==================== }
  128. function CFBundleCopyBundleURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopyBundleURL';
  129. function CFBundleGetValueForInfoDictionaryKey( bundle: CFBundleRef; key: CFStringRef ): CFTypeRef; external name '_CFBundleGetValueForInfoDictionaryKey';
  130. { Returns a localized value if available, otherwise the global value. }
  131. { This is the recommended function for examining the info dictionary. }
  132. function CFBundleGetInfoDictionary( bundle: CFBundleRef ): CFDictionaryRef; external name '_CFBundleGetInfoDictionary';
  133. { This is the global info dictionary. Note that CFBundle may add }
  134. { extra keys to the dictionary for its own use. }
  135. function CFBundleGetLocalInfoDictionary( bundle: CFBundleRef ): CFDictionaryRef; external name '_CFBundleGetLocalInfoDictionary';
  136. { This is the localized info dictionary. }
  137. procedure CFBundleGetPackageInfo( bundle: CFBundleRef; var packageType: OSType; var packageCreator: OSType ); external name '_CFBundleGetPackageInfo';
  138. function CFBundleGetIdentifier( bundle: CFBundleRef ): CFStringRef; external name '_CFBundleGetIdentifier';
  139. function CFBundleGetVersionNumber( bundle: CFBundleRef ): UInt32; external name '_CFBundleGetVersionNumber';
  140. function CFBundleGetDevelopmentRegion( bundle: CFBundleRef ): CFStringRef; external name '_CFBundleGetDevelopmentRegion';
  141. function CFBundleCopySupportFilesDirectoryURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopySupportFilesDirectoryURL';
  142. function CFBundleCopyResourcesDirectoryURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopyResourcesDirectoryURL';
  143. function CFBundleCopyPrivateFrameworksURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopyPrivateFrameworksURL';
  144. function CFBundleCopySharedFrameworksURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopySharedFrameworksURL';
  145. function CFBundleCopySharedSupportURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopySharedSupportURL';
  146. function CFBundleCopyBuiltInPlugInsURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopyBuiltInPlugInsURL';
  147. { ------------- Basic Bundle Info without a CFBundle instance ------------- }
  148. { This API is provided to enable developers to retrieve basic information }
  149. { about a bundle without having to create an instance of CFBundle. }
  150. { Because of caching behavior when a CFBundle instance exists, it will be faster }
  151. { to actually create a CFBundle if you need to retrieve multiple pieces of info. }
  152. function CFBundleCopyInfoDictionaryInDirectory( bundleURL: CFURLRef ): CFDictionaryRef; external name '_CFBundleCopyInfoDictionaryInDirectory';
  153. function CFBundleGetPackageInfoInDirectory( url: CFURLRef; var packageType: UInt32; var packageCreator: UInt32 ): Boolean; external name '_CFBundleGetPackageInfoInDirectory';
  154. { ==================== Resource Handling API ==================== }
  155. function CFBundleCopyResourceURL( bundle: CFBundleRef; resourceName: CFStringRef; resourceType: CFStringRef; subDirName: CFStringRef ): CFURLRef; external name '_CFBundleCopyResourceURL';
  156. function CFBundleCopyResourceURLsOfType( bundle: CFBundleRef; resourceType: CFStringRef; subDirName: CFStringRef ): CFArrayRef; external name '_CFBundleCopyResourceURLsOfType';
  157. function CFBundleCopyLocalizedString( bundle: CFBundleRef; key: CFStringRef; value: CFStringRef; tableName: CFStringRef ): CFStringRef; external name '_CFBundleCopyLocalizedString';
  158. function CFCopyLocalizedString( key: CFStringRef; comment: PChar ): CFStringRef; inline;
  159. function CFCopyLocalizedStringFromTable( key: CFStringRef; tableName: CFStringRef; comment: PChar ): CFStringRef; inline;
  160. function CFCopyLocalizedStringFromTableInBundle( key: CFStringRef; tableName: CFStringRef; bundle: CFBundleRef; comment: PChar ): CFStringRef; inline;
  161. function CFCopyLocalizedStringWithDefaultValue( key: CFStringRef; tableName: CFStringRef; bundle: CFBundleRef; value: CFStringRef; comment: PChar ): CFStringRef; inline;
  162. { ------------- Resource Handling without a CFBundle instance ------------- }
  163. { This API is provided to enable developers to use the CFBundle resource }
  164. { searching policy without having to create an instance of CFBundle. }
  165. { Because of caching behavior when a CFBundle instance exists, it will be faster }
  166. { to actually create a CFBundle if you need to access several resources. }
  167. function CFBundleCopyResourceURLInDirectory( bundleURL: CFURLRef; resourceName: CFStringRef; resourceType: CFStringRef; subDirName: CFStringRef ): CFURLRef; external name '_CFBundleCopyResourceURLInDirectory';
  168. function CFBundleCopyResourceURLsOfTypeInDirectory( bundleURL: CFURLRef; resourceType: CFStringRef; subDirName: CFStringRef ): CFArrayRef; external name '_CFBundleCopyResourceURLsOfTypeInDirectory';
  169. { =========== Localization-specific Resource Handling API =========== }
  170. { This API allows finer-grained control over specific localizations, }
  171. { as distinguished from the above API, which always uses the user's }
  172. { preferred localizations for the bundle in the current app context. }
  173. function CFBundleCopyBundleLocalizations( bundle: CFBundleRef ): CFArrayRef; external name '_CFBundleCopyBundleLocalizations';
  174. { Lists the localizations that a bundle contains. }
  175. function CFBundleCopyPreferredLocalizationsFromArray( locArray: CFArrayRef ): CFArrayRef; external name '_CFBundleCopyPreferredLocalizationsFromArray';
  176. { Given an array of possible localizations, returns the one or more }
  177. { of them that CFBundle would use in the current application context. }
  178. { To determine the localizations that would be used for a particular }
  179. { bundle in the current application context, apply this function to the }
  180. { result of CFBundleCopyBundleLocalizations. }
  181. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  182. function CFBundleCopyLocalizationsForPreferences( locArray: CFArrayRef; prefArray: CFArrayRef ): CFArrayRef; external name '_CFBundleCopyLocalizationsForPreferences';
  183. { Given an array of possible localizations, returns the one or more of }
  184. { them that CFBundle would use, without reference to the current application }
  185. { context, if the user's preferred localizations were given by prefArray. }
  186. { If prefArray is NULL, the current user's actual preferred localizations will }
  187. { be used. This is not the same as CFBundleCopyPreferredLocalizationsFromArray, }
  188. { because that function takes the current application context into account. }
  189. { To determine the localizations that another application would use, apply }
  190. { this function to the result of CFBundleCopyBundleLocalizations. }
  191. {#endif}
  192. function CFBundleCopyResourceURLForLocalization( bundle: CFBundleRef; resourceName: CFStringRef; resourceType: CFStringRef; subDirName: CFStringRef; localizationName: CFStringRef ): CFURLRef; external name '_CFBundleCopyResourceURLForLocalization';
  193. function CFBundleCopyResourceURLsOfTypeForLocalization( bundle: CFBundleRef; resourceType: CFStringRef; subDirName: CFStringRef; localizationName: CFStringRef ): CFArrayRef; external name '_CFBundleCopyResourceURLsOfTypeForLocalization';
  194. {#if MAC_OS_X_VERSION_10_2 <= MAC_OS_X_VERSION_MAX_ALLOWED}
  195. { =================== Unbundled application info ===================== }
  196. { This API is provided to enable developers to retrieve bundle-related }
  197. { information about an application that may be bundled or unbundled. }
  198. function CFBundleCopyInfoDictionaryForURL( url: CFURLRef ): CFDictionaryRef; external name '_CFBundleCopyInfoDictionaryForURL';
  199. { For a directory URL, this is equivalent to CFBundleCopyInfoDictionaryInDirectory. }
  200. { For a plain file URL representing an unbundled application, this will attempt to read }
  201. { an info dictionary either from the (__TEXT, __info_plist) section (for a Mach-o file) }
  202. { or from a 'plst' resource. }
  203. function CFBundleCopyLocalizationsForURL( url: CFURLRef ): CFArrayRef; external name '_CFBundleCopyLocalizationsForURL';
  204. { For a directory URL, this is equivalent to calling CFBundleCopyBundleLocalizations }
  205. { on the corresponding bundle. For a plain file URL representing an unbundled application, }
  206. { this will attempt to determine its localizations using the CFBundleLocalizations and }
  207. { CFBundleDevelopmentRegion keys in the dictionary returned by CFBundleCopyInfoDictionaryForURL,}
  208. { or a 'vers' resource if those are not present. }
  209. {#endif}
  210. { ==================== Primitive Code Loading API ==================== }
  211. { This API abstracts the various different executable formats supported on }
  212. { various platforms. It can load DYLD, CFM, or DLL shared libraries (on their }
  213. { appropriate platforms) and gives a uniform API for looking up functions. }
  214. { Note that Cocoa-based bundles containing Objective-C or Java code must }
  215. { be loaded with NSBundle, not CFBundle. Once they are loaded, however, }
  216. { either CFBundle or NSBundle can be used. }
  217. function CFBundleCopyExecutableURL( bundle: CFBundleRef ): CFURLRef; external name '_CFBundleCopyExecutableURL';
  218. function CFBundleIsExecutableLoaded( bundle: CFBundleRef ): Boolean; external name '_CFBundleIsExecutableLoaded';
  219. function CFBundleLoadExecutable( bundle: CFBundleRef ): Boolean; external name '_CFBundleLoadExecutable';
  220. procedure CFBundleUnloadExecutable( bundle: CFBundleRef ); external name '_CFBundleUnloadExecutable';
  221. function CFBundleGetFunctionPointerForName( bundle: CFBundleRef; functionName: CFStringRef ): UnivPtr; external name '_CFBundleGetFunctionPointerForName';
  222. procedure CFBundleGetFunctionPointersForNames( bundle: CFBundleRef; functionNames: CFArrayRef; ftbl: {variable-size-array} UnivPtrPtr ); external name '_CFBundleGetFunctionPointersForNames';
  223. function CFBundleGetDataPointerForName( bundle: CFBundleRef; symbolName: CFStringRef ): UnivPtr; external name '_CFBundleGetDataPointerForName';
  224. procedure CFBundleGetDataPointersForNames( bundle: CFBundleRef; symbolNames: CFArrayRef; stbl: {variable-size-array} UnivPtrPtr ); external name '_CFBundleGetDataPointersForNames';
  225. function CFBundleCopyAuxiliaryExecutableURL( bundle: CFBundleRef; executableName: CFStringRef ): CFURLRef; external name '_CFBundleCopyAuxiliaryExecutableURL';
  226. { This function can be used to find executables other than your main }
  227. { executable. This is useful, for instance, for applications that have }
  228. { some command line tool that is packaged with and used by the application. }
  229. { The tool can be packaged in the various platform executable directories }
  230. { in the bundle and can be located with this function. This allows an }
  231. { app to ship versions of the tool for each platform as it does for the }
  232. { main app executable. }
  233. { ==================== Getting a bundle's plugIn ==================== }
  234. function CFBundleGetPlugIn( bundle: CFBundleRef ): CFPlugInRef; external name '_CFBundleGetPlugIn';
  235. { ==================== Resource Manager-Related API ==================== }
  236. function CFBundleOpenBundleResourceMap( bundle: CFBundleRef ): SInt16; external name '_CFBundleOpenBundleResourceMap';
  237. { This function opens the non-localized and the localized resource files }
  238. { (if any) for the bundle, creates and makes current a single read-only }
  239. { resource map combining both, and returns a reference number for it. }
  240. { If it is called multiple times, it opens the files multiple times, }
  241. { and returns distinct reference numbers. }
  242. function CFBundleOpenBundleResourceFiles( bundle: CFBundleRef; var refNum: SInt16; var localizedRefNum: SInt16 ): SInt32; external name '_CFBundleOpenBundleResourceFiles';
  243. { Similar to CFBundleOpenBundleResourceMap, except that it creates two }
  244. { separate resource maps and returns reference numbers for both. }
  245. procedure CFBundleCloseBundleResourceMap( bundle: CFBundleRef; refNum: SInt16 ); external name '_CFBundleCloseBundleResourceMap';
  246. implementation
  247. {$R-}
  248. function CFCopyLocalizedString( key: CFStringRef; comment: PChar ): CFStringRef; inline;
  249. begin
  250. CFCopyLocalizedString := CFBundleCopyLocalizedString( CFBundleGetMainBundle, key, key, nil );
  251. end;
  252. function CFCopyLocalizedStringFromTable( key: CFStringRef; tableName: CFStringRef; comment: PChar ): CFStringRef; inline;
  253. begin
  254. CFCopyLocalizedStringFromTable := CFBundleCopyLocalizedString( CFBundleGetMainBundle, key, key, tableName );
  255. end;
  256. function CFCopyLocalizedStringFromTableInBundle( key: CFStringRef; tableName: CFStringRef; bundle: CFBundleRef; comment: PChar ): CFStringRef; inline;
  257. begin
  258. CFCopyLocalizedStringFromTableInBundle := CFBundleCopyLocalizedString( bundle, key, key, tableName );
  259. end;
  260. function CFCopyLocalizedStringWithDefaultValue( key: CFStringRef; tableName: CFStringRef; bundle: CFBundleRef; value: CFStringRef; comment: PChar ): CFStringRef; inline;
  261. begin
  262. CFCopyLocalizedStringWithDefaultValue := CFBundleCopyLocalizedString( bundle, key, value, tableName );
  263. end;
  264. end.