Skip to content

Commit 437be24

Browse files
committed
CFBundleCopyResourcesDirectoryURL
1 parent d2ff402 commit 437be24

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

core-foundation-sys/src/bundle.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ extern {
3535
pub fn CFBundleCopyPrivateFrameworksURL(bundle: CFBundleRef) -> CFURLRef;
3636
pub fn CFBundleCopySharedSupportURL(bundle: CFBundleRef) -> CFURLRef;
3737
pub fn CFBundleCopyBundleURL(bundle: CFBundleRef) -> CFURLRef;
38+
pub fn CFBundleCopyResourcesDirectoryURL(bundle: CFBundleRef) -> CFURLRef;
3839
}

core-foundation/src/bundle.rs

+18
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,24 @@ impl CFBundle {
9999
Some(PathBuf::from(url.get_file_system_path(kCFURLPOSIXPathStyle).to_string()))
100100
}
101101

102+
/// Bundle's resources location
103+
pub fn bundle_resources_url(&self) -> Option<CFURL> {
104+
unsafe {
105+
let bundle_url = CFBundleCopyResourcesDirectoryURL(self.0);
106+
if bundle_url.is_null() {
107+
None
108+
} else {
109+
Some(TCFType::wrap_under_create_rule(bundle_url))
110+
}
111+
}
112+
}
113+
114+
/// Bundle's resources location
115+
pub fn resources_path(&self) -> Option<PathBuf> {
116+
let url = self.bundle_resources_url()?;
117+
Some(PathBuf::from(url.get_file_system_path(kCFURLPOSIXPathStyle).to_string()))
118+
}
119+
102120
pub fn private_frameworks_url(&self) -> Option<CFURL> {
103121
unsafe {
104122
let fw_url = CFBundleCopyPrivateFrameworksURL(self.0);

0 commit comments

Comments
 (0)