コード例 #1
0
unichar_t *_GioMacMime(const char *path) {
    /* If we're on a mac, we can try to see if we've got a real resource fork */
    FSRef ref;
    FSCatalogInfo info;

    if ( FSPathMakeRef( (uint8 *) path,&ref,NULL)!=noErr )
return( NULL );
    if ( FSGetCatalogInfo(&ref,kFSCatInfoFinderInfo,&info,NULL,NULL,NULL)!=noErr )
return( NULL );
    if ( ((FInfo *) (info.finderInfo))->fdType==CHR('F','F','I','L') )
return( fontmacsuit );
    if ( ((FInfo *) (info.finderInfo))->fdType==CHR('G','I','F','f') )
return( imagegif );
    if ( ((FInfo *) (info.finderInfo))->fdType==CHR('P','N','G',' ') )
return( imagepng );
/*
    if ( ((FInfo *) (info.finderInfo))->fdType==CHR('B','M','P',' ') )
return( imagebmp );
*/
    if ( ((FInfo *) (info.finderInfo))->fdType==CHR('J','P','E','G') )
return( imagejpeg );
/*
    if ( ((FInfo *) (info.finderInfo))->fdType==CHR('T','I','F','F') )
return( imagetiff );
*/
    if ( ((FInfo *) (info.finderInfo))->fdType==CHR('T','E','X','T') )
return( textplain );

return( NULL );
}
コード例 #2
0
ファイル: sqMacFileLogic.c プロジェクト: fniephaus/squeak
OSErr makeFSSpec(char *pathString, int pathStringLength,FSSpec *spec)
{	
    CFURLRef    sillyThing;
    CFStringRef tmpStrRef;
	CFMutableStringRef filePath;
    FSRef	theFSRef;
    OSErr	err;
    
    tmpStrRef = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *) pathString,
										pathStringLength, gCurrentVMEncoding, true);
    if (tmpStrRef == nil)
        return -1000;
	filePath = CFStringCreateMutableCopy(NULL, 0, tmpStrRef);
	if (gCurrentVMEncoding == kCFStringEncodingUTF8) 
		CFStringNormalize(filePath, kCFStringNormalizationFormD);
    sillyThing = CFURLCreateWithFileSystemPath (kCFAllocatorDefault,filePath,kCFURLHFSPathStyle,false);
	if (sillyThing == NULL) 
		return -2000;
		
    if (CFURLGetFSRef(sillyThing,&theFSRef) == false) {
        // name contains multiple aliases or does not exist, so fallback to lookupPath
        CFRelease(filePath);
        CFRelease(sillyThing);
        return lookupPath(pathString,pathStringLength,spec,true,true);
    } 
            
    CFRelease(filePath);
    err = FSGetCatalogInfo (&theFSRef,kFSCatInfoNone,nil,nil,spec,nil);
    CFRelease(sillyThing);
    return err;
}
コード例 #3
0
ファイル: nav_serve.c プロジェクト: prophile/dim3
Boolean nav_file_filter(AEDesc *theItem,void *info,void *callBackUD,NavFilterModes filterMode)
{
    char					*c,filename[256];
    NavFileOrFolderInfo		*filefolder;
    AEDesc					desc;
	HFSUniStr255			uniname;
    CFStringRef				cfstr;
    FSRef					fref;
    
    if ((theItem->descriptorType!=typeFSS) && (theItem->descriptorType!=typeFSRef)) return(FALSE);

    filefolder=(NavFileOrFolderInfo*)info;
    if (filefolder->isFolder) return(TRUE);

	AECoerceDesc(theItem,typeFSRef,&desc);
	AEGetDescData(&desc,(void*)&fref,sizeof(FSRef));
    AEDisposeDesc(&desc);

    FSGetCatalogInfo(&fref,kFSCatInfoNone,NULL,&uniname,NULL,NULL);
	cfstr=CFStringCreateWithCharacters(kCFAllocatorDefault,uniname.unicode,uniname.length);
	CFStringGetCString(cfstr,filename,256,kCFStringEncodingMacRoman);
    CFRelease(cfstr);
    
    c=strchr(filename,'.');
    if (c==NULL) return(FALSE);
    
    return(strcasecmp((c+1),nav_filetype)==0);
}
コード例 #4
0
ファイル: MacIcons.cpp プロジェクト: prestocore/browser
OpBitmap* GetAttachmentIconOpBitmap(const uni_char* filename, BOOL big_attachment_icon, int iSize)
{
	int 		cx, cy;
	OpBitmap* 	result = 0;
	SInt16		label;
	IconRef		iconRef;

	FSRef fsref;
	if(OpFileUtils::ConvertUniPathToFSRef(filename, fsref))
	{
		FSCatalogInfo 	info;

		if(noErr == FSGetCatalogInfo(&fsref, kIconServicesCatalogInfoMask, &info, NULL, NULL, NULL))
		{
			if(noErr == GetIconRefFromFileInfo(&fsref, 0, NULL, kIconServicesCatalogInfoMask, &info, kIconServicesNormalUsageFlag, &iconRef, &label))
			{
				if (!iSize)
					cx = cy = big_attachment_icon ? 32 : 16;
				else
					cx = cy = iSize;

				result = CreateOpBitmapFromIcon(iconRef, cx, cy);
				ReleaseIconRef(iconRef);
			}
		}
	}

	return result;
}
コード例 #5
0
ファイル: osx.cpp プロジェクト: r0ssar00/platform
int SetFileComment(std::string spath, std::string scomment) {
	const char *path = spath.c_str();
	const char *comment = scomment.c_str();
	OSErr err = noErr;
	FSRef fileRef;
	FSSpec fileSpec;

	// see if the file in question exists and we can write it
	if (access(path, R_OK | W_OK | F_OK) == - 1) {
		return 1;
	}

	// get file reference from path
	err = FSPathMakeRef( (const UInt8 *) path, &fileRef, NULL);
	if (err != noErr) {
		return 1;
	}

	// retrieve filespec from file ref
	err = FSGetCatalogInfo(&fileRef, NULL, NULL, NULL, &fileSpec, NULL);
	if (err != noErr) {
		return 1;
	}
	// being by setting MacOS X Finder Comment
	Str255 pCommentStr;
	CopyCStringToPascal(comment, pCommentStr);
	err = MoreFESetComment(&fileSpec, pCommentStr, NULL);
	if (err != noErr) {
		return 1;
	}
	return 0;
}
コード例 #6
0
ファイル: ftmac.c プロジェクト: 32767/libgdx
  FT_GetFile_From_Mac_ATS_Name( const char*  fontName,
                                FSSpec*      pathSpec,
                                FT_Long*     face_index )
  {
#if ( __LP64__ ) || ( defined( MAC_OS_X_VERSION_10_5 ) && \
      ( MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 ) )
    FT_UNUSED( fontName );
    FT_UNUSED( pathSpec );
    FT_UNUSED( face_index );

    return FT_Err_Unimplemented_Feature;
#else
    FSRef     ref;
    FT_Error  err;


    err = FT_GetFileRef_From_Mac_ATS_Name( fontName, &ref, face_index );
    if ( FT_Err_Ok != err )
      return err;

    if ( noErr != FSGetCatalogInfo( &ref, kFSCatInfoNone, NULL, NULL,
                                    pathSpec, NULL ) )
      return FT_Err_Unknown_File_Format;

    return FT_Err_Ok;
#endif
  }
コード例 #7
0
ファイル: filepath.c プロジェクト: karstenw/frontier
boolean getfsvolume ( const ptrfilespec fs, long *vnum ) {
	
	//
	// 2006-07-12 creedon: for Mac, FSRef-ized
	//
	// 5.1.5b11 dmb:	get the volume that is actually specified in the fspec.
	//
	//					don't expand partial paths using the default directory.
	//

	#ifdef MACVERSION
	
		FSCatalogInfo catalogInfo;
		OSErr err = FSGetCatalogInfo ( &fs->ref, kFSCatInfoVolume, &catalogInfo, NULL, NULL, NULL );
		
		if ( catalogInfo.volume == 0 )
			return ( false );
		
		*vnum = catalogInfo.volume;

		return ( err == noErr );
		
	#endif
	
	#ifdef WIN95VERSION

		*vnum = 0;
	
		return ( true );
		
	#endif
	
	} // getfsvolume
コード例 #8
0
bool	HLFileSystemObject::IsVolume() const
{
	FSCatalogInfo theCatalogInfo;
	OSStatus theError = FSGetCatalogInfo(&mFSRef, kFSCatInfoNodeFlags | kFSCatInfoNodeID, &theCatalogInfo, NULL, NULL, NULL);
	ThrowIfError(theError, CAException(theError), "HLFileSystemObject::IsVolume: couldn't get the catalog info");
	return ((theCatalogInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0) && (theCatalogInfo.nodeID == fsRtDirID);
}
コード例 #9
0
bool	HLFileSystemObject::IsFile() const
{
	FSCatalogInfo theCatalogInfo;
	OSStatus theError = FSGetCatalogInfo(&mFSRef, kFSCatInfoNodeFlags, &theCatalogInfo, NULL, NULL, NULL);
	ThrowIfError(theError, CAException(theError), "HLFileSystemObject::IsFile: couldn't get the catalog info");
	return (theCatalogInfo.nodeFlags & kFSNodeIsDirectoryMask) == 0;
}
コード例 #10
0
static OSStatus MyIsVisibleFile(const FSRef *ref, Boolean *visible)
	// Determine whether a ref points to a visible file.
	//
	// I really want to call LSCopyItemInfoForRef and test the resulting 
	// flags for kLSItemInfoIsInvisible and kLSItemInfoIsPlainFile, but 
	// if I do that I have to take a dependency on Launch Services, which 
	// is part of ApplicationServices.framework [3101095].  That's not 
	// acceptable, because this code is commonly used in a setuid root helper 
	// tool and such a tool should depend on the minimal set of services, 
	// so I roll my own visibility test code.
{
	OSStatus		err;
	FSCatalogInfo 	info;
	HFSUniStr255  	name;
	
	assert(ref != NULL);
	assert(visible != NULL);
	
	err = FSGetCatalogInfo(ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, &name, NULL, NULL);
	if (err == noErr) {
		*visible =     ((info.nodeFlags & kFSNodeIsDirectoryMask) == 0) 					// file
					&& ((((FInfo *) &info.finderInfo[0])->fdFlags & kIsInvisible) == 0)		// visible
					&& (name.unicode[0] != '.');											// doesn't begin with .
	}
	return err;
}
コード例 #11
0
ファイル: ae.c プロジェクト: AdminCNP/appscript
static PyObject *AE_GetAppTerminology(PyObject* self, PyObject* args)
{
#if defined(__LP64__)
	PyErr_SetString(PyExc_NotImplementedError,
					"aem.ae.getappterminology isn't available in 64-bit processes.");
	return NULL;
#else
	static ComponentInstance defaultComponent;
	FSRef fsRef;
	FSSpec fss;
	AEDesc theDesc;
	Boolean didLaunch;
	OSAError err;
	
	if (!PyArg_ParseTuple(args, "O&", AE_GetFSRef, &fsRef))
		return NULL;
	err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &fss, NULL);
    if (err != noErr) return AE_MacOSError(err);
	if (!defaultComponent) {
		defaultComponent = OpenDefaultComponent(kOSAComponentType, 'ascr');
		err = GetComponentInstanceError(defaultComponent);
		if (err) return AE_MacOSError(err);
	}
	err = OSAGetAppTerminology(defaultComponent, 
							   kOSAModeNull,
							   &fss, 
							   0, 
							   &didLaunch, 
							   &theDesc);
	if (err) return AE_MacOSError(err);
	return BuildTerminologyList(&theDesc, typeAETE);
#endif
}
コード例 #12
0
void ofxQtAudioRecorder::createMovie(string url, int sampleRate, int numChannels){
	
	OSErr					err = noErr;
	FSRef					fsref;
	Boolean					isdir;
	
	// full data path
	url = ofToDataPath(url, true);
	
	// kill a file and make a new one if needed:	
	FILE * pFile;
	pFile = fopen (url.c_str(),"w");
	fclose (pFile);
	
	// create path reference
	err = FSPathMakeRef((const UInt8*)url.c_str(), &fsref, &isdir);
	if (err) { printf("FSPathMakeRef failed %d\n", err); printf("ERROR creating movie \n"); return; }
	
	// create file spec
	err = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &myFileSpec, NULL);
	if (err) { printf("FSGetCatalogInfo failed %d\n", err); printf("ERROR creating movie \n"); return; }
	
	// create that movie file
	err = CreateMovieFile(&myFileSpec, 'TVOD', smCurrentScript, createMovieFileDeleteCurFile | createMovieFileDontCreateResFile, &movieResRefNum, &movie);
	if(err) {
		printf("error: failed to create movie file\n");
		return;
	}
	
	prepareAudioRecording(sampleRate, numChannels);
}
コード例 #13
0
ファイル: dosio.cpp プロジェクト: FREEWING-JP/np2pi
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);
}
コード例 #14
0
void QStorageInfoPrivate::retrieveLabel()
{
#if !defined(Q_OS_IOS)
	// deprecated since 10.8
	FSRef ref;
	FSPathMakeRef(reinterpret_cast<const UInt8*>(QFile::encodeName(rootPath).constData()),
	              &ref,
	              Q_NULLPTR);
	// deprecated since 10.8
	FSCatalogInfo catalogInfo;
	OSErr error;
	error = FSGetCatalogInfo(&ref, kFSCatInfoVolume, &catalogInfo, Q_NULLPTR, Q_NULLPTR, Q_NULLPTR);

	if (error != noErr)
	{
		return;
	}

	// deprecated (use CFURLCopyResourcePropertiesForKeys for 10.7 and higher)
	HFSUniStr255 volumeName;
	error = FSGetVolumeInfo(catalogInfo.volume,
	                        0,
	                        Q_NULLPTR,
	                        kFSVolInfoFSInfo,
	                        Q_NULLPTR,
	                        &volumeName,
	                        Q_NULLPTR);

	if (error == noErr)
	{
		name = QCFString(FSCreateStringFromHFSUniStr(Q_NULLPTR, &volumeName));
	}

#endif
}
コード例 #15
0
void fixmacfile(char *filename)
{
  FInfo  fndrinfo;
#ifdef OSX_CARBON
  FSSpec fileSpec;
  FSRef fileRef;

  FSPathMakeRef((unsigned char *)filename, &fileRef, NULL);
  FSGetCatalogInfo(&fileRef, kFSCatInfoNone, NULL, NULL, &fileSpec, NULL);
  FSpGetFInfo(&fileSpec, &fndrinfo);
  fndrinfo.fdType='TEXT';
  fndrinfo.fdCreator='MSWD';
  FSpSetFInfo(&fileSpec, &fndrinfo);

#else
  char filename1[FNMLNGTH];
  char filename2[FNMLNGTH];
  strcpy(filename1,filename);
  strcpy(filename2,filename);
  getfinfo(filename1,0,&fndrinfo);
  fndrinfo.fdType='TEXT';
  fndrinfo.fdCreator='MSWD';
  setfinfo(filename2,0,&fndrinfo);
#endif
}
コード例 #16
0
    void Initialize(const std::string& location) {
	path_ = CFStringCreateWithCString(kCFAllocatorDefault, location.c_str(), kCFStringEncodingUTF8);
	if(!path_) {
	    std::cout << "KotoeriImpl: CFStringCreateCopy() failed" << std::endl;
	    return;
	}

	FSSpec spec;
	FSRef fileRef;
	CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, path_, kCFURLPOSIXPathStyle, false);
	OSErr err = !noErr;
	if(CFURLGetFSRef(url, &fileRef)) {
	    err = FSGetCatalogInfo(&fileRef, kFSCatInfoNone, NULL, NULL, &spec, NULL);
	}
	if(url) CFRelease(url);
	if(err != noErr) {
	    return;
	}

	if(DCMGetDictionaryIDFromFile(&spec, &id_) != noErr) {
	    std::cout << "DCMGetDictionaryIDFromFile() failed" << std::endl;
	    if(DCMRegisterDictionaryFile(&spec, &id_) != noErr) {
		std::cout << "DCMRegisterDictionaryFile() failed" << std::endl;
		return;
	    }
	    isRegistered_ = true;
	}
    }
コード例 #17
0
ファイル: HLDirectory.cpp プロジェクト: fruitsamples/HAL
bool	HLDirectoryFactory::ObjectIsA(const FSRef& inFSRef) const
{
	FSCatalogInfo theCatalogInfo;
	OSStatus theError = FSGetCatalogInfo(&inFSRef, kFSCatInfoNodeFlags, &theCatalogInfo, NULL, NULL, NULL);
	ThrowIfError(theError, CAException(theError), "HLDirectoryFactory::ObjectIsA: couldn't get the catalog info");
	return (theCatalogInfo.nodeFlags & kFSNodeIsDirectoryMask) != 0;
}
コード例 #18
0
ファイル: main.c プロジェクト: specious/osxutils
static void PrintOSXComment (char *path)
{
	OSErr	err = noErr;
    FSRef	fileRef;
    FSSpec	fileSpec;
	Str255	comment = "\p";
	char	cStrCmt[255] = "\0";
	AEIdleUPP inIdleProc = NewAEIdleUPP(&MyAEIdleCallback);

    ///////////// Make sure we can do as we please :) /////////////

            //see if the file in question exists and we can write it
            if (access(path, R_OK|F_OK) == -1)
            {
				perror(path);
                return;
            }

            //get file reference from path
            err = FSPathMakeRef(path, &fileRef, NULL);
            if (err != noErr)
            {
				fprintf(stderr, "FSPathMakeRef: Error %d for file %s\n", err, path);
                return;
            }

            //retrieve filespec from file ref
            err = FSGetCatalogInfo (&fileRef, NULL, NULL, NULL, &fileSpec, NULL);
            if (err != noErr)
            {
				fprintf(stderr, "FSGetCatalogInfo(): Error %d getting file spec for %s\n", err, path);
                return;
            }


    ///////////// oK, now we can go about getting the comment /////////////

	// call the apple event routine. I'm not going to pretend I understand what's going on
	// in all those horribly kludgy functions, but at least it works.
	err = MoreFEGetComment(&fileRef, &fileSpec, comment, inIdleProc);
	if (err)
	{
		fprintf(stderr, "Error %d getting comment for '%s'\n", err, path);
		if (err == -600)
			fprintf(stderr, "Finder is not running\n", err);//requires Finder to be running
		return;
	}
	//convert pascal string to c string
	strncpy((char *)&cStrCmt, (unsigned char *)&comment+1, comment[0]);
	//if there is no comment, we don't print out anything
	if (!strlen((char *)&cStrCmt))
		return;

	//print out the comment
	if (!printFileName)
			printf("%s\n", (char *)&cStrCmt);
		else
			printf("Comment for '%s':\n%s\n", path, (char *)&cStrCmt);
}
コード例 #19
0
ファイル: filefn.cpp プロジェクト: mheinsen/wxWidgets
void wxMacFilename2FSSpec( const wxString& path , FSSpec *spec )
{
    OSStatus err = noErr;
    FSRef fsRef;
    wxMacPathToFSRef( path , &fsRef );
    err = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, spec, NULL);
    verify_noerr( err );
}
コード例 #20
0
ファイル: qcore_mac.cpp プロジェクト: maxxant/qt
// Don't use this function, it won't work in 10.5 (Leopard) and up
OSErr qt_mac_create_fsspec(const QString &file, FSSpec *spec)
{
    FSRef fsref;
    OSErr ret = qt_mac_create_fsref(file, &fsref);
    if (ret == noErr)
        ret = FSGetCatalogInfo(&fsref, kFSCatInfoNone, 0, 0, spec, 0);
    return ret;
}
コード例 #21
0
bool 	createMovieFromPath(char * path, Movie &movie){



	Boolean 	isdir			= false;
	OSErr 		result 			= 0;
	FSSpec 		theFSSpec;

	short 		actualResId 	= DoTheRightThing;

	#ifdef TARGET_WIN32
		result = NativePathNameToFSSpec (path, &theFSSpec, 0);
		if (result != noErr) {
			ofLog(OF_LOG_ERROR,"NativePathNameToFSSpec failed %d", result);
			ofLog(OF_LOG_ERROR,"Error loading movie");
			return false;
		}

	#endif



	#ifdef TARGET_OSX
		FSRef 		fsref;
		result = FSPathMakeRef((const UInt8*)path, &fsref, &isdir);
		if (result) {
			ofLog(OF_LOG_ERROR,"FSPathMakeRef failed %d", result);
			ofLog(OF_LOG_ERROR,"Error loading movie");
			return false;
		}
		result = FSGetCatalogInfo(&fsref, kFSCatInfoNone, NULL, NULL, &theFSSpec, NULL);
		if (result) {
			ofLog(OF_LOG_ERROR,"FSGetCatalogInfo failed %d", result);
			ofLog(OF_LOG_ERROR,"Error loading movie");
			return false;
		}
	#endif


	short movieResFile;
	result = OpenMovieFile (&theFSSpec, &movieResFile, fsRdPerm);
	if (result == noErr) {

		short   movieResID = 0;
		result = NewMovieFromFile(&movie, movieResFile, &movieResID, (unsigned char *) 0, newMovieActive, (Boolean *) 0);
		if (result == noErr){
			CloseMovieFile (movieResFile);
		} else {
			ofLog(OF_LOG_ERROR,"NewMovieFromFile failed %d", result);
			return false;
		}
	} else {
		ofLog(OF_LOG_ERROR,"OpenMovieFile failed %d", result);
		return false;
	}

	return true;
}
コード例 #22
0
ファイル: dosio.cpp プロジェクト: FREEWING-JP/np2pi
short file_attr(const char *path) {

#ifdef TARGET_API_MAC_CARBON
	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);
#else
	Str255		fname;
	FSSpec		fss;
	CInfoPBRec	pb;
	short		ret;

	mkstr255(fname, path);
	FSMakeFSSpec(0, 0, fname, &fss);
	pb.dirInfo.ioNamePtr = fss.name;
	pb.dirInfo.ioVRefNum = fss.vRefNum;
	pb.dirInfo.ioDrDirID = fss.parID;
	if (fss.name[0] == 0) {
		pb.dirInfo.ioFDirIndex = -1;
	}
	else {
		pb.dirInfo.ioFDirIndex = 0;
	}
	if (PBGetCatInfo(&pb, false) != noErr) {
		return(-1);
	}
	if (pb.hFileInfo.ioFlAttrib & ioDirMask) {
		ret = FILEATTR_DIRECTORY;
	}
	else {
		ret = FILEATTR_ARCHIVE;
	}
	if (pb.hFileInfo.ioFlAttrib & 0x01) {
		ret |= FILEATTR_READONLY;
	}
	return(ret);
#endif
}
コード例 #23
0
OSErr getFInfoViaFSRef(FSRef *theFSRef,	FInfo *finderInfo) {
   OSErr	err;
	FSCatalogInfo catInfo;
	
	err = FSGetCatalogInfo (theFSRef,kFSCatInfoFinderInfo,&catInfo,nil,nil,nil);
	memcpy(finderInfo,&catInfo.finderInfo,sizeof(FInfo));	
	return err;
	
}
コード例 #24
0
FBL_Begin_Namespace


/**********************************************************************************************/
#if FBL_MAC


/**********************************************************************************************/
// NOTE:  fullPath to item that EXISTS on disk. Otherwise file not found error.
//
#if FBL_SUPPORT_FSSPEC
//
OSErr Path2Spec_FSRef( const char *inPath, FSSpec *spec)
{
	// parse path on parent folder and file name. 
	const char* pFileName = ExtractNameFromFullPath(inPath);
	const char* pDelim = pFileName - 1;

//	String folder_path( inPath, vuint32(pDelim - inPath) );

	vuint32 len;
	if( pDelim >= inPath )
		len = vuint32(pDelim - inPath);
	else
		len = strlen( inPath );
	
	MemPtr<char> folder_path( inPath, len + 1 );
	folder_path[len] = 0;
	
	char* pFolderPath = folder_path.begin();
	
	// convert the POSIX path to an FSRef of parent folder 
	FSRef ref;
	OSStatus result = FSPathMakeRef( (vuint8*) pFolderPath, &ref, NULL);
	
	if( result != 0 )
		return (OSErr) result;

	// and then convert the FSRef to an FSSpec 
	FSSpec parent;
	result = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &parent, NULL);
	if( result != 0 )
		return (OSErr) result;

	// now we have parent folder FSSpec, get its ID. 
	vint32 theDirID;
	bool isDirectory;
	GetDirectoryID( parent.vRefNum, parent.parID, parent.name, &theDirID, &isDirectory );
	
	// and now we make File spec:
	Str255 pasFileName;
	FBL::c2pstrcpy( pFileName, pasFileName );
	result = FSMakeFSSpec( parent.vRefNum, theDirID, pasFileName, spec );
	
	return (OSErr) result;
}
コード例 #25
0
int main(int argc, char **argv) {
	if (argc < 2) {
		printf("Usage: %s <save file>\n", argv[0]);
		printf("Applies the creator and type codes so the save can be used\n");
		printf("by the original interpreter.\n");
		return 0;
	}

	uint32 creator, type;

	// First, let's open our file to make sure it's a pegasus save
	// Also, we're going to extract what type we need to set (for the correct disc)
	try {
		Common::File file(argv[1], "rb");

		// Let's make sure the user already gunzip'd the file
		uint16 gzipTest = file.readUint16BE();
		if (gzipTest == 0x1F8B) {
			printf("Please gunzip the save file first\n");
			return 1;
		}

		creator = (gzipTest << 16) | file.readUint16BE(); // Too lazy to seek back :P
		type = file.readUint32BE();

		if (creator != kPegasusCreator) {
			printf("Failed to find pegasus creator in save file\n");
			return 1;
		}

		if (type != kPegasusDisc1 && type != kPegasusDisc2 && type != kPegasusDisc3 && type != kPegasusDisc4) {
			printf("Invalid pegasus save type in save file\n");
			return 1;
		}
	} catch (Common::FileException e) {
		printf("File error: '%s'\n", e.what());
		return 1;
	}

	FSCatalogInfo catInfo;
	FSRef ref;

	if (!FSPathMakeRef((const UInt8 *)argv[1], &ref, false)) {
		FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catInfo, 0, 0, 0);
		FileInfo *info = (FileInfo *)catInfo.finderInfo;
		info->fileCreator = creator;
		info->fileType = type;
		FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &catInfo);
	} else {
		printf("Failed to use File Manager to open the file\n");
		return 1;
	}

	printf("Success!\n");
	return 0;
}
コード例 #26
0
static OSErr getFInfo(char *filename,FSCatalogInfo *catInfo,CFStringEncoding encoding) {
   FSRef	theFSRef;
   OSErr	err;
   
	err =  getFSRef(filename,&theFSRef,encoding);
	if (err != 0)
		return err;
    err = FSGetCatalogInfo (&theFSRef,kFSCatInfoFinderInfo,catInfo,nil,nil,nil);
    return noErr;
}
コード例 #27
0
CFStringRef	HLFileSystemObject::CopyName() const
{
	//	get the whole unicode name from the catalog info
	HFSUniStr255 theUniStr255;
	OSStatus theError = FSGetCatalogInfo(&mFSRef, kFSCatInfoNone, NULL, &theUniStr255, NULL, NULL);
	ThrowIfError(theError, CAException(theError), "HLFileSystemObject::CopyName: couldn't get the catalog information");
	
	//	make a CFString with it
	return CFStringCreateWithCharacters(NULL, theUniStr255.unicode, theUniStr255.length);
}
コード例 #28
0
ファイル: mkalias.c プロジェクト: specious/osxutils
static OSErr FSGetFInfo(const FSRef* ref, FInfo *fInfo) {
  FSCatalogInfo cinfo;
  OSErr err = FSGetCatalogInfo(ref, kFSCatInfoFinderInfo, &cinfo, NULL, NULL, NULL);

  if (err != noErr)
    return err;

  *fInfo = *(FInfo*)cinfo.finderInfo;
  return err;
}
コード例 #29
0
ファイル: main.cpp プロジェクト: arnelh/Examples
OSStatus PathToFSSpec(const char *filename, FSSpec &outSpec)
{	
	FSRef fsRef;
	OSStatus result;
	require_noerr (result = FSPathMakeRef ((const UInt8*)filename, &fsRef, 0), home);
	require_noerr (result = FSGetCatalogInfo(&fsRef, kFSCatInfoNone, NULL, NULL, &outSpec, NULL), home);

home:
	return result;
}
コード例 #30
0
static bool isPackage(const QFileSystemMetaData &data, const QFileSystemEntry &entry)
{
    if (!data.isDirectory())
        return false;

    QFileInfo info(entry.filePath());
    QString suffix = info.suffix();

    if (suffix.length() > 0) {
        // First step: is the extension known ?
        CFStringRef extensionRef = QCFString::toCFStringRef(suffix);
        CFStringRef uniformTypeIdentifier = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extensionRef, NULL);
        if (UTTypeConformsTo(uniformTypeIdentifier, kUTTypeBundle))
            return true;

        // Second step: check if an application knows the package type
        CFStringRef path = QCFString::toCFStringRef(entry.filePath());
        QCFType<CFURLRef> url = CFURLCreateWithFileSystemPath(0, path, kCFURLPOSIXPathStyle, true);

        UInt32 type, creator;
        // Well created packages have the PkgInfo file
        if (CFBundleGetPackageInfoInDirectory(url, &type, &creator))
            return true;

        // Find if an application other than Finder claims to know how to handle the package
        QCFType<CFURLRef> application;
        LSGetApplicationForURL(url,
                               kLSRolesEditor|kLSRolesViewer|kLSRolesViewer,
                               NULL,
                               &application);

        if (application) {
            QCFType<CFBundleRef> bundle = CFBundleCreate(kCFAllocatorDefault, application);
            CFStringRef identifier = CFBundleGetIdentifier(bundle);
            QString applicationId = QCFString::toQString(identifier);
            if (applicationId != QLatin1String("com.apple.finder"))
                return true;
        }
    }

    // Third step: check if the directory has the package bit set
    FSRef packageRef;
    FSPathMakeRef((UInt8 *)entry.nativeFilePath().constData(), &packageRef, NULL);

    FSCatalogInfo catalogInfo;
    FSGetCatalogInfo(&packageRef,
                     kFSCatInfoFinderInfo,
                     &catalogInfo,
                     NULL,
                     NULL,
                     NULL);

    FolderInfo *folderInfo = reinterpret_cast<FolderInfo *>(catalogInfo.finderInfo);
    return folderInfo->finderFlags & kHasBundle;
}