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


C++ CFBundleCopyResourcesDirectoryURL函数代码示例

本文整理汇总了C++中CFBundleCopyResourcesDirectoryURL函数的典型用法代码示例。如果您正苦于以下问题:C++ CFBundleCopyResourcesDirectoryURL函数的具体用法?C++ CFBundleCopyResourcesDirectoryURL怎么用?C++ CFBundleCopyResourcesDirectoryURL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CFBundleCopyResourcesDirectoryURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: _dyld_image_count

CFStringRef Resources::getResourcesPathFromDyldImage(){
	const mach_header* header;
	header = (mach_header*)&_mh_bundle_header;
	const char* image_name = 0;
	char buffer[PATH_MAX];

	int cnt = _dyld_image_count();
	for (int i = 1; i < cnt; i++)
	{
		if (_dyld_get_image_header((unsigned long)i) == header)
		{
			image_name = _dyld_get_image_name(i);
			break;
		}
	}

	CFURLRef executableURL = CFURLCreateFromFileSystemRepresentation (kCFAllocatorDefault, (const unsigned char*)image_name, strlen (image_name), false);
	CFURLRef bundleContentsMacOSURL = CFURLCreateCopyDeletingLastPathComponent (kCFAllocatorDefault, executableURL);
	CFRelease (executableURL);
    CFURLRef bundleContentsURL = CFURLCreateCopyDeletingLastPathComponent (kCFAllocatorDefault, bundleContentsMacOSURL);
    CFRelease (bundleContentsMacOSURL);
    CFURLRef bundleURL = CFURLCreateCopyDeletingLastPathComponent (kCFAllocatorDefault, bundleContentsURL);
    CFRelease (bundleContentsURL);
    CFBundleRef bundle = CFBundleCreate (kCFAllocatorDefault, bundleURL);
    CFURLRef bundleResourcesURL = CFBundleCopyResourcesDirectoryURL(bundle);
	CFURLGetFileSystemRepresentation(bundleResourcesURL, TRUE, (UInt8*)buffer,PATH_MAX);
	CFStringRef path = CFStringCreateWithCString(NULL,buffer, kCFStringEncodingUTF8);
	return path;
}
开发者ID:2mc,项目名称:supercollider,代码行数:29,代码来源:Resources.cpp

示例2: getPath

std::string getPath()
{
    std::string fullpath;
    // ----------------------------------------------------------------------------
    // This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle
#ifdef __APPLE__
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
    char path[PATH_MAX];
    if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
    {
        // error!
    }
    CFRelease(resourcesURL);
    chdir(path);
    fullpath = path;
#else
	 char cCurrentPath[1024];
	 if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
		 return "";

	cCurrentPath[sizeof(cCurrentPath) - 1] = '\0';
	fullpath = cCurrentPath;

#endif    
    return fullpath;
}
开发者ID:jagenjo,项目名称:TJE_Framework,代码行数:27,代码来源:utils.cpp

示例3: SetupDefaultDirs

bool SetupDefaultDirs(const char *exefilepath, const char *auxfilepath, bool forcecommandline)
{
    datadir = StripFilePart(exefilepath);
    auxdir = auxfilepath ? StripFilePart(SanitizePath(auxfilepath).c_str()) : datadir;
    writedir = auxdir;

    #ifdef __APPLE__
        if (!forcecommandline)
        {
            // default data dir is the Resources folder inside the .app bundle
            CFBundleRef mainBundle = CFBundleGetMainBundle();
            CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
            char path[PATH_MAX];
            auto res = CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX);
            CFRelease(resourcesURL);
            if (!res)
                return false;
            datadir = string(path) + "/";
            #ifdef __IOS__
                writedir = StripFilePart(path) + "Documents/"; // there's probably a better way to do this in CF
            #else
                writedir = datadir; // FIXME: this should probably be ~/Library/Application Support/AppName, but for now this works for non-app store apps
            #endif
        }
    #elif defined(ANDROID)
        datadir = "/Documents/Lobster/";  // FIXME: temp solution
        writedir = datadir;
    #endif

    return true;  
}
开发者ID:tom-seddon,项目名称:lobster,代码行数:31,代码来源:platform.cpp

示例4: _glfwChangeToResourcesDirectory

void _glfwChangeToResourcesDirectory( void )
{
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL( mainBundle );
    char resourcesPath[ _GLFW_MAX_PATH_LENGTH ];
    
    CFStringRef lastComponent = CFURLCopyLastPathComponent( resourcesURL );
    if ( kCFCompareEqualTo != CFStringCompare(
            CFSTR( "Resources" ),
            lastComponent,
            0 ) )
    {
        UNBUNDLED;
    }
    
    CFRelease( lastComponent );

    if( !CFURLGetFileSystemRepresentation( resourcesURL,
                                           TRUE,
                                           (UInt8*)resourcesPath,
                                           _GLFW_MAX_PATH_LENGTH ) )
    {
        CFRelease( resourcesURL );
        UNBUNDLED;
    }

    CFRelease( resourcesURL );

    if( chdir( resourcesPath ) != 0 )
    {
        UNBUNDLED;
    }
}
开发者ID:x-y-z,项目名称:SteerSuite-CUDA,代码行数:33,代码来源:macosx_init.c

示例5: _expand_resources

static int
_expand_resources(krb5_context context, PTYPE param, const char *postfix, char **str)
{
    char path[MAXPATHLEN];

    CFBundleRef appBundle = CFBundleGetMainBundle();
    if (appBundle == NULL)
	return KRB5_CONFIG_BADFORMAT;

    /* 
     * Check if there is an Info.plist, if not, then its is not a real
     * bundle and skip
     */
    CFDictionaryRef infoPlist = CFBundleGetInfoDictionary(appBundle);
    if (infoPlist == NULL || CFDictionaryGetCount(infoPlist) == 0)
	return KRB5_CONFIG_BADFORMAT;

    CFURLRef resourcesDir = CFBundleCopyResourcesDirectoryURL(appBundle);
    if (resourcesDir == NULL)
	return KRB5_CONFIG_BADFORMAT;

    if (!CFURLGetFileSystemRepresentation(resourcesDir, true, (UInt8 *)path, sizeof(path))) {
	CFRelease(resourcesDir);
	return ENOMEM;
    }

    CFRelease(resourcesDir);

    *str = strdup(path);
    if (*str == NULL)
	return ENOMEM;

    return 0;
}
开发者ID:aosm,项目名称:Heimdal,代码行数:34,代码来源:expand_path.c

示例6: SDL_Init

	SDLApplication::SDLApplication () {
		
		SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
		
		currentUpdate = 0;
		lastUpdate = 0;
		nextUpdate = 0;
		
		KeyEvent keyEvent;
		MouseEvent mouseEvent;
		RenderEvent renderEvent;
		TouchEvent touchEvent;
		UpdateEvent updateEvent;
		WindowEvent windowEvent;
		
		#ifdef HX_MACOS
		CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ());
		char path[PATH_MAX];
		
		if (CFURLGetFileSystemRepresentation (resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) {
			
			chdir (path);
			
		}
		
		CFRelease (resourcesURL);
		#endif
		
	}
开发者ID:mandel59,项目名称:lime,代码行数:29,代码来源:SDLApplication.cpp

示例7: dataNode

void OSystem_SDL::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) {

#ifdef DATA_PATH
	// Add the global DATA_PATH to the directory search list
	// FIXME: We use depth = 4 for now, to match the old code. May want to change that
	Common::FSNode dataNode(DATA_PATH);
	if (dataNode.exists() && dataNode.isDirectory()) {
		s.add(DATA_PATH, new Common::FSDirectory(dataNode, 4), priority);
	}
#endif

#ifdef MACOSX
	// Get URL of the Resource directory of the .app bundle
	CFURLRef fileUrl = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
	if (fileUrl) {
		// Try to convert the URL to an absolute path
		UInt8 buf[MAXPATHLEN];
		if (CFURLGetFileSystemRepresentation(fileUrl, true, buf, sizeof(buf))) {
			// Success: Add it to the search path
			Common::String bundlePath((const char *)buf);
			s.add("__OSX_BUNDLE__", new Common::FSDirectory(bundlePath), priority);
		}
		CFRelease(fileUrl);
	}

#endif

}
开发者ID:havlenapetr,项目名称:Scummvm,代码行数:28,代码来源:sdl.cpp

示例8: defined

// Get all filenames and directories
void
PingusMain::init_path_finder()
{
  if (cmd_options.userdir.is_set())
    System::set_userdir(cmd_options.userdir.get());

  System::init_directories();

  if (cmd_options.datadir.is_set())
  {
    g_path_manager.set_path(cmd_options.datadir.get());
  }
  else
  { // do magic to guess the datadir
#if defined(__APPLE__)
    char resource_path[PATH_MAX];
    CFURLRef ref = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
    if (!ref || !CFURLGetFileSystemRepresentation(ref, true, (UInt8*)resource_path, PATH_MAX))
    {
      std::cout << "Error: Couldn't get Resources path.\n" << std::endl;
      exit(EXIT_FAILURE);
    }
    CFRelease(ref);
    g_path_manager.set_path("data");
#else
    g_path_manager.set_path("data"); // assume game is run from source dir
#endif
  }

  // Language is automatically picked from env variable
  //dictionary_manager.set_language(tinygettext::Language::from_env("it_IT.utf8")); // maybe overwritten by file ~/.pingus/config
  dictionary_manager.add_directory(g_path_manager.complete("po/"));
}
开发者ID:liushuyu,项目名称:aosc-os-abbs,代码行数:34,代码来源:pingus_main.cpp

示例9: main

int main(int argc, char *argv[])
#endif
{
#ifdef __APPLE__
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
    char path[PATH_MAX];
    if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
    {
        // error!
        std::cerr << "PATH ERROR " << __FILE__ << ": " << __LINE__ << std::endl;
    }
    CFRelease(resourcesURL);
    chdir(path); // cd in
    psc::Conf::i().init(path);
#elif _SHOOTING_CUBES_ANDROID_
    app_dummy();
    char buf[256] = {0};
    getcwd(buf, 256);
    chdir(app->activity->internalDataPath);
    LOGI("cwd: %s", buf);
    unpack_data(app);
    psc::Conf::i().init("", app->activity->internalDataPath, app->activity->externalDataPath);
    psc::App::i().init(app).launchOpening2().run();
    IrrDevice::i().~IrrDevice(); // manually destruct here, as IrrEx17 example?
#else
    psc::Conf::i().init(""); // doesn't need to find working_path on win32, not sure about linux though
    std::srand(std::time(0)^std::clock()); //  init srand for global rand...
    //return psc::App::i().init().launchOpening().run();
    return psc::App::i().init().launchOpening2().run();
#endif
}
开发者ID:godfat,项目名称:cubeat,代码行数:32,代码来源:main.cpp

示例10: fs_helpers_apple_init

/*
=================
fs_helpers_apple_init
=================
*/
erbool fs_helpers_apple_init (void)
{
    CFURLRef url;

    if (NULL == (cg_main_bundle = CFBundleGetMainBundle()))
    {
        sys_printf("CFBundleGetMainBundle failed\n");
        return false;
    }

    if (NULL == (url = CFBundleCopyResourcesDirectoryURL(cg_main_bundle)))
    {
        sys_printf("CFBundleCopyResourcesDirectoryURL failed\n");
        CFRelease(cg_main_bundle);
        return false;
    }

    fs_get_documents_path(paths[0].path, sizeof(paths[0].path));
    paths[0].valid = 1;
    paths[0].rdonly = 0;

    CFURLGetFileSystemRepresentation(url, true, (unsigned char *)paths[1].path, sizeof(paths[1].path));
    CFRelease(url);
    paths[1].valid = 1;
    paths[1].rdonly = 1;

    paths[2].valid = paths[3].valid = 0;

    return true;
}
开发者ID:eledot,项目名称:erszebet,代码行数:35,代码来源:fs_helpers_apple.c

示例11: pathForTool

static bool
pathForTool(CFStringRef toolName, char path[MAXPATHLEN])
{
    CFBundleRef bundle;
    CFURLRef resources;
    CFURLRef toolURL;
    Boolean success = true;
    
    bundle = CFBundleGetMainBundle();
    if (!bundle)
        return FALSE;
    
    resources = CFBundleCopyResourcesDirectoryURL(bundle);
    if (!resources)
        return FALSE;
    
    toolURL = CFURLCreateCopyAppendingPathComponent(NULL, resources, toolName, FALSE);
    CFRelease(resources);
    if (!toolURL)
        return FALSE;
    
    success = CFURLGetFileSystemRepresentation(toolURL, TRUE, (UInt8 *)path, MAXPATHLEN);
    
    CFRelease(toolURL);
    return !access(path, X_OK);
}
开发者ID:cylonbrain,项目名称:InsomniaX,代码行数:26,代码来源:auth_tool_run.c

示例12: 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

示例13: main

int main()
{
#ifdef __APPLE__
    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
    char path[PATH_MAX];
    if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
        return 1;

    CFRelease(resourcesURL);

    chdir(path);
#endif

    try
    {
        FormBuilder app;
        return app.run();
    }
    catch (std::exception e)
    {
        std::cerr << e.what() << std::endl;
        return 1;
    }

    return 0;
}
开发者ID:Goldenwing,项目名称:Hnefatafl,代码行数:27,代码来源:main.cpp

示例14: pathToResourceDirectory

string pathToResourceDirectory()
{
#ifdef __APPLE__
	char path[MAXPATHLEN];
	string tempString;
	CFBundleRef bundle;
	CFURLRef resDirURL;

	path[0] = '\0';
	
	bundle = CFBundleGetMainBundle();
	if (!bundle) return string ("");

	resDirURL = CFBundleCopyResourcesDirectoryURL(bundle);
	if (!resDirURL) return string ("");

	CFURLGetFileSystemRepresentation(resDirURL, TRUE, (UInt8 *)path, MAXPATHLEN);
	CFRelease(resDirURL);
	
	// put a trailing slash on the path
	tempString = string(path);
	tempString.append("/");
	return tempString;
#endif

#ifdef _WIN32
	return string("resources/");
#endif
}
开发者ID:Blz-Galaxy,项目名称:OpenGL_Animation_MT,代码行数:29,代码来源:platform.cpp

示例15: main

int main(int argc, char *argv[]) {
    std::ostream& stream = std::cout;
    const char *parm = (argc > 1 ? argv[1] : 0);

    stream << "welcome to goat attack ";
    stream << GameVersion;
    stream << "...\n" << std::endl;

    init_hpet();
    start_net();
    try {
        Configuration config(UserDirectory, ConfigFilename);

#ifdef DEDICATED_SERVER
        SubsystemNull subsystem(stream, "Goat Attack");
#else
        SubsystemSDL subsystem(stream, "Goat Attack", config.get_bool("shading_pipeline"));
#endif

#ifdef __APPLE__
        CFBundleRef mainBundle = CFBundleGetMainBundle();
        CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle);
        char path[PATH_MAX];
        if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX))
        {
            throw Exception("Cannot get bundle path");
        }
        CFRelease(resourcesURL);
        std::string data_directory(path);
        Resources resources(subsystem, data_directory);
#else
# ifdef DEDICATED_SERVER
        const char *data_directory = STRINGIZE_VALUE_OF(DATA_DIRECTORY);
# else
        const char *data_directory = (parm ? parm : STRINGIZE_VALUE_OF(DATA_DIRECTORY));
# endif
        Resources resources(subsystem, data_directory);
#endif
        Game game(resources, subsystem, config);
        game.run(parm ? parm : "");
    } catch (const ResourcesMissingException& e) {
        stream << std::endl << "ERROR: ";
#ifdef DEDICATED_SERVER
        stream << e.what() << std::endl;
#else
        stream << e.what() << std::endl;
        stream << "Ensure that you can add a data folder as parameter." << std::endl;
        stream << "Example: " << argv[0] << " path/to/your/data/folder" << std::endl;
#endif
    } catch (const Exception& e) {
        stream << std::endl << "ERROR: ";
        stream << e.what() << std::endl;
    }
    stop_net();

    stream << "\nbye bye... :)" << std::endl;

    return 0;
}
开发者ID:goatattack,项目名称:goatattack,代码行数:59,代码来源:main.cpp


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