From 437be24cdb5243ef3f03909ba58b0ee09bfaa198 Mon Sep 17 00:00:00 2001 From: Yu Shimura Date: Wed, 14 Oct 2020 11:04:07 +0900 Subject: [PATCH] CFBundleCopyResourcesDirectoryURL --- core-foundation-sys/src/bundle.rs | 1 + core-foundation/src/bundle.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/core-foundation-sys/src/bundle.rs b/core-foundation-sys/src/bundle.rs index 45c6429..29f8e12 100644 --- a/core-foundation-sys/src/bundle.rs +++ b/core-foundation-sys/src/bundle.rs @@ -35,4 +35,5 @@ extern { pub fn CFBundleCopyPrivateFrameworksURL(bundle: CFBundleRef) -> CFURLRef; pub fn CFBundleCopySharedSupportURL(bundle: CFBundleRef) -> CFURLRef; pub fn CFBundleCopyBundleURL(bundle: CFBundleRef) -> CFURLRef; + pub fn CFBundleCopyResourcesDirectoryURL(bundle: CFBundleRef) -> CFURLRef; } diff --git a/core-foundation/src/bundle.rs b/core-foundation/src/bundle.rs index e79e3c3..b9ab1f6 100644 --- a/core-foundation/src/bundle.rs +++ b/core-foundation/src/bundle.rs @@ -99,6 +99,24 @@ impl CFBundle { Some(PathBuf::from(url.get_file_system_path(kCFURLPOSIXPathStyle).to_string())) } + /// Bundle's resources location + pub fn bundle_resources_url(&self) -> Option { + unsafe { + let bundle_url = CFBundleCopyResourcesDirectoryURL(self.0); + if bundle_url.is_null() { + None + } else { + Some(TCFType::wrap_under_create_rule(bundle_url)) + } + } + } + + /// Bundle's resources location + pub fn resources_path(&self) -> Option { + let url = self.bundle_resources_url()?; + Some(PathBuf::from(url.get_file_system_path(kCFURLPOSIXPathStyle).to_string())) + } + pub fn private_frameworks_url(&self) -> Option { unsafe { let fw_url = CFBundleCopyPrivateFrameworksURL(self.0);