diff --git a/core-foundation-sys/src/url.rs b/core-foundation-sys/src/url.rs index a9049f8..3081ec2 100644 --- a/core-foundation-sys/src/url.rs +++ b/core-foundation-sys/src/url.rs @@ -88,12 +88,12 @@ extern { //fn CFURLCreateCopyAppendingPathExtension //fn CFURLCreateCopyDeletingLastPathComponent //fn CFURLCreateCopyDeletingPathExtension - pub fn CFURLCreateFilePathURL(allocator: CFAllocatorRef, url: CFURLRef, error: *mut CFErrorRef); + pub fn CFURLCreateFilePathURL(allocator: CFAllocatorRef, url: CFURLRef, error: *mut CFErrorRef) -> CFURLRef; //fn CFURLCreateFileReferenceURL pub fn CFURLCreateFromFileSystemRepresentation(allocator: CFAllocatorRef, buffer: *const u8, bufLen: CFIndex, isDirectory: Boolean) -> CFURLRef; //fn CFURLCreateFromFileSystemRepresentationRelativeToBase //fn CFURLCreateFromFSRef - pub fn CFURLCreateWithBytes(allocator: CFAllocatorRef, URLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef); + pub fn CFURLCreateWithBytes(allocator: CFAllocatorRef, URLBytes: *const u8, length: CFIndex, encoding: CFStringEncoding, baseURL: CFURLRef) -> CFURLRef; pub fn CFURLCreateWithFileSystemPath(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean) -> CFURLRef; pub fn CFURLCreateWithFileSystemPathRelativeToBase(allocator: CFAllocatorRef, filePath: CFStringRef, pathStyle: CFURLPathStyle, isDirectory: Boolean, baseURL: CFURLRef) -> CFURLRef; //fn CFURLCreateWithString(allocator: CFAllocatorRef, urlString: CFStringRef, @@ -143,7 +143,7 @@ extern { //fn CFURLCreateResourcePropertiesForKeysFromBookmarkData //fn CFURLCreateResourcePropertyForKeyFromBookmarkData //fn CFURLSetResourcePropertiesForKeys - pub fn CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef); + pub fn CFURLSetResourcePropertyForKey(url: CFURLRef, key: CFStringRef, value: CFTypeRef, error: *mut CFErrorRef) -> Boolean; //fn CFURLSetTemporaryResourcePropertyForKey /* Working with Bookmark Data */ diff --git a/core-foundation/src/url.rs b/core-foundation/src/url.rs index c3aad09..34c53b7 100644 --- a/core-foundation/src/url.rs +++ b/core-foundation/src/url.rs @@ -11,11 +11,13 @@ pub use core_foundation_sys::url::*; -use base::{TCFType}; +use base::{TCFType, CFIndex}; use string::{CFString}; use core_foundation_sys::base::{kCFAllocatorDefault, CFRelease}; use std::fmt; +use std::ptr; +use std::path::Path; pub struct CFURL(CFURLRef); @@ -40,6 +42,21 @@ impl fmt::Debug for CFURL { } impl CFURL { + pub fn from_path>(path: P, isDirectory: bool) -> Option { + let path = match path.as_ref().to_str() { + Some(path) => path, + None => return None, + }; + + unsafe { + let url_ref = CFURLCreateFromFileSystemRepresentation(ptr::null_mut(), path.as_ptr(), path.len() as CFIndex, isDirectory as u8); + if url_ref.is_null() { + return None; + } + Some(TCFType::wrap_under_create_rule(url_ref)) + } + } + pub fn from_file_system_path(filePath: CFString, pathStyle: CFURLPathStyle, isDirectory: bool) -> CFURL { unsafe { let url_ref = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, filePath.as_concrete_TypeRef(), pathStyle, isDirectory as u8);