當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。