boolean directorytopath ( const ptrfilespec fs, bigstring path ) { // // 2006-09-09 creedon: FSRef-ized // another way might be to use FSRefMakePath and then push insert the volume name on it // OSErr err; OSStatus status; FSRef volumesfsref; status = FSPathMakeRef ((UInt8 *)"/Volumes", &volumesfsref, NULL); if ((status == noErr) && (FSCompareFSRefs (&fs->ref, &volumesfsref) == noErr)) { /* bail if fs is Volumes directory */ setemptystring (path); return (true); } CFMutableStringRef ioPath = CFStringCreateMutable (NULL, 0); FSCatalogInfo catalogInfo; FSRef fsrefnomad = fs->ref; HFSUniStr255 names[100]; int i, n; UniChar inSepChar = ':'; err = noErr; clearbytes (&catalogInfo, longsizeof (catalogInfo)); for (n = 0; err == noErr && catalogInfo.nodeID != fsRtDirID && n < 100; n++) { err = FSGetCatalogInfo (&fsrefnomad, kFSCatInfoNodeID, &catalogInfo, &names[n], NULL, &fsrefnomad); } if (err != noErr) return (false); for (i = n - 1; i >= 0; --i) { CFStringAppendCharacters (ioPath, names[i].unicode, names[i].length); CFStringAppendCharacters (ioPath, &inSepChar, 1); } boolean success = CFStringGetPascalString (ioPath, path, 256, kCFStringEncodingMacRoman); CFRelease(ioPath); //PBS 2/28/11: fixed memory leak return success; } // directorytopath
static FT_Error FT_GetFileRef_From_Mac_ATS_Name( const char* fontName, FSRef* ats_font_ref, FT_Long* face_index ) { CFStringRef cf_fontName; ATSFontRef ats_font_id; *face_index = 0; cf_fontName = CFStringCreateWithCString( NULL, fontName, kCFStringEncodingMacRoman ); ats_font_id = ATSFontFindFromName( cf_fontName, kATSOptionFlagsUnRestrictedScope ); CFRelease( cf_fontName ); if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) return FT_Err_Unknown_File_Format; if ( noErr != FT_ATSFontGetFileReference( ats_font_id, ats_font_ref ) ) return FT_Err_Unknown_File_Format; /* face_index calculation by searching preceding fontIDs */ /* with same FSRef */ { ATSFontRef id2 = ats_font_id - 1; FSRef ref2; while ( id2 > 0 ) { if ( noErr != FT_ATSFontGetFileReference( id2, &ref2 ) ) break; if ( noErr != FSCompareFSRefs( ats_font_ref, &ref2 ) ) break; id2 --; } *face_index = ats_font_id - ( id2 + 1 ); } return FT_Err_Ok; }
OSStatus FindPIDForWoW(pid_t *pid) { CFURLRef outAppURL; OSErr err; err = LSFindApplicationForInfo(NULL, (CFStringRef)@"com.blizzard.worldofwarcraft", NULL, NULL, &outAppURL); err = 0; FSRef desired, found; ProcessSerialNumber psn = {0, kNoProcess}; if (!CFURLGetFSRef(outAppURL, &desired)) return errFSBadFSRef; do { err = GetNextProcess(&psn); if (err) return err; // -600 = process not found err = GetProcessBundleLocation(&psn, &found); } while (err || FSCompareFSRefs(&desired, &found)); err = GetProcessPID(&psn, pid); if (err) return err; return noErr; }
static PyObject *AE_PSNDescForApplicationPath(PyObject* self, PyObject* args) { ProcessSerialNumber psn = {0, kNoProcess}; FSRef appRef, foundRef; AEDesc result; OSStatus err; if (!PyArg_ParseTuple(args, "O&", AE_GetFSRef, &appRef)) return NULL; while (1) { err = GetNextProcess(&psn); if (err) return AE_MacOSError(err); err = GetProcessBundleLocation(&psn, &foundRef); if (err == noErr && FSCompareFSRefs(&appRef, &foundRef) == noErr) break; } err = AECreateDesc(typeProcessSerialNumber, &psn, sizeof(psn), &result); if (err != noErr) return AE_MacOSError(err); return Py_BuildValue("O&", AE_AEDesc_New, &result); }
char* MacLegacy_Select( filter_t *p_filter, const char* psz_fontname, bool b_bold, bool b_italic, int i_size, int *i_idx ) { VLC_UNUSED( b_bold ); VLC_UNUSED( b_italic ); VLC_UNUSED( i_size ); FSRef ref; unsigned char path[MAXPATHLEN]; char * psz_path; CFStringRef cf_fontName; ATSFontRef ats_font_id; *i_idx = 0; if( psz_fontname == NULL ) return NULL; msg_Dbg( p_filter, "looking for %s", psz_fontname ); cf_fontName = CFStringCreateWithCString( kCFAllocatorDefault, psz_fontname, kCFStringEncodingUTF8 ); ats_font_id = ATSFontFindFromName( cf_fontName, kATSOptionFlagsIncludeDisabledMask ); if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) { msg_Dbg( p_filter, "ATS couldn't find %s by name, checking family", psz_fontname ); ats_font_id = ATSFontFamilyFindFromName( cf_fontName, kATSOptionFlagsDefault ); if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) { msg_Dbg( p_filter, "ATS couldn't find either %s nor its family, checking PS name", psz_fontname ); ats_font_id = ATSFontFindFromPostScriptName( cf_fontName, kATSOptionFlagsDefault ); if ( ats_font_id == 0 || ats_font_id == 0xFFFFFFFFUL ) { msg_Err( p_filter, "ATS couldn't find %s (no font name, family or PS name)", psz_fontname ); CFRelease( cf_fontName ); return NULL; } } } CFRelease( cf_fontName ); if ( noErr != ATSFontGetFileReference( ats_font_id, &ref ) ) { msg_Err( p_filter, "ATS couldn't get file ref for %s", psz_fontname ); return NULL; } /* i_idx calculation by searching preceding fontIDs */ /* with same FSRef */ { ATSFontRef id2 = ats_font_id - 1; FSRef ref2; while ( id2 > 0 ) { if ( noErr != ATSFontGetFileReference( id2, &ref2 ) ) break; if ( noErr != FSCompareFSRefs( &ref, &ref2 ) ) break; id2 --; } *i_idx = ats_font_id - ( id2 + 1 ); } if ( noErr != FSRefMakePath( &ref, path, sizeof(path) ) ) { msg_Err( p_filter, "failure when getting path from FSRef" ); return NULL; } msg_Dbg( p_filter, "found %s", path ); psz_path = strdup( (char *)path ); return psz_path; }
void SplitForks(FSRef * inFileReference,FSRef * inParentReference,Boolean inFirstLevel) { OSErr tErr; FSIterator tIterator; if (inFirstLevel==TRUE) { FSCatalogInfo tInfo; HFSUniStr255 tUnicodeFileName; // We need to split forks of the first level (and it allows us to check whether it's a folder or not) tErr=FSGetCatalogInfo(inFileReference,kFSCatInfoGettableInfo,&tInfo,&tUnicodeFileName,NULL,NULL); if (tErr==noErr) { // Check this is not a Hard Link if ((tInfo.nodeFlags & kFSNodeHardLinkMask)==0) { tErr=SplitFileIfNeeded(inFileReference,inParentReference,&tInfo,&tUnicodeFileName); if (tErr==noErr) { if (tInfo.nodeFlags & kFSNodeIsDirectoryMask) { // It's a folder // We need to proceed with the contents of the folder SplitForks(inFileReference,inParentReference,FALSE); } } else { exit(-1); } } } else { logerror("An error while getting Catalog Information for the File\n"); } return; } tErr=FSOpenIterator(inFileReference,kFSIterateFlat,&tIterator); if (tErr==noErr) { ItemCount tLookForItems,tFoundItems; FSCatalogInfo * tFoundCatInfo; FSRef * tFoundReferences; HFSUniStr255 * tFoundFileNames; FSRef tPreviousCacheRef; Boolean tPreviousCacheRefSet=FALSE; tLookForItems=1; tFoundCatInfo=(FSCatalogInfo *) malloc(tLookForItems*sizeof(FSCatalogInfo)); tFoundReferences=(FSRef *) malloc(tLookForItems*sizeof(FSRef)); tFoundFileNames=(HFSUniStr255 *) malloc(tLookForItems*sizeof(HFSUniStr255)); do { tErr=FSGetCatalogInfoBulk(tIterator, tLookForItems, &tFoundItems, NULL, kFSCatInfoGettableInfo, tFoundCatInfo, tFoundReferences, NULL, tFoundFileNames); if (tErr==noErr) { if (tPreviousCacheRefSet==TRUE) { if (FSCompareFSRefs(&tPreviousCacheRef,&tFoundReferences[0])==noErr) { // We need to skip the file since this is the one we processed previously continue; } } else { tPreviousCacheRefSet=TRUE; } tPreviousCacheRef=tFoundReferences[0]; // Check this is not a Hard Link if ((tFoundCatInfo[0].nodeFlags & kFSNodeHardLinkMask)==0) { tErr=SplitFileIfNeeded(&tFoundReferences[0],inFileReference,&tFoundCatInfo[0],&tFoundFileNames[0]); if (tErr==noErr) { if (tFoundCatInfo[0].nodeFlags & kFSNodeIsDirectoryMask) { // 2. We need to proceed with the contents of the folder SplitForks(&tFoundReferences[0],inFileReference,FALSE); } } else { exit(-1); } } } else { // A COMPLETER } } while (tErr==noErr); free(tFoundCatInfo); free(tFoundReferences); free(tFoundFileNames); FSCloseIterator (tIterator); } if (tErr!=noErr) { switch(tErr) { case errFSNoMoreItems: // No more items in the folder, this is perfectly ok break; case afpAccessDenied: break; default: // A COMPLETER break; } } }