当前位置: 首页>>代码示例>>C++>>正文


C++ CFBundleCopyExecutableURL函数代码示例

本文整理汇总了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");
}
开发者ID:unofficial-opensource-apple,项目名称:Security,代码行数:26,代码来源:codesign.c

示例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;
  }
开发者ID:glindsey,项目名称:MetaHack,代码行数:35,代码来源:Paths.cpp

示例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;
}
开发者ID:parkera,项目名称:swift-corelibs-foundation,代码行数:26,代码来源:CFBundle_Binary.c

示例4: cfStringRelease

string Bundle::executablePath() const
{
	if (mExecutablePath.empty())
		return mExecutablePath = cfStringRelease(CFBundleCopyExecutableURL(cfBundle()));
	else
		return mExecutablePath;
}
开发者ID:Proteas,项目名称:codesign,代码行数:7,代码来源:osxcode.cpp

示例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;
}
开发者ID:parkera,项目名称:swift-corelibs-foundation,代码行数:26,代码来源:CFBundle_Binary.c

示例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);
}
开发者ID:ZeusFramework,项目名称:ZeusbaseUIKit,代码行数:29,代码来源:check_executable_architecture.c

示例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;
}
开发者ID:czbming,项目名称:libRocket,代码行数:27,代码来源:ShellMacOSX.cpp

示例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;
}
开发者ID:CueMol,项目名称:cuemol2,代码行数:28,代码来源:osx_stub.cpp

示例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;
}
开发者ID:parkera,项目名称:swift-corelibs-foundation,代码行数:29,代码来源:CFBundle_Binary.c

示例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;
}
开发者ID:lofter2011,项目名称:Icefox,代码行数:38,代码来源:nsUpdateDriver.cpp

示例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);
}	
开发者ID:grifotv,项目名称:blackbox,代码行数:25,代码来源:BlackBoxApp.cpp

示例12: get

CFURLRef
CFCBundle::CopyExecutableURL () const
{
    CFBundleRef bundle = get();
    if (bundle != NULL)
        return CFBundleCopyExecutableURL(bundle);
    return NULL;
}
开发者ID:32bitmicro,项目名称:riscv-lldb,代码行数:8,代码来源:CFCBundle.cpp

示例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()));
}
开发者ID:SchleunigerAG,项目名称:WinEC7_Qt5.3.1_Fixes,代码行数:9,代码来源:TestControllerWin.cpp

示例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;
}
开发者ID:parkera,项目名称:swift-corelibs-foundation,代码行数:56,代码来源:CFBundle_Binary.c

示例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;
}
开发者ID:amyvmiwei,项目名称:firefox,代码行数:54,代码来源:nsPluginsDirDarwin.cpp


注:本文中的CFBundleCopyExecutableURL函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。