#include "CFBundle.h"
#include "CFString.h"
CFBundle::CFBundle(const char *path)
: CFReleaser<CFBundleRef>(), m_bundle_url() {
if (path && path[0])
SetPath(path);
}
CFBundle::CFBundle(const CFBundle &rhs) = default;
CFBundle &CFBundle::operator=(const CFBundle &rhs) {
if (this != &rhs)
*this = rhs;
return *this;
}
CFBundle::~CFBundle() = default;
bool CFBundle::SetPath(const char *path) {
CFAllocatorRef alloc = kCFAllocatorDefault;
reset();
m_bundle_url.reset();
CFString cf_path;
cf_path.SetFileSystemRepresentation(path);
if (cf_path.get()) {
m_bundle_url.reset(::CFURLCreateWithFileSystemPath(
alloc, cf_path.get(), kCFURLPOSIXPathStyle, true));
if (m_bundle_url.get()) {
reset(::CFBundleCreate(alloc, m_bundle_url.get()));
}
}
return get() != NULL;
}
CFStringRef CFBundle::GetIdentifier() const {
CFBundleRef bundle = get();
if (bundle != NULL)
return ::CFBundleGetIdentifier(bundle);
return NULL;
}
CFURLRef CFBundle::CopyExecutableURL() const {
CFBundleRef bundle = get();
if (bundle != NULL)
return CFBundleCopyExecutableURL(bundle);
return NULL;
}