From 6ded5c360fcfa56fe0848a256302ed943e606f2d Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 8 May 2020 11:36:40 +0100 Subject: [PATCH] CFBundleCopyBundleURL --- core-foundation-sys/src/bundle.rs | 1 + core-foundation/src/bundle.rs | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core-foundation-sys/src/bundle.rs b/core-foundation-sys/src/bundle.rs index b4045d0..45c6429 100644 --- a/core-foundation-sys/src/bundle.rs +++ b/core-foundation-sys/src/bundle.rs @@ -34,4 +34,5 @@ extern { pub fn CFBundleCopyExecutableURL(bundle: CFBundleRef) -> CFURLRef; pub fn CFBundleCopyPrivateFrameworksURL(bundle: CFBundleRef) -> CFURLRef; pub fn CFBundleCopySharedSupportURL(bundle: CFBundleRef) -> CFURLRef; + pub fn CFBundleCopyBundleURL(bundle: CFBundleRef) -> CFURLRef; } diff --git a/core-foundation/src/bundle.rs b/core-foundation/src/bundle.rs index 7d051ff..e79e3c3 100644 --- a/core-foundation/src/bundle.rs +++ b/core-foundation/src/bundle.rs @@ -9,8 +9,10 @@ //! Core Foundation Bundle Type -pub use core_foundation_sys::bundle::*; use core_foundation_sys::base::kCFAllocatorDefault; +pub use core_foundation_sys::bundle::*; +use core_foundation_sys::url::kCFURLPOSIXPathStyle; +use std::path::PathBuf; use base::{CFType, TCFType}; use url::CFURL; @@ -79,6 +81,24 @@ impl CFBundle { } } + /// Bundle's own location + pub fn bundle_url(&self) -> Option { + unsafe { + let bundle_url = CFBundleCopyBundleURL(self.0); + if bundle_url.is_null() { + None + } else { + Some(TCFType::wrap_under_create_rule(bundle_url)) + } + } + } + + /// Bundle's own location + pub fn path(&self) -> Option { + let url = self.bundle_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);