Skip to content

Commit e7ccb1f

Browse files
Add more of CoreFoundation
1 parent 6f989e5 commit e7ccb1f

File tree

11 files changed

+1644
-751
lines changed

11 files changed

+1644
-751
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Objective-D
1+
# Objective D
22

3-
Objective-D provides essential bindings to Objective-C's Runtime API as well as as the
4-
Foundation framework.
3+
Type safe bindings to the Objective-C Runtime, Foundation and CoreFoundation for D.
54

6-
## NOTE
5+
## System Requirements
6+
This library is only available on Apple/Darwin derived operating systems currently.
7+
Eventually support may be added for non-apple systems.
78

8-
This relies on a D compiler which supports generating Objective-C compatible objects.
9-
Eg. DMD for x86_64 macs, or LDC with [This PR](https://github.com/ldc-developers/ldc/pull/4777).
9+
The library depends on Objective-C ABI support, and as such will only work on LDC 1.40+
10+
and DMD 2.111+.

dub.sdl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ copyright "Copyright © 2024, Inochi2D Project"
55
license "BSL-1.0"
66

77
# Only LDC is supported currently.
8-
toolchainRequirements gdc="no"
8+
toolchainRequirements gdc="no" frontend=">=2.111" ldc=">=1.40.0"
99

1010
targetPath "out/"
1111

12-
dependency "numem" version=">=1.0.4"
12+
dependency "numem" version=">=1.1.4"
1313

1414
# Default configuration.
1515
configuration "static" {

source/corefoundation/cfarray.d

Lines changed: 449 additions & 385 deletions
Large diffs are not rendered by default.

source/corefoundation/cfbundle.d

Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
/*
2+
CoreFoundation Bundles
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
7+
*/
8+
module corefoundation.cfbundle;
9+
import corefoundation.cfallocator;
10+
import corefoundation.cfstring;
11+
import corefoundation.core;
12+
import foundation.nsbundle;
13+
14+
extern(C) @nogc nothrow:
15+
16+
/**
17+
A reference to a CFBundle object.
18+
*/
19+
alias CFBundleRef = CFSubType!("CFBundle", NSBundle);
20+
alias CFPluginRef = CFBundleRef; /// ditto
21+
22+
/**
23+
Bundle Reference Number
24+
*/
25+
version(LP_64) alias CFBundleRefNum = int;
26+
else alias CFBundleRefNum = SInt16;
27+
28+
enum {
29+
kCFBundleExecutableArchitectureI386 = 0x00000007,
30+
kCFBundleExecutableArchitecturePPC = 0x00000012,
31+
kCFBundleExecutableArchitectureX86_64 = 0x01000007,
32+
kCFBundleExecutableArchitecturePPC64 = 0x01000012,
33+
kCFBundleExecutableArchitectureARM64 = 0x0100000c,
34+
}
35+
36+
/**
37+
The version of the Info.plist format
38+
*/
39+
extern __gshared const CFStringRef kCFBundleInfoDictionaryVersionKey;
40+
41+
/**
42+
The name of the executable in this bundle, if any
43+
*/
44+
extern __gshared const CFStringRef kCFBundleExecutableKey;
45+
46+
/**
47+
The bundle identifier (for CFBundleGetBundleWithIdentifier())
48+
*/
49+
extern __gshared const CFStringRef kCFBundleIdentifierKey;
50+
51+
/**
52+
The version number of the bundle. For Mac OS 9 style version numbers (for example "2.5.3d5"),
53+
clients can use CFBundleGetVersionNumber() instead of accessing this key directly since that
54+
function will properly convert the version string into its compact integer representation.
55+
*/
56+
extern __gshared const CFStringRef kCFBundleVersionKey;
57+
58+
/**
59+
The name of the development language of the bundle.
60+
*/
61+
extern __gshared const CFStringRef kCFBundleDevelopmentRegionKey;
62+
63+
/**
64+
The human-readable name of the bundle. This key is often found in the InfoPlist.strings since it is usually localized.
65+
*/
66+
extern __gshared const CFStringRef kCFBundleNameKey;
67+
68+
/**
69+
Allows an unbundled application that handles localization itself to specify which localizations it has available.
70+
*/
71+
extern __gshared const CFStringRef kCFBundleLocalizationsKey;
72+
73+
/**
74+
Returns the main bundle.
75+
76+
Returns:
77+
The main bundle for the current process.
78+
*/
79+
extern CFBundleRef CFBundleGetMainBundle();
80+
81+
/**
82+
A bundle can name itself by providing a key in the info dictionary.
83+
This facility is meant to allow bundle-writers to get hold of their
84+
bundle from their code without having to know where it was on the disk.
85+
This is meant to be a replacement mechanism for +bundleForClass: users.
86+
Note that this does not search for bundles on the disk; it will locate
87+
only bundles already loaded or otherwise known to the current process.
88+
*/
89+
extern CFBundleRef CFBundleGetBundleWithIdentifier(CFStringRef bundleID);
90+
91+
/**
92+
This is potentially expensive, and not thread-safe.
93+
Use with care.
94+
Best used for debuggging or other diagnostic purposes.
95+
*/
96+
extern CFArrayRef CFBundleGetAllBundles();
97+
98+
extern CFTypeID CFBundleGetTypeID();
99+
100+
extern CFBundleRef CFBundleCreate(CFAllocatorRef allocator, CFURLRef bundleURL);
101+
/* Might return an existing instance with the ref-count bumped. */
102+
103+
extern CFArrayRef CFBundleCreateBundlesFromDirectory(CFAllocatorRef allocator, CFURLRef directoryURL, CFStringRef bundleType);
104+
/* Create instances for all bundles in the given directory matching the given type */
105+
/* (or all of them if bundleType is NULL). Instances are created using CFBundleCreate() and are not released. */
106+
107+
/* ==================== Basic Bundle Info ==================== */
108+
109+
extern CFURLRef CFBundleCopyBundleURL(CFBundleRef bundle);
110+
111+
extern CFTypeRef CFBundleGetValueForInfoDictionaryKey(CFBundleRef bundle, CFStringRef key);
112+
/* Returns a localized value if available, otherwise the global value. */
113+
/* This is the recommended function for examining the info dictionary. */
114+
115+
extern CFDictionaryRef CFBundleGetInfoDictionary(CFBundleRef bundle);
116+
/* This is the global info dictionary. Note that CFBundle may add */
117+
/* extra keys to the dictionary for its own use. */
118+
119+
extern CFDictionaryRef CFBundleGetLocalInfoDictionary(CFBundleRef bundle);
120+
/* This is the localized info dictionary. */
121+
122+
extern void CFBundleGetPackageInfo(CFBundleRef bundle, UInt32 *packageType, UInt32 *packageCreator);
123+
124+
extern CFStringRef CFBundleGetIdentifier(CFBundleRef bundle);
125+
126+
extern UInt32 CFBundleGetVersionNumber(CFBundleRef bundle);
127+
128+
extern CFStringRef CFBundleGetDevelopmentRegion(CFBundleRef bundle);
129+
130+
extern CFURLRef CFBundleCopySupportFilesDirectoryURL(CFBundleRef bundle);
131+
132+
extern CFURLRef CFBundleCopyResourcesDirectoryURL(CFBundleRef bundle);
133+
134+
extern CFURLRef CFBundleCopyPrivateFrameworksURL(CFBundleRef bundle);
135+
136+
extern CFURLRef CFBundleCopySharedFrameworksURL(CFBundleRef bundle);
137+
138+
extern CFURLRef CFBundleCopySharedSupportURL(CFBundleRef bundle);
139+
140+
extern CFURLRef CFBundleCopyBuiltInPlugInsURL(CFBundleRef bundle);
141+
142+
/* ------------- Basic Bundle Info without a CFBundle instance ------------- */
143+
/* This API is provided to enable developers to retrieve basic information */
144+
/* about a bundle without having to create an instance of CFBundle. */
145+
/* Because of caching behavior when a CFBundle instance exists, it will be faster */
146+
/* to actually create a CFBundle if you need to retrieve multiple pieces of info. */
147+
extern CFDictionaryRef CFBundleCopyInfoDictionaryInDirectory(CFURLRef bundleURL);
148+
149+
extern Boolean CFBundleGetPackageInfoInDirectory(CFURLRef url, UInt32 *packageType, UInt32 *packageCreator);
150+
151+
/* ==================== Resource Handling API ==================== */
152+
153+
extern CFURLRef CFBundleCopyResourceURL(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName);
154+
extern CFArrayRef CFBundleCopyResourceURLsOfType(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName);
155+
extern CFStringRef CFBundleCopyLocalizedString(CFBundleRef bundle, CFStringRef key, CFStringRef value, CFStringRef tableName);
156+
157+
/**
158+
Returns a localized string given a list of possible localizations.
159+
The one most suitable to use with the given $(D bundle) is returned.
160+
161+
Params:
162+
bundle = The bundle to examine.
163+
key: The key for the localized string to retrieve.
164+
value: A default value to return if no value exists for $(D key).
165+
tableName: The name of the strings file to search.
166+
localizations = An array of BCP 47 language codes corresponding to available localizations.
167+
Bundle compares the array against its available localizations, and uses the best
168+
result to retrieve the localized string.
169+
If empty, we treat it as no localization is available, and may return a fallback.
170+
171+
Returns:
172+
A localized version of the string designated by $(D key) in table $(D tableName).
173+
*/
174+
extern CFStringRef CFBundleCopyLocalizedStringForLocalizations(CFBundleRef bundle, CFStringRef key, CFStringRef value, CFStringRef tableName, CFArrayRef localizations);
175+
176+
extern CFURLRef CFBundleCopyResourceURLInDirectory(CFURLRef bundleURL, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName);
177+
extern CFArrayRef CFBundleCopyResourceURLsOfTypeInDirectory(CFURLRef bundleURL, CFStringRef resourceType, CFStringRef subDirName);
178+
179+
/**
180+
Lists the localizations that a bundle contains.
181+
*/
182+
extern CFArrayRef CFBundleCopyBundleLocalizations(CFBundleRef bundle);
183+
184+
/**
185+
Get localizations from an array.
186+
187+
Given an array of possible localizations, returns the one or more
188+
of them that CFBundle would use in the current application context.
189+
To determine the localizations that would be used for a particular
190+
bundle in the current application context, apply this function to the
191+
result of CFBundleCopyBundleLocalizations().
192+
*/
193+
extern CFArrayRef CFBundleCopyPreferredLocalizationsFromArray(CFArrayRef locArray);
194+
195+
/**
196+
Given an array of possible localizations, returns the one or more of
197+
them that CFBundle would use, without reference to the current application
198+
context, if the user's preferred localizations were given by prefArray.
199+
If prefArray is NULL, the current user's actual preferred localizations will
200+
be used. This is not the same as CFBundleCopyPreferredLocalizationsFromArray(),
201+
because that function takes the current application context into account.
202+
To determine the localizations that another application would use, apply
203+
this function to the result of CFBundleCopyBundleLocalizations().
204+
*/
205+
extern CFArrayRef CFBundleCopyLocalizationsForPreferences(CFArrayRef locArray, CFArrayRef prefArray);
206+
extern CFURLRef CFBundleCopyResourceURLForLocalization(CFBundleRef bundle, CFStringRef resourceName, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName);
207+
208+
/**
209+
The localizationName argument to CFBundleCopyResourceURLForLocalization() or
210+
CFBundleCopyResourceURLsOfTypeForLocalization() must be identical to one of the
211+
localizations in the bundle, as returned by CFBundleCopyBundleLocalizations().
212+
It is recommended that either CFBundleCopyPreferredLocalizationsFromArray() or
213+
CFBundleCopyLocalizationsForPreferences() be used to select the localization.
214+
*/
215+
extern CFArrayRef CFBundleCopyResourceURLsOfTypeForLocalization(CFBundleRef bundle, CFStringRef resourceType, CFStringRef subDirName, CFStringRef localizationName);
216+
217+
/**
218+
For a directory URL, this is equivalent to CFBundleCopyInfoDictionaryInDirectory().
219+
For a plain file URL representing an unbundled executable, this will attempt to read
220+
an info dictionary from the (__TEXT, __info_plist) section, if it is a Mach-o file.
221+
*/
222+
extern CFDictionaryRef CFBundleCopyInfoDictionaryForURL(CFURLRef url);
223+
224+
/**
225+
For a directory URL, this is equivalent to calling CFBundleCopyBundleLocalizations()
226+
on the corresponding bundle. For a plain file URL representing an unbundled executable,
227+
this will attempt to determine its localizations using the CFBundleLocalizations and
228+
CFBundleDevelopmentRegion keys in the dictionary returned by CFBundleCopyInfoDictionaryForURL.
229+
*/
230+
extern CFArrayRef CFBundleCopyLocalizationsForURL(CFURLRef url);
231+
232+
/**
233+
For a directory URL, this is equivalent to calling CFBundleCopyExecutableArchitectures()
234+
on the corresponding bundle. For a plain file URL representing an unbundled executable,
235+
this will return the architectures it provides, if it is a Mach-o file, or NULL otherwise.
236+
*/
237+
extern CFArrayRef CFBundleCopyExecutableArchitecturesForURL(CFURLRef url);
238+
extern CFURLRef CFBundleCopyExecutableURL(CFBundleRef bundle);
239+
240+
/**
241+
If the bundle's executable exists and is a Mach-o file, this function will return an array
242+
of CFNumbers whose values are integers representing the architectures the file provides.
243+
The values currently in use are those listed in the enum above, but others may be added
244+
in the future. If the executable is not a Mach-o file, this function returns NULL.
245+
*/
246+
extern CFArrayRef CFBundleCopyExecutableArchitectures(CFBundleRef bundle);
247+
248+
/**
249+
This function will return true if the bundle is loaded, or if the bundle appears to be
250+
loadable upon inspection. This does not mean that the bundle is definitively loadable,
251+
since it may fail to load due to link errors or other problems not readily detectable.
252+
If this function detects problems, it will return false, and return a CFError by reference.
253+
It is the responsibility of the caller to release the CFError.
254+
*/
255+
extern Boolean CFBundlePreflightExecutable(CFBundleRef bundle, CFErrorRef *error);
256+
257+
/**
258+
If the bundle is already loaded, this function will return true. Otherwise, it will attempt
259+
to load the bundle, and it will return true if that attempt succeeds. If the bundle fails
260+
to load, this function will return false, and it will return a CFError by reference.
261+
It is the responsibility of the caller to release the CFError.
262+
*/
263+
extern Boolean CFBundleLoadExecutableAndReturnError(CFBundleRef bundle, CFErrorRef *error);
264+
265+
extern Boolean CFBundleLoadExecutable(CFBundleRef bundle);
266+
extern Boolean CFBundleIsExecutableLoaded(CFBundleRef bundle);
267+
extern void CFBundleUnloadExecutable(CFBundleRef bundle);
268+
extern void *CFBundleGetFunctionPointerForName(CFBundleRef bundle, CFStringRef functionName);
269+
extern void CFBundleGetFunctionPointersForNames(CFBundleRef bundle, CFArrayRef functionNames, void *ftbl[]);
270+
extern void *CFBundleGetDataPointerForName(CFBundleRef bundle, CFStringRef symbolName);
271+
extern void CFBundleGetDataPointersForNames(CFBundleRef bundle, CFArrayRef symbolNames, void *stbl[]);
272+
273+
/**
274+
This function can be used to find executables other than your main
275+
executable. This is useful, for instance, for applications that have
276+
some command line tool that is packaged with and used by the application.
277+
The tool can be packaged in the various platform executable directories
278+
in the bundle and can be located with this function. This allows an
279+
app to ship versions of the tool for each platform as it does for the
280+
main app executable.
281+
*/
282+
extern CFURLRef CFBundleCopyAuxiliaryExecutableURL(CFBundleRef bundle, CFStringRef executableName);
283+
extern CFPlugInRef CFBundleGetPlugIn(CFBundleRef bundle);
284+
285+
version(OSX) {
286+
extern Boolean CFBundleIsExecutableLoadable(CFBundleRef bundle);
287+
extern Boolean CFBundleIsExecutableLoadableForURL(CFURLRef url);
288+
extern Boolean CFBundleIsArchitectureLoadable(cpu_type_t arch);
289+
290+
/**
291+
This function opens the non-localized and the localized resource files
292+
(if any) for the bundle, creates and makes current a single read-only
293+
resource map combining both, and returns a reference number for it.
294+
If it is called multiple times, it opens the files multiple times,
295+
and returns distinct reference numbers.
296+
*/
297+
deprecated("The Carbon Resource Manager is deprecated. This should only be used to access Resource Manager-style resources in old bundles.")
298+
extern CFBundleRefNum CFBundleOpenBundleResourceMap(CFBundleRef bundle);
299+
300+
/**
301+
Similar to CFBundleOpenBundleResourceMap(), except that it creates two
302+
separate resource maps and returns reference numbers for both.
303+
*/
304+
deprecated("The Carbon Resource Manager is deprecated. This should only be used to access Resource Manager-style resources in old bundles.")
305+
extern SInt32 CFBundleOpenBundleResourceFiles(CFBundleRef bundle, CFBundleRefNum *refNum, CFBundleRefNum *localizedRefNum);
306+
307+
deprecated("The Carbon Resource Manager is deprecated. This should only be used to access Resource Manager-style resources in old bundles.")
308+
extern void CFBundleCloseBundleResourceMap(CFBundleRef bundle, CFBundleRefNum refNum);
309+
}

0 commit comments

Comments
 (0)