Merge pull request #376 from kornelski/bundleurl

CFBundleCopyBundleURL
This commit is contained in:
Jeff Muizelaar
2020-05-08 08:32:17 -04:00
committed by GitHub
2 changed files with 22 additions and 1 deletions
+1
View File
@@ -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;
}
+21 -1
View File
@@ -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<CFURL> {
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<PathBuf> {
let url = self.bundle_url()?;
Some(PathBuf::from(url.get_file_system_path(kCFURLPOSIXPathStyle).to_string()))
}
pub fn private_frameworks_url(&self) -> Option<CFURL> {
unsafe {
let fw_url = CFBundleCopyPrivateFrameworksURL(self.0);