LLDB mainline
CFCBundle.cpp
Go to the documentation of this file.
1//===-- CFCBundle.cpp -----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "CFCBundle.h"
10#include "CFCString.h"
11
12// CFCBundle constructor
14 if (path && path[0])
15 SetPath(path);
16}
17
19 : CFCReleaser<CFBundleRef>(url ? CFBundleCreate(NULL, url) : NULL) {}
20
21// Destructor
22CFCBundle::~CFCBundle() = default;
23
24// Set the path for a bundle by supplying a
25bool CFCBundle::SetPath(const char *path) {
26 CFAllocatorRef alloc = kCFAllocatorDefault;
27 // Release our old bundle and URL
28 reset();
29
30 // Make a CFStringRef from the supplied path
31 CFCString cf_path;
32 cf_path.SetFileSystemRepresentation(path);
33 if (cf_path.get()) {
34 // Make our Bundle URL
35 CFCReleaser<CFURLRef> bundle_url(::CFURLCreateWithFileSystemPath(
36 alloc, cf_path.get(), kCFURLPOSIXPathStyle, true));
37 if (bundle_url.get())
38 reset(::CFBundleCreate(alloc, bundle_url.get()));
39 }
40 return get() != NULL;
41}
42
43bool CFCBundle::GetPath(char *dst, size_t dst_len) {
44 CFBundleRef bundle = get();
45 if (bundle) {
46 CFCReleaser<CFURLRef> bundle_url(CFBundleCopyBundleURL(bundle));
47 if (bundle_url.get()) {
48 Boolean resolveAgainstBase = 0;
49 return ::CFURLGetFileSystemRepresentation(bundle_url.get(),
50 resolveAgainstBase,
51 (UInt8 *)dst, dst_len) != 0;
52 }
53 }
54 return false;
55}
56
58 CFBundleRef bundle = get();
59 if (bundle != NULL)
60 return ::CFBundleGetIdentifier(bundle);
61 return NULL;
62}
63
65 CFBundleRef bundle = get();
66 if (bundle != NULL)
67 return ::CFBundleGetValueForInfoDictionaryKey(bundle, key);
68 return NULL;
69}
70
72 CFBundleRef bundle = get();
73 if (bundle != NULL)
74 return CFBundleCopyExecutableURL(bundle);
75 return NULL;
76}
~CFCBundle() override
CFStringRef GetIdentifier() const
Definition: CFCBundle.cpp:57
bool SetPath(const char *path)
Definition: CFCBundle.cpp:25
CFURLRef CopyExecutableURL() const
Definition: CFCBundle.cpp:71
CFCBundle(const char *path=NULL)
Definition: CFCBundle.cpp:13
CFTypeRef GetValueForInfoDictionaryKey(CFStringRef key) const
Definition: CFCBundle.cpp:64
bool GetPath(char *dst, size_t dst_len)
Definition: CFCBundle.cpp:43
void reset(CFBundleRef ptr=NULL)
Definition: CFCReleaser.h:86
CFStringRef SetFileSystemRepresentation(const char *path)
Definition: CFCString.cpp:41