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; }
void* AppleCMIODPSampleNewPlugIn(CFAllocatorRef allocator, CFUUIDRef requestedTypeUUID) { if (not CFEqual(requestedTypeUUID, kCMIOHardwarePlugInTypeID)) return 0; try { // Before going any further, make sure the SampleAssistant process is registerred with Mach's bootstrap service. Normally, this would be done by having an appropriately // configured plist in /Library/LaunchDaemons, but if that is done then the process will be owned by root, thus complicating the debugging process. Therefore, in the event that the // plist is missing (as would be the case for most debugging efforts) attempt to register the SampleAssistant now. It will fail gracefully if allready registered. mach_port_t assistantServicePort; name_t assistantServiceName = "com.apple.cmio.DPA.Sample"; kern_return_t err = bootstrap_look_up(bootstrap_port, assistantServiceName, &assistantServicePort); if (BOOTSTRAP_SUCCESS != err) { // Create an URL to SampleAssistant that resides at "/Library/CoreMediaIO/Plug-Ins/DAL/Sample.plugin/Contents/Resources/SampleAssistant" CACFURL assistantURL(CFURLCreateWithFileSystemPath(NULL, CFSTR("/Library/CoreMediaIO/Plug-Ins/DAL/Sample.plugin/Contents/Resources/SampleAssistant"), kCFURLPOSIXPathStyle, false)); ThrowIf(not assistantURL.IsValid(), CAException(-1), "AppleCMIODPSampleNewPlugIn: unable to create URL for the SampleAssistant"); // Get the maximum size of the of the file system representation of the SampleAssistant's absolute path CFIndex length = CFStringGetMaximumSizeOfFileSystemRepresentation(CACFString(CFURLCopyFileSystemPath(CACFURL(CFURLCopyAbsoluteURL(assistantURL.GetCFObject())).GetCFObject(), kCFURLPOSIXPathStyle)).GetCFString()); // Get the file system representation CAAutoFree<char> path(length); (void) CFURLGetFileSystemRepresentation(assistantURL.GetCFObject(), true, reinterpret_cast<UInt8*>(path.get()), length); mach_port_t assistantServerPort; err = bootstrap_create_server(bootstrap_port, path, getuid(), true, &assistantServerPort); ThrowIf(BOOTSTRAP_SUCCESS != err, CAException(err), "AppleCMIODPSampleNewPlugIn: couldn't create server"); err = bootstrap_check_in(assistantServerPort, assistantServiceName, &assistantServicePort); // The server port is no longer needed so get rid of it (void) mach_port_deallocate(mach_task_self(), assistantServerPort); // Make sure the call to bootstrap_create_service() succeeded ThrowIf(BOOTSTRAP_SUCCESS != err, CAException(err), "AppleCMIODPSampleNewPlugIn: couldn't create SampleAssistant service port"); } // The service port is not longer needed so get rid of it (void) mach_port_deallocate(mach_task_self(), assistantServicePort); CMIO::DP::Sample::PlugIn* plugIn = new CMIO::DP::Sample::PlugIn(requestedTypeUUID); plugIn->Retain(); return plugIn->GetInterface(); } catch (...) { return NULL; } }
/** * 実行している自身のディレクトリパス取得 * @return 実行ディレクトリフルパス */ std::string getBinaryDir() { const int MAXPATHLEN = 4096; char exepath[MAXPATHLEN] = {}; #if _WIN32 wchar_t app_full_path[1024]; DWORD length = GetModuleFileNameW(NULL, app_full_path, sizeof(app_full_path) / sizeof(wchar_t)); std::wstring str(app_full_path, length); const char16_t* p = reinterpret_cast<const char16_t*>(str.c_str()); std::u16string u16str(p); // utf16 to utf8 std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert; std::string stdstr = convert.to_bytes(u16str); std::string::size_type pos = stdstr.find_last_of("\\"); if (pos != std::string::npos) { std::string basepath = stdstr.substr(0, pos + 1); return basepath; } return stdstr; #elif __APPLE__ #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1012 uint32_t size = sizeof(exepath); int ret = _NSGetExecutablePath(exepath, &size); if (0 != ret) { return ""; // FIXME(IDS): } #else CFBundleRef bundle = CFBundleGetMainBundle(); CFURLRef executableURL = CFBundleCopyExecutableURL(bundle); CFStringRef executablePath = CFURLCopyFileSystemPath(executableURL, kCFURLPOSIXPathStyle); CFStringGetMaximumSizeOfFileSystemRepresentation(executablePath); CFStringGetFileSystemRepresentation(executablePath, exepath, MAXPATHLEN); CFRelease(executablePath); CFRelease(executableURL); #endif #else // Linux readlink("/proc/self/exe", exepath, sizeof(exepath)); #endif // for Mac & Linux std::string fullpath(exepath); size_t t = fullpath.rfind("/"); if (t != std::string::npos) { fullpath = fullpath.substr(0, t + 1); } return fullpath; }
char* _CFFSCreateRepresentation(CFStringRef path) { if (!path) { errno = EINVAL; return NULL; } CFIndex length = CFStringGetMaximumSizeOfFileSystemRepresentation(path); char* buffer = (char*)malloc(length); if (!buffer) { return NULL; } if (!CFStringGetFileSystemRepresentation(path, buffer, length)) { free(buffer); errno = ENAMETOOLONG; return NULL; } return buffer; }
CString fileSystemRepresentation(const String& path) { RetainPtr<CFStringRef> cfString = path.createCFString(); if (!cfString) return CString(); CFIndex size = CFStringGetMaximumSizeOfFileSystemRepresentation(cfString.get()); Vector<char> buffer(size); if (!CFStringGetFileSystemRepresentation(cfString.get(), buffer.data(), buffer.size())) { LOG_ERROR("Failed to get filesystem representation to create CString from cfString"); return CString(); } return CString(buffer.data(), strlen(buffer.data())); }
/* Return the string value suitable for use with posix file system calls for KEY found in PLIST. NULL will be returned if KEY does not have a valid value in the the property list, if the value is not a string, or if there were errors extracting the value for KEY. */ const char * macosx_get_plist_posix_value(const void *plist, const char* key) { char *value = NULL; CFStringRef cf_key; CFStringRef cf_value; if (plist == NULL) return NULL; cf_key = (CFStringRef)CFStringCreateWithCString(kCFAllocatorDefault, key, kCFStringEncodingUTF8); cf_value = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)plist, cf_key); if ((cf_value != NULL) && (CFGetTypeID(cf_value) == CFStringGetTypeID())) { CFIndex max_value_len; max_value_len = CFStringGetMaximumSizeOfFileSystemRepresentation(cf_value); if (max_value_len > 0) { value = (char *)xmalloc(max_value_len + 1); if (value) { if (!CFStringGetFileSystemRepresentation(cf_value, value, max_value_len)) { /* We failed to get a file system representation of the bundle executable, just free the buffer we malloc'ed. */ xfree(value); value = NULL; } } } } if (cf_key) { CFRelease(cf_key); } return value; }
void mui_init(){ #if TARGET_OS_IPHONE if( mui::MuiConfig::detectRetina ){ ofAppiOSWindow * w = ofAppiOSWindow::getInstance(); if( w->isRetinaEnabled() ){ mui::MuiConfig::scaleFactor = 2; mui::MuiConfig::useRetinaAssets = true; } } #endif //TODO: allow retina in osx too! Poco::Path appPath; #if TARGET_OS_IPHONE // http://www.cocoabuilder.com/archive/cocoa/193451-finding-out-executable-location-from-c-program.html CFBundleRef bundle = CFBundleGetMainBundle(); CFURLRef url = CFBundleCopyExecutableURL(bundle); // CFBundleCopyResourcesDirectoryURL(bundle); CFURLRef absolute = CFURLCopyAbsoluteURL(url); CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); CFIndex maxLength = CFStringGetMaximumSizeOfFileSystemRepresentation(path); char *result = (char*)malloc(maxLength); if(result) { if(!CFStringGetFileSystemRepresentation(path,result, maxLength)) { free(result); result = NULL; } } CFRelease(path); CFRelease(url); CFRelease(absolute); appPath = Poco::Path(result); appPath = appPath.parent(); #elif TARGET_OS_MAC // http://www.cocoabuilder.com/archive/cocoa/193451-finding-out-executable-location-from-c-program.html CFBundleRef bundle = CFBundleGetMainBundle(); CFURLRef url = CFBundleCopyExecutableURL(bundle); // CFBundleCopyResourcesDirectoryURL(bundle); CFURLRef absolute = CFURLCopyAbsoluteURL(url); CFStringRef path = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle); CFIndex maxLength = CFStringGetMaximumSizeOfFileSystemRepresentation(path); char *result = (char*)malloc(maxLength); if(result) { if(!CFStringGetFileSystemRepresentation(path,result, maxLength)) { free(result); result = NULL; } } CFRelease(path); CFRelease(url); CFRelease(absolute); appPath = Poco::Path(result); appPath = appPath.parent().parent().pushDirectory("Resources"); if( mui::MuiConfig::detectRetina ){ ofAppGLFWWindow * window = dynamic_cast<ofAppGLFWWindow*>(ofGetWindowPtr()); if( window != NULL ){ mui::MuiConfig::scaleFactor = window->getPixelScreenCoordScale(); } } #else appPath = Poco::Path(ofToDataPath("", true)); #endif mui::MuiConfig::dataPath = appPath.absolute(); }