Home | History | Annotate | Download | only in MacOSX
      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 //----------------------------------------------------------------------
     20 CFBundle::CFBundle(const char *path) :
     21     CFReleaser<CFBundleRef>(),
     22     m_bundle_url()
     23 {
     24     if (path && path[0])
     25         SetPath(path);
     26 }
     27 
     28 //----------------------------------------------------------------------
     29 // CFBundle copy constructor
     30 //----------------------------------------------------------------------
     31 CFBundle::CFBundle(const CFBundle& rhs) :
     32     CFReleaser<CFBundleRef>(rhs),
     33     m_bundle_url(rhs.m_bundle_url)
     34 {
     35 
     36 }
     37 
     38 //----------------------------------------------------------------------
     39 // CFBundle copy constructor
     40 //----------------------------------------------------------------------
     41 CFBundle&
     42 CFBundle::operator=(const CFBundle& rhs)
     43 {
     44     *this = rhs;
     45     return *this;
     46 }
     47 
     48 //----------------------------------------------------------------------
     49 // Destructor
     50 //----------------------------------------------------------------------
     51 CFBundle::~CFBundle()
     52 {
     53 }
     54 
     55 //----------------------------------------------------------------------
     56 // Set the path for a bundle by supplying a
     57 //----------------------------------------------------------------------
     58 bool
     59 CFBundle::SetPath (const char *path)
     60 {
     61     CFAllocatorRef alloc = kCFAllocatorDefault;
     62     // Release our old bundle and ULR
     63     reset();    // This class is a CFReleaser<CFBundleRef>
     64     m_bundle_url.reset();
     65     // Make a CFStringRef from the supplied path
     66     CFString cf_path;
     67     cf_path.SetFileSystemRepresentation(path);
     68     if (cf_path.get())
     69     {
     70         // Make our Bundle URL
     71         m_bundle_url.reset (::CFURLCreateWithFileSystemPath (alloc, cf_path.get(), kCFURLPOSIXPathStyle, true));
     72         if (m_bundle_url.get())
     73         {
     74             reset (::CFBundleCreate (alloc, m_bundle_url.get()));
     75         }
     76     }
     77     return get() != NULL;
     78 }
     79 
     80 CFStringRef
     81 CFBundle::GetIdentifier () const
     82 {
     83     CFBundleRef bundle = get();
     84     if (bundle != NULL)
     85         return ::CFBundleGetIdentifier (bundle);
     86     return NULL;
     87 }
     88 
     89 
     90 CFURLRef
     91 CFBundle::CopyExecutableURL () const
     92 {
     93     CFBundleRef bundle = get();
     94     if (bundle != NULL)
     95         return CFBundleCopyExecutableURL(bundle);
     96     return NULL;
     97 }
     98