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; }
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; }
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; }
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; } }
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; }
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 }
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 }
// 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/")); }
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 }
/* ================= 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; }
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); }
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; }
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; }
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 }
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; }
SDLApplication::SDLApplication () { if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) { printf ("Could not initialize SDL: %s.\n", SDL_GetError ()); } currentApplication = this; framePeriod = 1000.0 / 60.0; #ifdef EMSCRIPTEN emscripten_cancel_main_loop (); emscripten_set_main_loop (UpdateFrame, 0, 0); emscripten_set_main_loop_timing (EM_TIMING_RAF, 1); #endif currentUpdate = 0; lastUpdate = 0; nextUpdate = 0; ApplicationEvent applicationEvent; GamepadEvent gamepadEvent; KeyEvent keyEvent; MouseEvent mouseEvent; RenderEvent renderEvent; SensorEvent sensorEvent; TextEvent textEvent; TouchEvent touchEvent; WindowEvent windowEvent; #if defined(IOS) || defined(ANDROID) for (int i = 0; i < SDL_NumJoysticks (); i++) { if (strstr (SDL_JoystickNameForIndex (i), "Accelerometer")) { accelerometer = SDL_JoystickOpen (i); accelerometerID = SDL_JoystickInstanceID (accelerometer); } } #endif #ifdef HX_MACOS CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ()); char path[PATH_MAX]; if (CFURLGetFileSystemRepresentation (resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { chdir (path); } CFRelease (resourcesURL); #endif }
String WebInspectorProxy::inspectorBaseURL() const { // Web Inspector uses localized strings, so it's not contained within inspector directory. RetainPtr<CFURLRef> htmlURLRef(AdoptCF, CFBundleCopyResourcesDirectoryURL(webKitBundle())); if (!htmlURLRef) return String(); return String(CFURLGetString(htmlURLRef.get())); }
char *HostFilesys::getDataFolder(char *buffer, unsigned int bufsize) { UInt8 main_bundle_loc[MAXPATHLEN]; CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); CFURLGetFileSystemRepresentation(url, true, main_bundle_loc, sizeof(main_bundle_loc)); CFRelease(url); //printf("Data folder ---------> %s\n", main_bundle_loc); return safe_strncpy(buffer, (char*)main_bundle_loc, bufsize); }
void setcwd(void) { // make sure cwd is where the app is (launching from Finder sets it to / by default) unsigned char parentdir[MAXPATHLEN]; CFURLRef url = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); if (CFURLGetFileSystemRepresentation(url, true, parentdir, MAXPATHLEN)) { chdir((char *)parentdir); } CFRelease(url); }
char* bundle_path() { CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); int len = 4096; char* path = malloc(len); CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8*)path, len); return path; }
const String application_path() { cf::Url url(CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle())); cf::String url_string(CFStringCreateCopy(NULL, CFURLGetString(url.c_obj()))); char path_buffer[PATH_MAX]; if (!CFURLGetFileSystemRepresentation( url.c_obj(), true, reinterpret_cast<UInt8*>(path_buffer), PATH_MAX)) { throw Exception("couldn't get application_path()"); } return String(utf8::decode(path_buffer)); }
void initialize() { static bool initialized = false; if (initialized) { return; } // Determine path for resources #ifdef TARGET_OSX CFBundleRef mainBundle = CFBundleGetMainBundle(); if (mainBundle) { boost::filesystem::path bundlePath = convertCFUrlToPath(CFBundleCopyBundleURL(mainBundle)); boost::filesystem::path resourcesPath = convertCFUrlToPath(CFBundleCopyResourcesDirectoryURL(mainBundle)); resources = bundlePath / resourcesPath; } #elif TARGET_LINUX resources = boost::filesystem::read_symlink(boost::filesystem::path("/proc/self/exe")).parent_path() / boost::filesystem::path("resources"); #endif if (!valid(resources)) { throw std::runtime_error("Unable to determine resource directory!"); } // Determine data path char const* dataPathEnv = getenv(DATA_DIRECTORY_ENV_NAME.c_str()); if (dataPathEnv) { data = boost::filesystem::path(dataPathEnv); } else { boost::filesystem::path userHome; char const* home = util::coalesce(getenv("HOME"), getenv("USERPROFILE")); if (home) { userHome = boost::filesystem::path(home); } else { char const* homedrive = getenv("HOMEDRIVE"); char const* homepath = getenv("HOMEPATH"); if (homedrive && homepath) { userHome = boost::filesystem::path(std::string(homedrive) + homepath); } } if (!valid(userHome)) { throw std::runtime_error("Unable to determine user home directory!"); } data = userHome / DATA_DIRECTORY_DEFAULT_NAME; ensureDirectoryExists(data); } initialized = true; }
void RudeGlobals::GetPath(char *path) { #ifdef RUDE_IPHONE CFBundleRef bundle = CFBundleGetMainBundle(); CFURLRef url = CFBundleCopyResourcesDirectoryURL(bundle); CFStringRef cfpath = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); CFStringGetCString(cfpath, path, 512, kCFStringEncodingASCII); #endif }
void initI18n(void) { const char *textdomainDirectory = NULL; if (!setLanguage("")) // set to system default { // no system default? debug(LOG_ERROR, "initI18n: No system language found"); } #if defined(WZ_OS_WIN) { // Retrieve an absolute path to the locale directory char localeDir[PATH_MAX]; sstrcpy(localeDir, PHYSFS_getBaseDir()); sstrcat(localeDir, "\\" LOCALEDIR); // Set locale directory and translation domain name textdomainDirectory = bindtextdomain(PACKAGE, localeDir); } #else #ifdef WZ_OS_MAC { char resourcePath[PATH_MAX]; CFURLRef resourceURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); if( CFURLGetFileSystemRepresentation( resourceURL, true, (UInt8 *) resourcePath, PATH_MAX) ) { sstrcat(resourcePath, "/locale"); textdomainDirectory = bindtextdomain(PACKAGE, resourcePath); } else { debug( LOG_ERROR, "Could not change to resources directory." ); } if (resourceURL != NULL) { CFRelease(resourceURL); } debug(LOG_INFO, "resourcePath is %s", resourcePath); } #else textdomainDirectory = bindtextdomain(PACKAGE, LOCALEDIR); #endif #endif if (!textdomainDirectory) { debug(LOG_ERROR, "initI18n: bindtextdomain failed!"); } (void)bind_textdomain_codeset(PACKAGE, "UTF-8"); (void)textdomain(PACKAGE); }
SDLApplication::SDLApplication () { if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_TIMER | SDL_INIT_JOYSTICK) != 0) { printf ("Could not initialize SDL: %s.\n", SDL_GetError ()); } SDL_LogSetPriority (SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN); currentApplication = this; framePeriod = 1000.0 / 60.0; #ifdef EMSCRIPTEN emscripten_cancel_main_loop (); emscripten_set_main_loop (UpdateFrame, 0, 0); emscripten_set_main_loop_timing (EM_TIMING_RAF, 1); #endif currentUpdate = 0; lastUpdate = 0; nextUpdate = 0; ApplicationEvent applicationEvent; DropEvent dropEvent; GamepadEvent gamepadEvent; JoystickEvent joystickEvent; KeyEvent keyEvent; MouseEvent mouseEvent; RenderEvent renderEvent; SensorEvent sensorEvent; TextEvent textEvent; TouchEvent touchEvent; WindowEvent windowEvent; SDL_EventState (SDL_DROPFILE, SDL_ENABLE); SDLJoystick::Init (); #ifdef HX_MACOS CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL (CFBundleGetMainBundle ()); char path[PATH_MAX]; if (CFURLGetFileSystemRepresentation (resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { chdir (path); } CFRelease (resourcesURL); #endif }
void msGetExecutableDir(string &path) { CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path1[PATH_MAX]; if (CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path1, PATH_MAX)) { CFRelease(resourcesURL); path = path1; } }
// returns e.g. "/Applications/appname.app/Contents/Resources" if application is bundled, // or the directory of the binary, e.g. "/usr/local/bin/appname", if it is *not* bundled. static wxString GetResourcesDir() { CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle()); CFURLRef absoluteURL = CFURLCopyAbsoluteURL(resourcesURL); // relative -> absolute CFRelease(resourcesURL); CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kCFURLPOSIXPathStyle); CFRelease(absoluteURL); #if wxCHECK_VERSION(3, 0, 0) return wxCFStringRef(cfStrPath).AsString(wxLocale::GetSystemEncoding()); #else return wxMacCFStringHolder(cfStrPath).AsString(wxLocale::GetSystemEncoding()); #endif }
CFStringRef Resources::getResourcesPathFromBundleId() { //@@TODO char buffer[PATH_MAX]; CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("SuperColldierAU") ); if (bundle == NULL) return NULL; CFURLRef bundleURL = CFBundleCopyBundleURL(bundle); CFURLGetFileSystemRepresentation(bundleURL, TRUE, (UInt8*)buffer,PATH_MAX); CFStringRef bundlePath = CFStringCreateWithCString(NULL,buffer, kCFStringEncodingUTF8); CFURLRef bundleResourcesURL = CFBundleCopyResourcesDirectoryURL(bundle); CFStringRef resourcesRelativePath = CFURLGetString(bundleResourcesURL); CFMutableStringRef resourcesPath = CFStringCreateMutable(NULL,0); CFStringAppend(resourcesPath,bundlePath); CFStringAppend(resourcesPath,resourcesRelativePath); return resourcesPath; }
void setWorkdir(){ #ifdef __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { throw TetrisException("Could not initialize workdir."); } CFRelease(resourcesURL); chdir(path); #endif }
void OSystem_IPHONE::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { // 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); } }