Äúµ±Ç°µÄλÖãºÊ×Ò³ > IT±à³Ì > C++
| CÓïÑÔ | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | ѧÊõÓë´úÂë | cnn¾í»ýÉñ¾­ÍøÂç | gnn | ͼÏñÐÞ¸´ | Keras | Êý¾Ý¼¯ | Neo4j | ×ÔÈ»ÓïÑÔ´¦Àí | Éî¶Èѧϰ | ҽѧCAD | ҽѧӰÏñ | ³¬²ÎÊý | pointnet | pytorch | Òì³£¼ì²â | Transformers | Çé¸Ð·ÖÀà | ֪ʶͼÆ× |

×Ôѧ½Ì³Ì£ºC++ FSpMakeFSRefº¯Êý´úÂëʾÀý

51×ÔÑ§Íø 2021-06-01 20:43:45
  C++
ÕâÆª½Ì³ÌC++ FSpMakeFSRefº¯Êý´úÂëʾÀýдµÃºÜʵÓã¬Ï£ÍûÄܰﵽÄú¡£

±¾ÎÄÕûÀí»ã×ÜÁËC++ÖÐFSpMakeFSRefº¯ÊýµÄµäÐÍÓ÷¨´úÂëʾÀý¡£Èç¹ûÄúÕý¿àÓÚÒÔÏÂÎÊÌ⣺C++ FSpMakeFSRefº¯ÊýµÄ¾ßÌåÓ÷¨£¿C++ FSpMakeFSRefÔõôÓã¿C++ FSpMakeFSRefʹÓõÄÀý×Ó£¿ÄÇô¹§Ï²Äú, ÕâÀᆱѡµÄº¯Êý´úÂëʾÀý»òÐí¿ÉÒÔΪÄúÌṩ°ïÖú¡£

ÔÚÏÂÎÄÖÐÒ»¹²Õ¹Ê¾ÁËFSpMakeFSRefº¯ÊýµÄ28¸ö´úÂëʾÀý£¬ÕâЩÀý×ÓĬÈϸù¾ÝÊÜ»¶Ó­³Ì¶ÈÅÅÐò¡£Äú¿ÉÒÔΪϲ»¶»òÕ߸оõÓÐÓõĴúÂëµãÔÞ£¬ÄúµÄÆÀ¼Û½«ÓÐÖúÓÚÎÒÃǵÄÏµÍ³ÍÆ¼ö³ö¸ü°ôµÄC++´úÂëʾÀý¡£

ʾÀý1: LoadBundle

CFBundleRef LoadBundle(const char *tpath){	OSErr theErr;	CFBundleRef theBundle = NULL;	FSSpec fspec;	if ((theErr = MCS_path2FSSpec(tpath, &fspec)) != noErr)		return NULL;	FSRef theRef;	CFURLRef theBundleURL;	theErr = FSpMakeFSRef(&fspec, &theRef);	theBundleURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &theRef);	if (theBundleURL != NULL)	{		/* Turn the CFURL into a bundle reference */		theBundle = CFBundleCreate(kCFAllocatorSystemDefault, theBundleURL);		CFRelease(theBundleURL);	}	if (theErr != noErr || theBundle == NULL)		return NULL;	Boolean isLoaded = CFBundleLoadExecutable(theBundle);	if (!isLoaded)	{		CFRelease(theBundle);		return NULL;	}	return theBundle;}
¿ª·¢ÕßID:Bjoernke£¬ÏîÄ¿Ãû³Æ:livecode£¬´úÂëÐÐÊý:27£¬


ʾÀý2: mkstr255

void *file_list1st(const char *dir, FLINFO *fli) {	FLISTH		ret;	Str255		fname;	FSSpec		fss;	FSRef		fsr;	FSIterator	fsi;	mkstr255(fname, dir);	if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) ||		(FSpMakeFSRef(&fss, &fsr) != noErr) ||		(FSOpenIterator(&fsr, kFSIterateFlat, &fsi) != noErr)) {		goto ff1_err1;	}	ret = _MALLOC(sizeof(_FLHDL), dir);	if (ret == NULL) {		goto ff1_err2;	}	((FLHDL)ret)->eoff = FALSE;	((FLHDL)ret)->fsi = fsi;	if (file_listnext(ret, fli) == SUCCESS) {		return(ret);	}ff1_err2:	FSCloseIterator(fsi);ff1_err1:	return(NULL);}
¿ª·¢ÕßID:FREEWING-JP£¬ÏîÄ¿Ãû³Æ:np2pi£¬´úÂëÐÐÊý:30£¬


ʾÀý3: FSSpecToFullPath

void	FSSpecToFullPath(const FSSpec &fss, char *path){	FSRef ref;		RequireNoErrString(FSpMakeFSRef(&fss, &ref), "FSpMakeFSRef failed");	RequireNoErrString(FSRefMakePath(&ref, (UInt8 *)path, 256), "FSRefMakePath failed");}
¿ª·¢ÕßID:fruitsamples£¬ÏîÄ¿Ãû³Æ:XFramework£¬´úÂëÐÐÊý:7£¬


ʾÀý4: FT_ATSFontGetFileReference

  /* Mac OS X 10.5 and later.                                  */  static OSStatus  FT_ATSFontGetFileReference( ATSFontRef  ats_font_id,                              FSRef*      ats_font_ref )  {#if defined( MAC_OS_X_VERSION_10_5 ) && /    ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 )     OSStatus  err;    err = ATSFontGetFileReference( ats_font_id, ats_font_ref );    return err;#elif __LP64__ /* No 64bit Carbon API on legacy platforms */    FT_UNUSED( ats_font_id );    FT_UNUSED( ats_font_ref );    return fnfErr;#else /* 32bit Carbon API on legacy platforms */    OSStatus  err;    FSSpec    spec;    err = ATSFontGetFileSpecification( ats_font_id, &spec );    if ( noErr == err )      err = FSpMakeFSRef( &spec, ats_font_ref );    return err;#endif  }
¿ª·¢ÕßID:32767£¬ÏîÄ¿Ãû³Æ:libgdx£¬´úÂëÐÐÊý:31£¬


ʾÀý5: string

 string& Configuration::GetExecutablePath() {     string& path = new string("");     ProcessSerialNumber PSN;     ProcessInfoRec pinfo;     FSSpec pspec;     FSRef fsr;     OSStatus err;     // set up process serial number.     PSN.highLongOfPSN = 0;     PSN.lowLongOfPSN = kCurrentProcess;     // set up info block.     pinfo.processInfoLength = sizeof(pinfo);     pinfo.processName = NULL;     pinfo.processAppSpec = &pspec;     // grab the vrefnum and directory.     err = GetProcessInformation(&PSN, &pinfo);     if (! err ) {         char c_path[2048];         FSSpec fss2;         int tocopy;         err = FSMakeFSSpec(pspec.vRefNum, pspec.parID, 0, &fss2);         if ( ! err ) {             err = FSpMakeFSRef(&fss2, &fsr);             if ( ! err ) {                 char c_path[2049];                 err = (OSErr)FSRefMakePath(&fsr, (UInt8*)c_path, 2048);                 if (! err ) {                     path += c_path;                 }             }         }     }     return path; }
¿ª·¢ÕßID:dwhobrey£¬ÏîÄ¿Ãû³Æ:MindCausalModellingLibrary£¬´úÂëÐÐÊý:34£¬


ʾÀý6: file_attr

short file_attr(const char *path) {	Str255			fname;	FSSpec			fss;	FSRef			fsr;	FSCatalogInfo	fsci;	short			ret;	mkstr255(fname, path);	if ((FSMakeFSSpec(0, 0, fname, &fss) != noErr) ||		(FSpMakeFSRef(&fss, &fsr) != noErr) ||		(FSGetCatalogInfo(&fsr, kFSCatInfoNodeFlags, &fsci,										NULL, NULL, NULL) != noErr)) {		return(-1);	}	if (fsci.nodeFlags & kFSNodeIsDirectoryMask) {		ret = FILEATTR_DIRECTORY;	}	else {		ret = FILEATTR_ARCHIVE;	}	if (fsci.nodeFlags & kFSNodeLockedMask) {		ret |= FILEATTR_READONLY;	}	return(ret);}
¿ª·¢ÕßID:FREEWING-JP£¬ÏîÄ¿Ãû³Æ:np2pi£¬´úÂëÐÐÊý:26£¬


ʾÀý7: FFAvi_MovieImportFile

ComponentResult FFAvi_MovieImportFile(ff_global_ptr storage, const FSSpec *theFile, Movie theMovie, Track targetTrack,									  Track *usedTrack, TimeValue atTime, TimeValue *addedDuration, long inFlags, long *outFlags){	ComponentResult result;	Handle dataRef = NULL;	OSType dataRefType;	FSRef theFileFSRef;		*outFlags = 0;		result = QTNewDataReferenceFromFSSpec(theFile, 0, &dataRef, &dataRefType);	require_noerr(result,bail);		result = MovieImportDataRef(storage->ci, dataRef, dataRefType, theMovie, targetTrack, usedTrack, atTime, addedDuration,								inFlags, outFlags);	require_noerr(result, bail);		result = FSpMakeFSRef(theFile, &theFileFSRef);	require_noerr(result, bail);		bail:		if(dataRef)			DisposeHandle(dataRef);		return result;} /* FFAvi_MovieImportFile() */
¿ª·¢ÕßID:eirnym£¬ÏîÄ¿Ãû³Æ:perian£¬´úÂëÐÐÊý:26£¬


ʾÀý8: FT_New_Face_From_FSSpec

  FT_New_Face_From_FSSpec( FT_Library     library,                           const FSSpec*  spec,                           FT_Long        face_index,                           FT_Face*       aface )  {#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && /      ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )    FT_UNUSED( library );    FT_UNUSED( spec );    FT_UNUSED( face_index );    FT_UNUSED( aface );    return FT_THROW( Unimplemented_Feature );#else    FSRef  ref;    /* check of `library' and `aface' delayed to `FT_New_Face_From_FSRef' */    if ( !spec || FSpMakeFSRef( spec, &ref ) != noErr )      return FT_THROW( Invalid_Argument );    else      return FT_New_Face_From_FSRef( library, &ref, face_index, aface );#endif  }
¿ª·¢ÕßID:ImageMagick£¬ÏîÄ¿Ãû³Æ:ttf£¬´úÂëÐÐÊý:25£¬


ʾÀý9: ExtractSingleItem

/* This function extracts a single FSRef from a NavReplyRecord. */static OSErr ExtractSingleItem(const NavReplyRecord *reply, FSRef *item){    FSSpec fss;    SInt32 itemCount;    DescType junkType;    AEKeyword junkKeyword;    Size junkSize;    OSErr osErr;    osErr = AECountItems(&reply->selection, &itemCount);    if( itemCount != 1 )	/* we only work with one object at a time */        osErr = paramErr;    if( osErr == noErr )        osErr = AEGetNthPtr(&reply->selection, 1, typeFSS, &junkKeyword, &junkType, &fss, sizeof(fss), &junkSize);    if( osErr == noErr )    {        mycheck(junkType == typeFSS);        mycheck(junkSize == sizeof(FSSpec));        /* We call FSMakeFSSpec because sometimes Nav is braindead		*/        /* and gives us an invalid FSSpec (where the name is empty).	*/        /* While FSpMakeFSRef seems to handle that (and the file system	*/        /* engineers assure me that that will keep working (at least	*/        /* on traditional Mac OS) because of the potential for breaking	*/        /* existing applications), I'm still wary of doing this so		*/        /* I regularise the FSSpec by feeding it through FSMakeFSSpec.	*/        if( fss.name[0] == 0 )            osErr = FSMakeFSSpec(fss.vRefNum, fss.parID, fss.name, &fss);        if( osErr == noErr )            osErr = FSpMakeFSRef(&fss, item);    }    return osErr;}
¿ª·¢ÕßID:fruitsamples£¬ÏîÄ¿Ãû³Æ:FSCopyObject£¬´úÂëÐÐÊý:36£¬


ʾÀý10: strcpyFileSystemRepresentationFromClassicPath

static OSStatus strcpyFileSystemRepresentationFromClassicPath(char *nativePath, char * classicPath, long nativePathMaxLength ){		CFURLRef   fileAsCFURLRef = 0;		Boolean    resolveAgainstBase = true;		FSRef fileAsFSRef;		Boolean gotPath;		char pathPStr[256];		FSSpec spec;		OSStatus err = 0;				strcpy(pathPStr,classicPath);		my_c2pstr(pathPStr);		err = FSMakeFSSpec(0, 0, (StringPtr)pathPStr,&spec);		if(err == fnfErr) {			// just means the file does not exist yet			err = FSpCreate (&spec,'MPW ','TEXT',smSystemScript); // we should be able to use any creator and type here		}		if(err) return err;				err = FSpMakeFSRef(&spec,&fileAsFSRef);		if(err) return err;		 // Convert the reference to the file to a CFURL		fileAsCFURLRef = CFURLCreateFromFSRef(NULL, &fileAsFSRef);		if(fileAsCFURLRef) {			gotPath = CFURLGetFileSystemRepresentation(fileAsCFURLRef,resolveAgainstBase,(UInt8 *)nativePath,nativePathMaxLength);			CFRelease(fileAsCFURLRef); fileAsCFURLRef = 0;		}				if(gotPath) 			return noErr;				return -1; // did not get the path}
¿ª·¢ÕßID:JamesMakela-NOAA£¬ÏîÄ¿Ãû³Æ:PyGnome£¬´úÂëÐÐÊý:35£¬


ʾÀý11: spec2path

static OSStatus spec2path(const FSSpec& spec, char* path, UInt32 maxPathSize){    FSRef ref;    OSStatus status = FSpMakeFSRef(&spec, &ref);    if (status == noErr)        status = ref2path(ref, path, maxPathSize);    return status;}
¿ª·¢ÕßID:binoc-software£¬ÏîÄ¿Ãû³Æ:mozilla-cvs£¬´úÂëÐÐÊý:8£¬


ʾÀý12: PathToFile

/* FSSpec -> FSRef -> URL(Unix) -> HPFS+ */int PathToFile(char *pathName, int pathNameMax, FSSpec *where,UInt32 encoding) {                CFURLRef sillyThing;        CFStringRef filePath;        FSSpec	failureRetry;        FSRef	theFSRef;        OSErr	error;        Boolean isDirectory=false,retryWithDirectory=false;        char	rememberName[256];                *pathName = 0x00;        error = FSpMakeFSRef (where, &theFSRef);        if (error != noErr) {            retryWithDirectory = true;            failureRetry = *where;            CopyCStringToPascal(":",failureRetry.name);            CopyPascalStringToC(where->name,(char *) &rememberName);            error = FSpMakeFSRef(&failureRetry,&theFSRef);            if (error != noErr)                 return -1;	}                sillyThing =  CFURLCreateFromFSRef (kCFAllocatorDefault, &theFSRef);        isDirectory = CFURLHasDirectoryPath(sillyThing);                filePath = CFURLCopyFileSystemPath (sillyThing, kCFURLHFSPathStyle);        CFRelease(sillyThing);          		CFMutableStringRef mutableStr= CFStringCreateMutableCopy(NULL, 0, filePath);          CFRelease(filePath);    		// HFS+ imposes Unicode2.1 decomposed UTF-8 encoding on all path elements  		if (gCurrentVMEncoding == kCFStringEncodingUTF8)   			CFStringNormalize(mutableStr, kCFStringNormalizationFormKC); // pre-combined            CFStringGetCString (mutableStr, pathName,pathNameMax, encoding);                if (retryWithDirectory) {            strcat(pathName,":");            strcat(pathName,rememberName);            isDirectory = false;        }        if (isDirectory)            strcat(pathName,":");        return 0;}
¿ª·¢ÕßID:fniephaus£¬ÏîÄ¿Ãû³Æ:squeak£¬´úÂëÐÐÊý:46£¬


ʾÀý13: wxMacFSSpec2MacFilename

wxString wxMacFSSpec2MacFilename( const FSSpec *spec ){    FSRef fsRef ;    if ( FSpMakeFSRef( spec , &fsRef) == noErr )    {        return wxMacFSRefToPath( &fsRef ) ;    }    return wxEmptyString ;}
¿ª·¢ÕßID:mheinsen£¬ÏîÄ¿Ãû³Æ:wxWidgets£¬´úÂëÐÐÊý:9£¬


ʾÀý14: FolderIconCheck

/* ¥Õ¥©¥ë¥À¥¢¥¤¥³¥ó¤ò¥Á¥§¥Ã¥¯ */OSErr FolderIconCheck(const FSSpec *theFolderSpec,short *alertMode){	OSErr	err;	long	dirID;	FSSpec	theIconFile;	Str15	iconFileName;	Boolean	isDirectory;	#ifdef __MOREFILESX__	FSRef	fsRef;	FinderInfo	info;		err = FSpMakeFSRef(theFolderSpec,&fsRef);	if (err != noErr) return err;	#else	DInfo	dirInfo;	#endif		/* ¤Þ¤º¡¢¥«¥¹¥¿¥à¥¢¥¤¥³¥ó¥Õ¥é¥°¤¬Á¢¤Ã¤Æ¤¤¤ë¤«¤É¤¦¤«¤ò
C++ FStrEqº¯Êý´úÂëʾÀý
C++ FS_Writeº¯Êý´úÂëʾÀý
ÍòÊÂOK×ÔÑ§Íø£º51×ÔÑ§Íø_Èí¼þ×ÔÑ§Íø_CAD×ÔÑ§Íø×Ôѧexcel¡¢×ÔѧPS¡¢×ÔѧCAD¡¢×ÔѧCÓïÑÔ¡¢×Ôѧcss3ʵÀý£¬ÊÇÒ»¸öͨ¹ýÍøÂç×ÔÖ÷ѧϰ¹¤×÷¼¼ÄܵÄ×Ôѧƽ̨£¬ÍøÓÑϲ»¶µÄÈí¼þ×ÔÑ§ÍøÕ¾¡£