CFBundle.cpp revision 341825
1//===-- CFBundle.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// Created by Greg Clayton on 1/16/08. 11// 12//===----------------------------------------------------------------------===// 13 14#include "CFBundle.h" 15#include "CFString.h" 16 17//---------------------------------------------------------------------- 18// CFBundle constructor 19//---------------------------------------------------------------------- 20CFBundle::CFBundle(const char *path) 21 : CFReleaser<CFBundleRef>(), m_bundle_url() { 22 if (path && path[0]) 23 SetPath(path); 24} 25 26//---------------------------------------------------------------------- 27// CFBundle copy constructor 28//---------------------------------------------------------------------- 29CFBundle::CFBundle(const CFBundle &rhs) 30 : CFReleaser<CFBundleRef>(rhs), m_bundle_url(rhs.m_bundle_url) {} 31 32//---------------------------------------------------------------------- 33// CFBundle copy constructor 34//---------------------------------------------------------------------- 35CFBundle &CFBundle::operator=(const CFBundle &rhs) { 36 *this = rhs; 37 return *this; 38} 39 40//---------------------------------------------------------------------- 41// Destructor 42//---------------------------------------------------------------------- 43CFBundle::~CFBundle() {} 44 45//---------------------------------------------------------------------- 46// Set the path for a bundle by supplying a 47//---------------------------------------------------------------------- 48bool CFBundle::SetPath(const char *path) { 49 CFAllocatorRef alloc = kCFAllocatorDefault; 50 // Release our old bundle and ULR 51 reset(); // This class is a CFReleaser<CFBundleRef> 52 m_bundle_url.reset(); 53 // Make a CFStringRef from the supplied path 54 CFString cf_path; 55 cf_path.SetFileSystemRepresentation(path); 56 if (cf_path.get()) { 57 // Make our Bundle URL 58 m_bundle_url.reset(::CFURLCreateWithFileSystemPath( 59 alloc, cf_path.get(), kCFURLPOSIXPathStyle, true)); 60 if (m_bundle_url.get()) { 61 reset(::CFBundleCreate(alloc, m_bundle_url.get())); 62 } 63 } 64 return get() != NULL; 65} 66 67CFStringRef CFBundle::GetIdentifier() const { 68 CFBundleRef bundle = get(); 69 if (bundle != NULL) 70 return ::CFBundleGetIdentifier(bundle); 71 return NULL; 72} 73 74CFURLRef CFBundle::CopyExecutableURL() const { 75 CFBundleRef bundle = get(); 76 if (bundle != NULL) 77 return CFBundleCopyExecutableURL(bundle); 78 return NULL; 79} 80