Exemplo n.º 1
0
static PyObject *Res_HOpenResFile(PyObject *_self, PyObject *_args)
{
    PyObject *_res = NULL;
    short _rv;
    short vRefNum;
    long dirID;
    Str255 fileName;
    SignedByte permission;
#ifndef HOpenResFile
    PyMac_PRECHECK(HOpenResFile);
#endif
    if (!PyArg_ParseTuple(_args, "hlO&b",
                          &vRefNum,
                          &dirID,
                          PyMac_GetStr255, fileName,
                          &permission))
        return NULL;
    _rv = HOpenResFile(vRefNum,
                       dirID,
                       fileName,
                       permission);
    {
        OSErr _err = ResError();
        if (_err != noErr) return PyMac_Error(_err);
    }
    _res = Py_BuildValue("h",
                         _rv);
    return _res;
}
Exemplo n.º 2
0
P2 (PUBLIC pascal trap, INTEGER, FSpOpenResFile,
    FSSpecPtr, spec, SignedByte, perms)
{
    INTEGER retval;

    retval = HOpenResFile (CW (spec->vRefNum), CL (spec->parID), spec->name,
                           perms);
    return retval;
}
Exemplo n.º 3
0
short HOpenResFilePath(
	short vRefNum,
	long dirID,
	ConstStr255Param fileName,
	char permission,
	short resource_number)
{
	short hndl= HOpenResFile(vRefNum, dirID, fileName, permission);
	short path_count= countstr(resource_number);
	Str255 new_filename;
	short i;
	
	for (i= 0; i<path_count && hndl==NONE; ++i)
	{
		getpstr((char *)new_filename, resource_number, i);
		pstrcat(new_filename, (unsigned char *) fileName);
		
		hndl= HOpenResFile(0, 0, new_filename, permission);
	}
	
	return hndl;
}
Exemplo n.º 4
0
pascal	short	FSpOpenResFileCompat(const FSSpec *spec,
                                     SignedByte permission)
{
#if !__MACOSSEVENORLATER
    if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() )
    {
        return ( HOpenResFile(spec->vRefNum, spec->parID, spec->name, permission) );
    }
    else
#endif	/* !__MACOSSEVENORLATER */
    {
        return ( FSpOpenResFile(spec, permission) );
    }
}
Exemplo n.º 5
0
static Boolean SearchDirectory( UInt16 volID, UInt32 dirID, UInt8 * targetLang, OSType sig, UInt32 depth )
{	
	Str31		fileName;
	UInt16		fileIndex 	= 1;
	OSErr		err 		= noErr;
	CInfoPBRec	catPb;
	struct LanguageDescriptor ** locaRSRC;
	
	gLocaleResFile = 0;		/* Set locale file to invalid number	*/
		
	while( err == noErr ) {
		catPb.dirInfo.ioCompletion 	= nil;
		catPb.dirInfo.ioNamePtr		= fileName;
		catPb.dirInfo.ioVRefNum		= volID;
		catPb.dirInfo.ioFDirIndex	= fileIndex++;
		catPb.dirInfo.ioDrDirID		= dirID;
		
		err = PBGetCatInfoSync( &catPb );
	
		// If I found a folder, then look inside.  But only go to the specified depth
		if( err == noErr) {			
			if( catPb.dirInfo.ioFlAttrib & (1<<4) ) {	// Look in the folder, if I haven't exceeded the depth
				
				if( depth ) {
					if( SearchDirectory( volID, catPb.dirInfo.ioDrDirID, targetLang, sig, depth - 1 ) )
						return true;		/* A locale file was found, so exit	*/
					else		
						continue;			/* Nothing so far, so keep looking	*/
				}
				else {
					continue;
				}
			}
			else {	// Check if its a locale file
				if( 	catPb.hFileInfo.ioFlFndrInfo.fdType 	== 'LANG'
					&&	catPb.hFileInfo.ioFlFndrInfo.fdCreator 	== 'CARO' ) {
						ASInt16 curLocaleFile;

						/* Fix for 408144.
						** Check for an open resource file.  Skip already open files.
						** If another Plugin has it open this will cause great confusion.
						** Example is "WHA" and "WHA Library".  "WHA Library" close the "WHA lang"
						** file while looking for the "WHA Library lang" file.
						*/
						curLocaleFile = GetResRefNumFromFCB(volID, dirID, fileName);
						if( curLocaleFile != -1  )
							continue;				/* continue on to the next file					*/

						curLocaleFile = HOpenResFile( volID, dirID, fileName, fsCurPerm );

						if( curLocaleFile == -1  )	/* Check for a valid file.  If its bad, then	*/
							continue;				/* continue on to the next file					*/
							
						locaRSRC = (struct LanguageDescriptor **) Get1Resource( 'LOCA', 2010 );
						if( locaRSRC ) {

							if( (*locaRSRC)->mSignature == sig ) {	/* Check the client signature	*/
								
								if( (*locaRSRC)->mLocale3Letters == *( UInt32 * )targetLang )
								{
									gLocaleResFile = curLocaleFile;
								}
							}
						
							ReleaseResource( ( Handle )locaRSRC );
						}
						
						if( gLocaleResFile != curLocaleFile ) {
							CloseResFile( curLocaleFile );	/* Release the locale file	*/
							continue;						/* Didn't find it, so try the next one	*/
						}
						else
							return true;				/* Got it, so exit	*/
				}
			}
		}
	}
	return false;	/* Found nothing	*/
}
Exemplo n.º 6
0
/*
**	GetIconFromDesktopFile
**
**	INPUT a pointer to a non-existent Handle, because we'll allocate one
**
**	search each BNDL resource for the right fileCreator and once we get it
**		find the 'FREF' type in BNDL
**		for each localID in the type, open the FREF resource
**			if the FREF is the desired fileType
**				get its icon localID
**				get the ICN# type in BNDL
**				get the icon resource number from the icon localID
**				get the icon resource type from the desktop mgr's iconType
**				get the icon of that type and number
*/
static	OSErr	GetIconFromDesktopFile(ConstStr255Param volName,
									   short vRefNum,
									   short iconType,
									   OSType fileCreator,
									   OSType fileType,
									   Handle *iconHandle)
{
	OSErr			error;
	short			realVRefNum;
	Str255			desktopName;
	short			savedResFile;
	short			dfRefNum;
	BNDLRecHandle	theBndl = NULL;
	BundleTypePtr	theBundleType;
	short			iconLocalID;
	short			iconRsrcID;
	OSType			iconRsrcType;
	Handle			returnIconHandle;	
	char			bndlState;
	
	*iconHandle = NULL;
	
	error = DetermineVRefNum(volName, vRefNum, &realVRefNum);
	if ( error == noErr )
	{
		error = GetDesktopFileName(realVRefNum, desktopName);
		if ( error == noErr )
		{
			savedResFile = CurResFile();
		
			/*
			**	Open the 'Desktop' file in the root directory. (because
			**	opening the resource file could preload unwanted resources,
			**	bracket the call with SetResLoad(s))
			*/
			SetResLoad(false);
			dfRefNum = HOpenResFile(realVRefNum, fsRtDirID, desktopName, fsRdPerm);
			SetResLoad(true);
		
			if ( dfRefNum != -1 )
			{
				/*
				**	Find the BNDL resource with the specified creator.
				*/
				error = FindBundleGivenCreator(fileCreator, &theBndl);
				if ( error == noErr )
				{
					/* Lock the BNDL resource so it won't be purged when other resources are loaded */
					bndlState = HGetState((Handle)theBndl);
					HLock((Handle)theBndl);
					
					/* Find the 'FREF' BundleType record in the BNDL resource. */
					error = FindTypeInBundle(kFREFResType, theBndl, &theBundleType);
					if ( error == noErr )
					{
						/* Find the local ID in the 'FREF' resource with the specified fileType */
						error = GetLocalIDFromFREF(theBundleType, fileType, &iconLocalID);
						if ( error == noErr )
						{
							/* Find the 'ICN#' BundleType record in the BNDL resource. */
							error = FindTypeInBundle(kIconFamResType, theBndl, &theBundleType);
							if ( error == noErr )
							{
								/* Find the icon's resource ID in the 'ICN#' BundleType record */
								error = GetIconRsrcIDFromLocalID(theBundleType, iconLocalID, &iconRsrcID);
								if ( error == noErr )
								{
									/* Map Desktop Manager icon type to resource type */
									iconRsrcType = DTIconToResIcon(iconType);
									
									if ( iconRsrcType != (OSType)0 )
									{
										/* Load the icon */
										returnIconHandle = Get1Resource(iconRsrcType, iconRsrcID);
										if ( returnIconHandle != NULL )
										{
											/* Copy the resource handle, and return the copy */
											HandToHand(&returnIconHandle);
											if ( MemError() == noErr )
											{
												*iconHandle = returnIconHandle;
											}
											else
											{
												error = afpItemNotFound;
											}
										}
										else
										{
											error = afpItemNotFound;
										}
									}
								}
							}
						}
					}
					/* Restore the state of the BNDL resource */ 
					HSetState((Handle)theBndl, bndlState);
				}
				/* Restore the resource chain and close the Desktop file */
				UseResFile(savedResFile);
				CloseResFile(dfRefNum);
			}
			else
			{
				error = ResError(); /* could not open Desktop file */
			}
		}
		if ( (error != noErr) && (error != memFullErr) )
		{
			error = afpItemNotFound;	/* force an error we should return */
		}
	}
	
	return ( error );
}
Exemplo n.º 7
0
/*
**	GetAPPLFromDesktopFile
**
**	Get a application's location from the
**	Desktop file's 'APPL' resources.
*/
static	OSErr	GetAPPLFromDesktopFile(ConstStr255Param volName,
									   short vRefNum,
									   OSType creator,
									   short *applVRefNum,
									   long *applParID,
									   Str255 applName)
{
	OSErr error;
	short realVRefNum;
	Str255 desktopName;
	short savedResFile;
	short dfRefNum;
	Handle applResHandle;
	Boolean foundCreator;
	Ptr applPtr;
	long applSize;
	
	error = DetermineVRefNum(volName, vRefNum, &realVRefNum);
	if ( error == noErr )
	{
		error = GetDesktopFileName(realVRefNum, desktopName);
		if ( error == noErr )
		{
			savedResFile = CurResFile();
			/*
			**	Open the 'Desktop' file in the root directory. (because
			**	opening the resource file could preload unwanted resources,
			**	bracket the call with SetResLoad(s))
			*/
			SetResLoad(false);
			dfRefNum = HOpenResFile(realVRefNum, fsRtDirID, desktopName, fsRdPerm);
			SetResLoad(true);
			
			if ( dfRefNum != -1)
			{
				/* Get 'APPL' resource ID 0 */
				applResHandle = Get1Resource(kAPPLResType, 0);
				if ( applResHandle != NULL )
				{
					applSize = GetHandleSize((Handle)applResHandle);
					if ( applSize != 0 )	/* make sure the APPL resource isn't empty */
					{
						foundCreator = false;
						applPtr = *applResHandle;
						
						/* APPL's don't have a count so I have to use the size as the bounds */
						while ( (foundCreator == false) &&
								(applPtr < (*applResHandle + applSize)) )
						{
							if ( ((APPLRecPtr)applPtr)->creator == creator )
							{
								foundCreator = true;
							}
							else
							{
								/* fun with pointer math... */
								applPtr += sizeof(OSType) +
										   sizeof(long) +
										   ((APPLRecPtr)applPtr)->applName[0] + 1;
								/* application mappings are word aligned within the resource */
								if ( ((unsigned long)applPtr % 2) != 0 )
								{
									applPtr += 1;
								}
							}
						}
						if ( foundCreator == true )
						{
							*applVRefNum = realVRefNum;
							*applParID = ((APPLRecPtr)applPtr)->parID;
							BlockMoveData(((APPLRecPtr)applPtr)->applName,
										  applName,
										  ((APPLRecPtr)applPtr)->applName[0] + 1);
							/* error is already noErr */
						}
						else
						{
							error = afpItemNotFound;	/* didn't find a creator match */
						}
					}
					else
					{
						error = afpItemNotFound;	/* no APPL mapping available */
					}
				}
				else
				{
					error = afpItemNotFound;	/* no APPL mapping available */
				}
				
				/* restore the resource chain and close the Desktop file */
				UseResFile(savedResFile);
				CloseResFile(dfRefNum);
			}
			else
			{
				error = afpItemNotFound;
			}
		}
	}
	
	return ( error );
}
Exemplo n.º 8
0
/*
**	GetCommentFromDesktopFile
**
**	Get a file or directory's Finder comment field (if any) from the
**	Desktop file's 'FCMT' resources.
*/
static	OSErr	GetCommentFromDesktopFile(short vRefNum,
										  long dirID,
										  ConstStr255Param name,
										  Str255 comment)
{
	OSErr error;
	short commentID;
	short realVRefNum;
	Str255 desktopName;
	short savedResFile;
	short dfRefNum;
	StringHandle commentHandle;
	
	/* Get the comment ID number */
	error = GetCommentID(vRefNum, dirID, name, &commentID);
	if ( error == noErr )
	{
		if ( commentID != 0 )	/* commentID == 0 means there's no comment */
		{
			error = DetermineVRefNum(name, vRefNum, &realVRefNum);
			if ( error == noErr )
			{
				error = GetDesktopFileName(realVRefNum, desktopName);
				if ( error == noErr )
				{
					savedResFile = CurResFile();
					/*
					**	Open the 'Desktop' file in the root directory. (because
					**	opening the resource file could preload unwanted resources,
					**	bracket the call with SetResLoad(s))
					*/
					SetResLoad(false);
					dfRefNum = HOpenResFile(realVRefNum, fsRtDirID, desktopName, fsRdPerm);
					SetResLoad(true);
					
					if ( dfRefNum != -1)
					{
						/* Get the comment resource */
						commentHandle = (StringHandle)Get1Resource(kFCMTResType,commentID);
						if ( commentHandle != NULL )
						{
							if ( GetHandleSize((Handle)commentHandle) > 0 )
							{
								BlockMoveData(*commentHandle, comment, *commentHandle[0] + 1);
							}
							else
							{
								error = afpItemNotFound;	/* no comment available */
							}
						}
						else
						{
							error = afpItemNotFound;	/* no comment available */
						}
						
						/* restore the resource chain and close the Desktop file */
						UseResFile(savedResFile);
						CloseResFile(dfRefNum);
					}
					else
					{
						error = afpItemNotFound;
					}
				}
				else
				{
					error = afpItemNotFound;
				}
			}
		}
		else
		{
			error = afpItemNotFound;	/* no comment available */
		}
	}
	
	return ( error );
}
Exemplo n.º 9
0
  LOCAL_FUNC
  TT_Error  TT_Open_Stream( const String*  filepathname, 
                            TT_Stream*     stream )
  {
    TT_Error     error;
    Int          file;
    PStream_Rec  stream_rec;
    TFileMap*    map;

    int          size, err = 0;
    short        vRefNum, res = -1;
    Str255       FontName;
    char         *cp, *p, *fname, *sep;
    Str63        myName;
    long         dirID;


    if ( ALLOC( *stream, sizeof ( TStream_Rec ) ) )
      return error;

    map = Allocate_Map();
    if ( !map )
    {
      error = TT_Err_Out_Of_Memory;
      goto Memory_Fail;
    }
    
    stream_rec = STREAM2REC( *stream );

    /* Find the dirID of the Fonts folder in the current System folder */
    if (FindFolder(kOnSystemDisk, kFontsFolderType, kDontCreateFolder, &vRefNum, &dirID)) 
        goto File_Fail;

    /* Break the name apart */
    fname = mystrdup(filepathname); /* Make a copy so we can muck with it */
    sep = ":/";     /* Things that can seperate file path componants */
    
    strtok(fname, sep);             /* Skip over "fonts:" */
    
    if ((p = strtok(NULL, sep)) == NULL)        /* Get filename */
        goto File_Fail;
    strcpy(myName + 1, p);                      /* Make this a Pascal string (Yuck!) */
    myName[0] = strlen(p);
     
    if ((p = strtok(NULL, sep)) == NULL)        /* Get res name */
        goto File_Fail;
    strcpy(FontName+1, p);                      /* Make this a Pascal string (Yuck!) */
    FontName[0] = strlen(p);
    
    FREE( fname );
    
    if ((cp = strchr(FontName, '.')) != NULL)   /* Strip off ".ttf" , if any */
        *cp = 0;
    
    /* Read the font into a buffer */
    if ((map->resid = HOpenResFile(vRefNum, dirID, myName, fsRdPerm)) == -1)
        goto File_Fail;
    
    if ((map->handle = Get1NamedResource('sfnt', FontName)) == NULL)
        goto Map_Fail;
    
    HLock(map->handle);
    map->base   = *map->handle;
    map->offset = 0;
    map->size   = GetResourceSizeOnDisk(map->handle);

    if ( map->base == NULL )
        goto Lock_Fail;

    stream_rec->map = map;
    stream_rec->pos = 0;

#ifndef TT_CONFIG_OPTION_THREAD_SAFE
    CUR_Stream = stream_rec;
#endif

    return TT_Err_Ok;

  Lock_Fail:
    ReleaseResource(map->handle);
    
  Map_Fail:
    CloseResFile(map->resid);

  File_Fail:
    error = TT_Err_Could_Not_Open_File;
    FREE( map );

  Memory_Fail:
    FREE( *stream );
    FREE( fname );
    return error;
  }