From 82f7421c137a7a755529f9018c57bdf92cfe6c26 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 16 May 2016 10:11:19 -0700 Subject: [PATCH 1/2] Add bindings for `CFBundleGetMainBundle()` and `CFBundleGetInfoDictionary()`. --- core-foundation-sys/src/bundle.rs | 3 +++ core-foundation/src/bundle.rs | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/core-foundation-sys/src/bundle.rs b/core-foundation-sys/src/bundle.rs index 7dead25..51746a6 100644 --- a/core-foundation-sys/src/bundle.rs +++ b/core-foundation-sys/src/bundle.rs @@ -10,6 +10,7 @@ use libc::c_void; use base::CFTypeID; +use dictionary::CFDictionaryRef; use string::CFStringRef; #[repr(C)] @@ -23,6 +24,8 @@ extern { */ pub fn CFBundleGetBundleWithIdentifier(bundleID: CFStringRef) -> CFBundleRef; pub fn CFBundleGetFunctionPointerForName(bundle: CFBundleRef, function_name: CFStringRef) -> *const c_void; + pub fn CFBundleGetMainBundle() -> CFBundleRef; + pub fn CFBundleGetInfoDictionary(bundle: CFBundleRef) -> CFDictionaryRef; pub fn CFBundleGetTypeID() -> CFTypeID; } diff --git a/core-foundation/src/bundle.rs b/core-foundation/src/bundle.rs index 7b32635..8344225 100644 --- a/core-foundation/src/bundle.rs +++ b/core-foundation/src/bundle.rs @@ -13,6 +13,7 @@ pub use core_foundation_sys::bundle::*; use core_foundation_sys::base::CFRelease; use base::{TCFType}; +use dictionary::CFDictionary; /// A Bundle type. pub struct CFBundle(CFBundleRef); @@ -25,4 +26,21 @@ impl Drop for CFBundle { } } +impl CFBundle { + pub fn main_bundle() -> CFBundle { + unsafe { + let bundle_ref = CFBundleGetMainBundle(); + TCFType::wrap_under_get_rule(bundle_ref) + } + } + + pub fn info_dictionary(&self) -> CFDictionary { + unsafe { + let info_dictionary = CFBundleGetInfoDictionary(self.0); + TCFType::wrap_under_get_rule(info_dictionary) + } + } +} + impl_TCFType!(CFBundle, CFBundleRef, CFBundleGetTypeID); + From 3e5f2a5efe42a1dc8d199b6807e6ba6615d73cfe Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 16 May 2016 10:12:00 -0700 Subject: [PATCH 2/2] Add bindings for `CFDictionarySetValue()`. --- core-foundation-sys/src/dictionary.rs | 3 +++ core-foundation/src/dictionary.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/core-foundation-sys/src/dictionary.rs b/core-foundation-sys/src/dictionary.rs index d7631b5..e1d159a 100644 --- a/core-foundation-sys/src/dictionary.rs +++ b/core-foundation-sys/src/dictionary.rs @@ -63,4 +63,7 @@ extern { pub fn CFDictionaryGetTypeID() -> CFTypeID; pub fn CFDictionaryGetValueIfPresent(theDict: CFDictionaryRef, key: *const c_void, value: *mut *const c_void) -> Boolean; + pub fn CFDictionarySetValue(theDict: CFDictionaryRef, + key: *const c_void, + value: *const c_void); } diff --git a/core-foundation/src/dictionary.rs b/core-foundation/src/dictionary.rs index 9540fba..e27ed4a 100644 --- a/core-foundation/src/dictionary.rs +++ b/core-foundation/src/dictionary.rs @@ -96,4 +96,9 @@ impl CFDictionary { let value: CFTypeRef = mem::transmute(self.get(key)); TCFType::wrap_under_get_rule(value) } + + #[inline] + pub unsafe fn set_value(&self, key: *const c_void, value: *const c_void) { + CFDictionarySetValue(self.0, key, value) + } }