1 //===-- CFCBundle.cpp -------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "CFCBundle.h" 11 #include "CFCString.h" 12 13 //---------------------------------------------------------------------- 14 // CFCBundle constructor 15 //---------------------------------------------------------------------- 16 CFCBundle::CFCBundle(const char *path) : 17 CFCReleaser<CFBundleRef>() 18 { 19 if (path && path[0]) 20 SetPath(path); 21 } 22 23 CFCBundle::CFCBundle(CFURLRef url) : 24 CFCReleaser<CFBundleRef>(url ? CFBundleCreate(NULL, url) : NULL) 25 { 26 } 27 28 //---------------------------------------------------------------------- 29 // Destructor 30 //---------------------------------------------------------------------- 31 CFCBundle::~CFCBundle() 32 { 33 } 34 35 //---------------------------------------------------------------------- 36 // Set the path for a bundle by supplying a 37 //---------------------------------------------------------------------- 38 bool 39 CFCBundle::SetPath (const char *path) 40 { 41 CFAllocatorRef alloc = kCFAllocatorDefault; 42 // Release our old bundle and URL 43 reset(); 44 45 // Make a CFStringRef from the supplied path 46 CFCString cf_path; 47 cf_path.SetFileSystemRepresentation(path); 48 if (cf_path.get()) 49 { 50 // Make our Bundle URL 51 CFCReleaser<CFURLRef> bundle_url (::CFURLCreateWithFileSystemPath (alloc, cf_path.get(), kCFURLPOSIXPathStyle, true)); 52 if (bundle_url.get()) 53 reset (::CFBundleCreate (alloc, bundle_url.get())); 54 } 55 return get() != NULL; 56 } 57 58 CFStringRef 59 CFCBundle::GetIdentifier () const 60 { 61 CFBundleRef bundle = get(); 62 if (bundle != NULL) 63 return ::CFBundleGetIdentifier (bundle); 64 return NULL; 65 } 66 67 CFTypeRef 68 CFCBundle::GetValueForInfoDictionaryKey(CFStringRef key) const 69 { 70 CFBundleRef bundle = get(); 71 if (bundle != NULL) 72 return ::CFBundleGetValueForInfoDictionaryKey(bundle, key); 73 return NULL; 74 } 75 76 CFURLRef 77 CFCBundle::CopyExecutableURL () const 78 { 79 CFBundleRef bundle = get(); 80 if (bundle != NULL) 81 return CFBundleCopyExecutableURL(bundle); 82 return NULL; 83 } 84