CFBundleCopyResourcesDirectoryURL

This commit is contained in:
Yu Shimura
2020-10-14 11:04:07 +09:00
parent d2ff40289a
commit 437be24cdb
2 changed files with 19 additions and 0 deletions
+1
View File
@@ -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;
}
+18
View File
@@ -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<CFURL> {
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<PathBuf> {
let url = self.bundle_resources_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);