本文整理匯總了C++中CFBundleCopyExecutableURL函數的典型用法代碼示例。如果您正苦於以下問題:C++ CFBundleCopyExecutableURL函數的具體用法?C++ CFBundleCopyExecutableURL怎麽用?C++ CFBundleCopyExecutableURL使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CFBundleCopyExecutableURL函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: open_bundle
static FILE *
open_bundle(const char * path, const char * mode)
{
char full_path[1024] = {};
CFStringRef path_cfstring = NULL;
CFURLRef path_url = NULL;
CFBundleRef bundle = NULL;
CFURLRef exec = NULL;
path_cfstring = CFStringCreateWithFileSystemRepresentation(kCFAllocatorDefault, path);
require_quiet(path_cfstring, out);
path_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path_cfstring, kCFURLPOSIXPathStyle, true);
require_quiet(path_url, out);
bundle = CFBundleCreate(kCFAllocatorDefault, path_url);
require_quiet(bundle, out);
exec = CFBundleCopyExecutableURL(bundle);
require(exec, out);
require(CFURLGetFileSystemRepresentation(exec, true, (uint8_t*)full_path, sizeof(full_path)), out);
out:
CFReleaseSafe(path_cfstring);
CFReleaseSafe(path_url);
CFReleaseSafe(bundle);
CFReleaseSafe(exec);
return fopen(full_path, "r");
}
示例2: CFBundleGetMainBundle
Paths::Paths()
{
std::string workingDirectory { "." /* boost::filesystem::current_path().string() */ };
std::string logDirectory { workingDirectory + "/log" };
std::string resourcesDirectory { workingDirectory + "/resources" };
// If in MacOS, we get these in a somewhat different manner, because Apple has to be different.
// (See https://stackoverflow.com/questions/516200/relative-paths-not-working-in-xcode-c?rq=1 for details)
#ifdef __APPLE__
CFBundleRef mainBundle = CFBundleGetMainBundle();
char path[PATH_MAX];
CFURLRef executableURL = CFBundleCopyExecutableURL(mainBundle);
if (!CFURLGetFileSystemRepresentation(executableURL, TRUE, (UInt8 *)path, PATH_MAX))
{
LOG(FATAL) << "Could not obtain resources directory name from CoreFoundation!";
}
logDirectory = std::string(path) + "/log";
CFRelease(executableURL);
CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
{
LOG(FATAL) << "Could not obtain resources directory name from CoreFoundation!";
}
resourcesDirectory = std::string(path);
CFRelease(resourcesURL);
#endif
std::cout << "Log directory is " << logDirectory << std::endl;
std::cout << "Resources directory is " << resourcesDirectory << std::endl;
m_logsPath = logDirectory;
m_resourcesPath = resourcesDirectory;
}
示例3: _CFBundleDlfcnCheckLoaded
CF_PRIVATE Boolean _CFBundleDlfcnCheckLoaded(CFBundleRef bundle) {
if (!bundle->_isLoaded) {
CFURLRef executableURL = CFBundleCopyExecutableURL(bundle);
char buff[CFMaxPathSize];
if (executableURL && CFURLGetFileSystemRepresentation(executableURL, true, (uint8_t *)buff, CFMaxPathSize)) {
int mode = RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD | RTLD_FIRST;
void *handle = dlopen(buff, mode);
if (handle) {
if (!bundle->_handleCookie) {
bundle->_handleCookie = handle;
#if LOG_BUNDLE_LOAD
printf("dlfcn check load bundle %p, dlopen of %s mode 0x%x getting handle %p\n", bundle, buff, mode, bundle->_handleCookie);
#endif /* LOG_BUNDLE_LOAD */
}
bundle->_isLoaded = true;
} else {
#if LOG_BUNDLE_LOAD
printf("dlfcn check load bundle %p, dlopen of %s mode 0x%x no handle\n", bundle, buff, mode);
#endif /* LOG_BUNDLE_LOAD */
}
}
if (executableURL) CFRelease(executableURL);
}
return bundle->_isLoaded;
}
示例4: cfStringRelease
string Bundle::executablePath() const
{
if (mExecutablePath.empty())
return mExecutablePath = cfStringRelease(CFBundleCopyExecutableURL(cfBundle()));
else
return mExecutablePath;
}
示例5: _CFBundleDYLDCheckLoaded
CF_PRIVATE Boolean _CFBundleDYLDCheckLoaded(CFBundleRef bundle) {
if (!bundle->_isLoaded) {
CFURLRef executableURL = CFBundleCopyExecutableURL(bundle);
char buff[CFMaxPathSize];
if (executableURL && CFURLGetFileSystemRepresentation(executableURL, true, (uint8_t *)buff, CFMaxPathSize)) {
const void *header = __CFBundleDYLDFindImage(buff);
if (header) {
if (bundle->_binaryType == __CFBundleUnknownBinary) bundle->_binaryType = __CFBundleDYLDFrameworkBinary;
if (!bundle->_imageCookie) {
bundle->_imageCookie = header;
#if LOG_BUNDLE_LOAD
printf("dyld check load bundle %p, find %s getting image %p\n", bundle, buff, bundle->_imageCookie);
#endif /* LOG_BUNDLE_LOAD */
}
bundle->_isLoaded = true;
} else {
#if LOG_BUNDLE_LOAD
printf("dyld check load bundle %p, find %s no image\n", bundle, buff);
#endif /* LOG_BUNDLE_LOAD */
}
}
if (executableURL) CFRelease(executableURL);
}
return bundle->_isLoaded;
}
示例6: examine_bundle
/* Examines a directory, treating it as a bundle, and determines whether it has an executable.
* Examines the executable as a regular file to determine which architectures it matches.
* Prints out the results.
*/
static void examine_bundle(const uint8_t *bundle_path) {
CFURLRef bundleURL = CFURLCreateFromFileSystemRepresentation(NULL, bundle_path, strlen((const char *)bundle_path), true), executableURL = NULL;
CFBundleRef bundle = NULL;
uint8_t path[PATH_MAX];
struct stat statBuf;
if (bundleURL && (bundle = CFBundleCreate(NULL, bundleURL))) {
// Try to obtain a path to an executable within the bundle.
executableURL = CFBundleCopyExecutableURL(bundle);
if (executableURL && CFURLGetFileSystemRepresentation(executableURL, true, path, PATH_MAX) && stat((const char *)path, &statBuf) == 0) {
// Make sure it is a regular file, and if so examine it as a regular file.
if ((statBuf.st_mode & S_IFMT) == S_IFREG) {
examine_file(path);
} else {
printf("Unsupported file type for file %s.\n", path);
}
} else {
printf("No executable located for %s.\n", bundle_path);
}
} else {
printf("Cannot read %s.\n", bundle_path);
}
if (executableURL) CFRelease(executableURL);
if (bundle) CFRelease(bundle);
if (bundleURL) CFRelease(bundleURL);
}
示例7: gettimeofday
bool Shell::Initialise(const Rocket::Core::String& path)
{
gettimeofday(&start_time, NULL);
InputMacOSX::Initialise();
// Find the location of the executable.
CFBundleRef bundle = CFBundleGetMainBundle();
CFURLRef executable_url = CFBundleCopyExecutableURL(bundle);
CFStringRef executable_posix_file_name = CFURLCopyFileSystemPath(executable_url, kCFURLPOSIXPathStyle);
CFIndex max_length = CFStringGetMaximumSizeOfFileSystemRepresentation(executable_posix_file_name);
char* executable_file_name = new char[max_length];
if (!CFStringGetFileSystemRepresentation(executable_posix_file_name, executable_file_name, max_length))
executable_file_name[0] = 0;
executable_path = Rocket::Core::String(executable_file_name);
executable_path = executable_path.Substring(0, executable_path.RFind("/") + 1);
delete[] executable_file_name;
CFRelease(executable_posix_file_name);
CFRelease(executable_url);
file_interface = new ShellFileInterface(executable_path + "../../../" + path);
Rocket::Core::SetFileInterface(file_interface);
return true;
}
示例8: getExePath
bool getExePath(char *respath)
{
CFBundleRef appBundle = CFBundleGetMainBundle();
if (!appBundle)
return false;
CFURLRef url = CFBundleCopyExecutableURL(appBundle);
if (!url)
return false;
CFURLRef absurl = nullptr;
// CFURLRef url2 = url;
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(NULL, url);
CFRelease(url);
absurl = CFURLCopyAbsoluteURL(url2);
CFRelease(url2);
char tbuffer[MAXPATHLEN];
CFURLGetFileSystemRepresentation(absurl, true,
(UInt8*) tbuffer,
sizeof(tbuffer));
printf("abs exec url = %s\n", tbuffer);
CFRelease(absurl);
snprintf(respath, MAXPATHLEN, "%s/XUL", tbuffer);
return true;
}
示例9: _CFBundleDLLLoad
CF_PRIVATE Boolean _CFBundleDLLLoad(CFBundleRef bundle, CFErrorRef *error) {
CFErrorRef localError = NULL;
if (!bundle->_isLoaded) {
CFURLRef executableURL = CFBundleCopyExecutableURL(bundle);
wchar_t buff[CFMaxPathSize];
if (executableURL && _CFURLGetWideFileSystemRepresentation(executableURL, true, (wchar_t *)buff, CFMaxPathSize)) {
bundle->_hModule = LoadLibraryW(buff);
if (bundle->_hModule) {
bundle->_isLoaded = true;
} else {
if (error) {
localError = _CFBundleCreateError(CFGetAllocator(bundle), bundle, CFBundleExecutableLinkError);
} else {
CFLog(__kCFLogBundle, CFSTR("Failed to load bundle %@"), bundle);
}
}
} else {
if (error) {
localError = _CFBundleCreateError(CFGetAllocator(bundle), bundle, CFBundleExecutableNotFoundError);
} else {
CFLog(__kCFLogBundle, CFSTR("Cannot find executable for bundle %@"), bundle);
}
}
if (executableURL) CFRelease(executableURL);
}
if (!bundle->_isLoaded && error) *error = localError;
return bundle->_isLoaded;
}
示例10: GetXULRunnerStubPath
// This is a copy of OS X's XRE_GetBinaryPath from nsAppRunner.cpp with the
// gBinaryPath check removed so that the updater can reload the stub executable
// instead of xulrunner-bin. See bug 349737.
static nsresult
GetXULRunnerStubPath(const char* argv0, nsILocalFile* *aResult)
{
nsresult rv;
nsCOMPtr<nsILocalFile> lf;
NS_NewNativeLocalFile(EmptyCString(), PR_TRUE, getter_AddRefs(lf));
nsCOMPtr<nsILocalFileMac> lfm (do_QueryInterface(lf));
if (!lfm)
return NS_ERROR_FAILURE;
// Works even if we're not bundled.
CFBundleRef appBundle = CFBundleGetMainBundle();
if (!appBundle)
return NS_ERROR_FAILURE;
CFURLRef bundleURL = CFBundleCopyExecutableURL(appBundle);
if (!bundleURL)
return NS_ERROR_FAILURE;
FSRef fileRef;
if (!CFURLGetFSRef(bundleURL, &fileRef)) {
CFRelease(bundleURL);
return NS_ERROR_FAILURE;
}
rv = lfm->InitWithFSRef(&fileRef);
CFRelease(bundleURL);
if (NS_FAILED(rv))
return rv;
NS_ADDREF(*aResult = lf);
return NS_OK;
}
示例11: CFBundleGetMainBundle
void BlackBoxApp::loadImage() {
#ifdef TARGET_OSX
// Get the absolute location of the executable file in the bundle.
CFBundleRef appBundle = CFBundleGetMainBundle();
CFURLRef executableURL = CFBundleCopyExecutableURL(appBundle);
char execFile[4096];
if (CFURLGetFileSystemRepresentation(executableURL, TRUE, (UInt8 *)execFile, 4096)) {
// Strip out the filename to just get the path
string strExecFile = execFile;
int found = strExecFile.find_last_of("/");
string strPath = strExecFile.substr(0, found);
// Change the working directory to that of the executable
if(-1 == chdir(strPath.c_str())) {
ofLog(OF_LOG_ERROR, "Unable to change working directory to executable's directory.");
}
} else {
ofLog(OF_LOG_ERROR, "Unable to identify executable's directory.");
}
CFRelease(executableURL);
#endif
image.loadImage("image.png");
image.setAnchorPercent(0.5, 0.5);
}
示例12: get
CFURLRef
CFCBundle::CopyExecutableURL () const
{
CFBundleRef bundle = get();
if (bundle != NULL)
return CFBundleCopyExecutableURL(bundle);
return NULL;
}
示例13: adoptCF
void TestController::initializeTestPluginDirectory()
{
RetainPtr<CFURLRef> bundleURL = adoptCF(CFBundleCopyExecutableURL(CFBundleGetMainBundle()));
RetainPtr<CFURLRef> bundleDirectoryURL = adoptCF(CFURLCreateCopyDeletingLastPathComponent(0, bundleURL.get()));
RetainPtr<CFStringRef> testPluginDirectoryNameString = adoptCF(CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(testPluginDirectoryName), wcslen(testPluginDirectoryName)));
RetainPtr<CFURLRef> testPluginDirectoryURL = adoptCF(CFURLCreateCopyAppendingPathComponent(0, bundleDirectoryURL.get(), testPluginDirectoryNameString.get(), true));
RetainPtr<CFStringRef> testPluginDirectoryPath = adoptCF(CFURLCopyFileSystemPath(testPluginDirectoryURL.get(), kCFURLWindowsPathStyle));
m_testPluginDirectory.adopt(WKStringCreateWithCFString(testPluginDirectoryPath.get()));
}
示例14: _CFBundleDlfcnPreflight
CF_EXPORT Boolean _CFBundleDlfcnPreflight(CFBundleRef bundle, CFErrorRef *error) {
Boolean retval = true;
CFErrorRef localError = NULL;
if (!bundle->_isLoaded) {
CFURLRef executableURL = CFBundleCopyExecutableURL(bundle);
char buff[CFMaxPathSize];
retval = false;
if (executableURL && CFURLGetFileSystemRepresentation(executableURL, true, (uint8_t *)buff, CFMaxPathSize)) {
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
retval = dlopen_preflight(buff);
#endif
if (!retval && error) {
CFArrayRef archs = CFBundleCopyExecutableArchitectures(bundle);
CFStringRef debugString = NULL;
const char *errorString = dlerror();
if (errorString && strlen(errorString) > 0) debugString = CFStringCreateWithFileSystemRepresentation(kCFAllocatorSystemDefault, errorString);
if (archs) {
Boolean hasSuitableArch = false, hasRuntimeMismatch = false;
CFIndex i, count = CFArrayGetCount(archs);
SInt32 arch, curArch = _CFBundleCurrentArchitecture();
for (i = 0; !hasSuitableArch && i < count; i++) {
if (CFNumberGetValue((CFNumberRef)CFArrayGetValueAtIndex(archs, i), kCFNumberSInt32Type, (void *)&arch) && arch == curArch) hasSuitableArch = true;
}
#if defined(BINARY_SUPPORT_DYLD)
if (hasSuitableArch) {
uint32_t mainFlags = 0;
if (_CFBundleGrokObjCImageInfoFromMainExecutable(NULL, &mainFlags) && (mainFlags & 0x2) != 0) {
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED
uint32_t bundleFlags = 0;
if (_CFBundleGetObjCImageInfo(bundle, NULL, &bundleFlags) && (bundleFlags & 0x2) == 0) hasRuntimeMismatch = true;
#endif
}
}
#endif /* BINARY_SUPPORT_DYLD */
if (hasRuntimeMismatch) {
localError = _CFBundleCreateErrorDebug(CFGetAllocator(bundle), bundle, CFBundleExecutableRuntimeMismatchError, debugString);
} else if (!hasSuitableArch) {
localError = _CFBundleCreateErrorDebug(CFGetAllocator(bundle), bundle, CFBundleExecutableArchitectureMismatchError, debugString);
} else {
localError = _CFBundleCreateErrorDebug(CFGetAllocator(bundle), bundle, CFBundleExecutableLoadError, debugString);
}
CFRelease(archs);
} else {
localError = _CFBundleCreateErrorDebug(CFGetAllocator(bundle), bundle, CFBundleExecutableLoadError, debugString);
}
if (debugString) CFRelease(debugString);
}
} else {
if (error) localError = _CFBundleCreateError(CFGetAllocator(bundle), bundle, CFBundleExecutableNotFoundError);
}
if (executableURL) CFRelease(executableURL);
}
if (!retval && error) *error = localError;
return retval;
}
示例15: NS_WARNING
PRBool nsPluginsDir::IsPluginFile(nsIFile* file)
{
nsCString temp;
file->GetNativeLeafName(temp);
/*
* Don't load the VDP fake plugin, to avoid tripping a bad bug in OS X
* 10.5.3 (see bug 436575).
*/
if (!strcmp(temp.get(), "VerifiedDownloadPlugin.plugin")) {
NS_WARNING("Preventing load of VerifiedDownloadPlugin.plugin (see bug 436575)");
return PR_FALSE;
}
// If we're running on OS X Lion (10.7) or later, don't load the Java Embedding
// Plugin (any version). If/when Steven Michaud releases a version of the JEP that
// works on Lion, we'll need to revise this code. See bug 670655.
if (OnLionOrLater() && !strcmp(temp.get(), "MRJPlugin.plugin")) {
NS_WARNING("Preventing load of Java Embedding Plugin (MRJPlugin.plugin) on OS X Lion (see bug 670655)");
return PR_FALSE;
}
CFURLRef pluginURL = NULL;
if (NS_FAILED(toCFURLRef(file, pluginURL)))
return PR_FALSE;
PRBool isPluginFile = PR_FALSE;
CFBundleRef pluginBundle = CFBundleCreate(kCFAllocatorDefault, pluginURL);
if (pluginBundle) {
UInt32 packageType, packageCreator;
CFBundleGetPackageInfo(pluginBundle, &packageType, &packageCreator);
if (packageType == 'BRPL' || packageType == 'IEPL' || packageType == 'NSPL') {
CFURLRef executableURL = CFBundleCopyExecutableURL(pluginBundle);
if (executableURL) {
isPluginFile = IsLoadablePlugin(executableURL);
::CFRelease(executableURL);
}
}
::CFRelease(pluginBundle);
}
else {
LSItemInfoRecord info;
if (LSCopyItemInfoForURL(pluginURL, kLSRequestTypeCreator, &info) == noErr) {
if ((info.filetype == 'shlb' && info.creator == 'MOSS') ||
info.filetype == 'NSPL' ||
info.filetype == 'BRPL' ||
info.filetype == 'IEPL') {
isPluginFile = IsLoadablePlugin(pluginURL);
}
}
}
::CFRelease(pluginURL);
return isPluginFile;
}