|
Mac OS 9
|
Resource Manager Interfaces. More...
Go to the source code of this file.
Macros | |
| #define | NewResErrUPP(userRoutine) |
| #define | DisposeResErrUPP(userUPP) DisposeRoutineDescriptor(userUPP) |
| #define | InvokeResErrUPP(thErr, userUPP) CALL_ONE_PARAMETER_UPP((userUPP), uppResErrProcInfo, (thErr)) |
| #define | NewResErrProc(userRoutine) NewResErrUPP(userRoutine) |
| #define | CallResErrProc(userRoutine, thErr) InvokeResErrUPP(thErr, userRoutine) |
Typedefs | |
| typedef Boolean | currentlyNativeEndian |
| typedef SInt16 | RsrcChainLocation |
| typedef short | ResFileRefNum |
| typedef short | ResID |
| typedef short | ResAttributes |
| typedef short | ResFileAttributes |
Functions | |
| typedef | CALLBACK_API_REGISTER68K (void, ResErrProcPtr,(OSErr thErr)) |
| typedef | REGISTER_UPP_TYPE (ResErrProcPtr) ResErrUPP |
| ResErrUPP | NewResErrUPP (ResErrProcPtr userRoutine) |
| void | DisposeResErrUPP (ResErrUPP userUPP) |
| void | InvokeResErrUPP (OSErr thErr, ResErrUPP userUPP) |
| typedef | CALLBACK_API (OSErr, ResourceEndianFilterPtr)(Handle theResource |
| short | InitResources (void) |
| void | RsrcZoneInit (void) |
| void | CloseResFile (short refNum) |
| OSErr | ResError (void) |
| Find if an error occurred in a resource operation. More... | |
| short | CurResFile (void) |
| Get reference number of current resource file. More... | |
| short | HomeResFile (Handle theResource) |
| Given a resource handle, return a file reference number. More... | |
| void | CreateResFile (ConstStr255Param fileName) |
| short | OpenResFile (ConstStr255Param fileName) |
| void | UseResFile (short refNum) |
| Make specified resource file the "current file". More... | |
| for (j=1;j<=rTotal;j++) | |
| short | Count1Types (void) |
| Get total number of resource types in current file. More... | |
| void | GetIndType (ResType *theType, short index) |
| Get the ResType of a resource, given its index. More... | |
| void | Get1IndType (ResType *theType, short index) |
| void | SetResLoad (Boolean load) |
| Set state of automatic resource loading. More... | |
| SetResLoad (FALSE) | |
| SetResLoad (TRUE) | |
| short | Count1Resources (ResType theType) |
| Get "1-deep" count of resources of selected type. More... | |
| Handle | GetIndResource (ResType theType, short index) |
| Handle | Get1IndResource (ResType theType, short index) |
| Handle | GetResource (ResType theType, short theID) |
| Handle | Get1Resource (ResType theType, short theID) |
| Handle | GetNamedResource (ResType theType, ConstStr255Param name) |
| Handle | Get1NamedResource (ResType theType, ConstStr255Param name) |
| void | MacLoadResource (Handle theResource) |
| void | ReleaseResource (Handle theResource) |
| void | DetachResource (Handle theResource) |
| Prevent resource from being discarded when file is closed. More... | |
| short | UniqueID (ResType theType) |
| Get unique resource ID (before adding a resource) More... | |
| short | Unique1ID (ResType theType) |
| 1-deep, get unique resource ID More... | |
| short | GetResAttrs (Handle theResource) |
| void | GetResInfo (Handle theResource, short *theID, ResType *theType, Str255 name) |
| Given a handle, obtain resource ID, type, and name. More... | |
| void | SetResInfo (Handle theResource, short theID, ConstStr255Param name) |
| void | AddResource (Handle theData, ResType theType, short theID, ConstStr255Param name) |
| Make arbitrary data in memory into a resource. More... | |
| long | GetResourceSizeOnDisk (Handle theResource) |
| long | GetMaxResourceSize (Handle theResource) |
| long | RsrcMapEntry (Handle theResource) |
| Obtain offset in resource map for a handle's entry. More... | |
| void | SetResAttrs (Handle theResource, short attrs) |
| Set resource attributes (purgeable, locked, etc.) More... | |
| void | ChangedResource (Handle theResource) |
| void | RemoveResource (Handle theResource) |
| void | UpdateResFile (short refNum) |
| Write changed resource map and data to disk. More... | |
| void | SetResPurge (Boolean install) |
| Write data of one resource to disk. More... | |
| short | GetResFileAttrs (short refNum) |
| Obtain resource file attributes. More... | |
| void | SetResFileAttrs (short refNum, short attrs) |
| Set resource file attributes. More... | |
| short | OpenRFPerm (ConstStr255Param fileName, short vRefNum, SInt8 permission) |
| Handle | RGetResource (ResType theType, short theID) |
| short | HOpenResFile (short vRefNum, long dirID, ConstStr255Param fileName, SInt8 permission) |
| void | HCreateResFile (short vRefNum, long dirID, ConstStr255Param fileName) |
| short | FSpOpenResFile (const FSSpec *spec, SignedByte permission) |
| Open resource file specified by an FSSpec. More... | |
| void | FSpCreateResFile (const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag) |
| void | ReadPartialResource (Handle theResource, long offset, void *buffer, long count) |
| void | WritePartialResource (Handle theResource, long offset, const void *buffer, long count) |
| void | SetResourceSize (Handle theResource, long newSize) |
| Handle | GetNextFOND (Handle fondHandle) |
| OSErr | RegisterResourceEndianFilter (ResType theType, ResourceEndianFilterPtr theFilterProc) |
| void | TempInsertROMMap (Boolean tempResLoad) |
| OSErr | InsertResourceFile (SInt16 refNum, RsrcChainLocation where) |
| OSErr | DetachResourceFile (SInt16 refNum) |
| Boolean | FSpResourceFileAlreadyOpen (const FSSpec *resourceFile, Boolean *inChain, SInt16 *refNum) |
| OSErr | FSpOpenOrphanResFile (const FSSpec *spec, SignedByte permission, SInt16 *refNum) |
| OSErr | GetTopResourceFile (SInt16 *refNum) |
| OSErr | GetNextResourceFile (SInt16 curRefNum, SInt16 *nextRefNum) |
| Handle | getnamedresource (ResType theType, const char *name) |
| Handle | get1namedresource (ResType theType, const char *name) |
| short | openrfperm (const char *fileName, short vRefNum, char permission) |
| short | openresfile (const char *fileName) |
| void | createresfile (const char *fileName) |
| void | getresinfo (Handle theResource, short *theID, ResType *theType, char *name) |
| void | setresinfo (Handle theResource, short theID, const char *name) |
| void | addresource (Handle theResource, ResType theType, short theID, const char *name) |
| short | FSOpenResFile (const FSRef *ref, SInt8 permission) |
| void | FSCreateResFile (const FSRef *parentRef, UniCharCount nameLength, const UniChar *name, FSCatalogInfoBitmap whichInfo, const FSCatalogInfo *catalogInfo, FSRef *newRef, FSSpec *newSpec) |
| Boolean | FSResourceFileAlreadyOpen (const FSRef *resourceFileRef, Boolean *inChain, SInt16 *refNum) |
| OSErr | FSCreateResourceFile (const FSRef *parentRef, UniCharCount nameLength, const UniChar *name, FSCatalogInfoBitmap whichInfo, const FSCatalogInfo *catalogInfo, UniCharCount forkNameLength, const UniChar *forkName, FSRef *newRef, FSSpec *newSpec) |
| OSErr | FSOpenResourceFile (const FSRef *ref, UniCharCount forkNameLength, const UniChar *forkName, SInt8 permissions, SInt16 *refNum) |
Variables | |
| short | rTotal = CountTypes() |
| Get total number of resource types in open files. More... | |
| short | j |
| ResType | rt |
| char * | rtp |
| </pre > *par | Copyright |
| rCount = CountResources('DRVR') | |
| Find how many of a selected resource type exist. More... | |
| * | FileAttributes |
Resource Manager Interfaces.
For bug reports, consult the following page on the World Wide Web:
http://developer.apple.com/bugreporter/
| #define NewResErrUPP | ( | userRoutine | ) |
| typedef short ResFileRefNum |
These typedefs were originally created for the Copland Resource Mangager
| typedef SInt16 RsrcChainLocation |
© RESOURCE CHAIN LOCATION - for use with the Resource Manager chain manipulation routines under Carbon.
| void AddResource | ( | Handle | theData, |
| ResType | theType, | ||
| short | theID, | ||
| ConstStr255Param | name | ||
| ) |
Make arbitrary data in memory into a resource.
AddResource converts an existing handle (either one that points to any existing data or even an empty handle) into a handle recognized by the Resource Manager and saved in the resource map . This affects the map of the current resource file (see UseResFile ). This function automatically sets the resChanged bit of the resource attribute. Thus, when the current resource file is closed or updated the resource data and map will be written to disk (see ChangedResource ). All other attributes are cleared; use SetResAttrs before writing the resource if you want different attributes. This is the opposite of DetachResource , which converts a resource handle into a generic handle. To duplicate a resource, use DetachResource followed by AddResource . Example
| void addresource | ( | Handle | theResource, |
| ResType | theType, | ||
| short | theID, | ||
| const char * | name | ||
| ) |
| void ChangedResource | ( | Handle | theResource | ) |
| void CloseResFile | ( | short | refNum | ) |
| short Count1Resources | ( | ResType | theType | ) |
Get "1-deep" count of resources of selected type.
Count1Resources returns the number of resources of a specified type which exist in the current resource file. rTypeis a 4-byte ResType value identifying the resource type you wish to count (e.g. 'FONT', 'MENU', etc.).
a positive integer; the number of resources of the specified type in the current resource file. Returns 0 if none found.
This function is the "1-deep" version of CountResources . To generate a list of resources of type rType for the current resource file, use Get1IndResource with an index ranging from 1 to the value obtained via Count1Resources . Refer to CountTypes and GetIndResource for related details.
| short Count1Types | ( | void | ) |
Get total number of resource types in current file.
Count1Types returns the number of resource types in the current resource file. It can be used as a first step in "1-deep" examination of resources.
a positive integer; it is the total number of distinct resource types in the current resource file.
Count1Types works exactly like CountTypes except that it limits the type search to the current resource file. This is normally followed by a series of calls to Get1IndType . Refer to CountTypes for related details.
| void createresfile | ( | const char * | fileName | ) |
| void CreateResFile | ( | ConstStr255Param | fileName | ) |
| short CurResFile | ( | void | ) |
Get reference number of current resource file.
CurResFile returns the file reference number of the "current resource file" - the first file searched during a resource request.
an integer; the reference number of the current resource file.
You can use this function early in an application to determine the reference number of the application's resource file. The global variable CurMap (at 0x0A5A) contains the same information that this call returns. Thus, the following are the same except that the latter generates less code: fRef= CurResFile (); fRef= CurMap;
| void DetachResource | ( | Handle | theResource | ) |
Prevent resource from being discarded when file is closed.
DetachResource removes a resource handle from the resource map without releasing it from memory. This can be used to keep one or more resources in memory after closing a resource file. rHandle is a handle leading to some variable length resource data. This should be a valid handle obtained via GetResource , GetNamedResource , etc.
none (if rHandle is not a handle to a resource, or if detachment is disallowed, ResError will return an error).
DetachResource causes rHandle 's resource map pointer to be set to NIL while maintaining the resource in memory and keeping the handle's master pointer valid. One significant effect is that when a resource's file is closed (see CloseResFile ), the resource data is not purged from memory. After this call, rHandle is no longer considered to be a resource handle. Calls such as ReleaseResource and GetResInfo will not respond. If you call GetResource (et. al.) for the same handle, the resource will be read into memory again. You can copy the detached resource and install the duplicate into the resource list via AddResource . To discard the detached resource data, use DisposHandle . This function is not valid for resources tagged with the resChanged attribute ( ResError returns resAttrErr ).
| OSErr DetachResourceFile | ( | SInt16 | refNum | ) |
If the file is not currently in the resource chain, this returns resNotFound Otherwise, the resource file is removed from the resource chain. DetachResourceFile()
| void DisposeResErrUPP | ( | ResErrUPP | userUPP | ) |
| void FSCreateResFile | ( | const FSRef * | parentRef, |
| UniCharCount | nameLength, | ||
| const UniChar * | name, | ||
| FSCatalogInfoBitmap | whichInfo, | ||
| const FSCatalogInfo * | catalogInfo, | ||
| FSRef * | newRef, | ||
| FSSpec * | newSpec | ||
| ) |
| OSErr FSCreateResourceFile | ( | const FSRef * | parentRef, |
| UniCharCount | nameLength, | ||
| const UniChar * | name, | ||
| FSCatalogInfoBitmap | whichInfo, | ||
| const FSCatalogInfo * | catalogInfo, | ||
| UniCharCount | forkNameLength, | ||
| const UniChar * | forkName, | ||
| FSRef * | newRef, | ||
| FSSpec * | newSpec | ||
| ) |
Summary: Creates a new resource file.
Discussion: This function creates a new file and initializes the specified named fork as an empty resource fork. This function allows for the creation of data fork only files which can be used for storing resources. Passing in a null name defaults to using the data fork.
Parameters:
parentRef: The directory where the file is to be created
nameLength: Number of Unicode characters in the file's name
name: A pointer to the Unicode name
whichInfo: Which catalog info fields to set
catalogInfo: The values for catalog info fields to set; may be NULL
forkNameLength: The length of the fork name (in Unicode characters)
forkName: The name of the fork to initialize (in Unicode); may be NULL
newRef: A pointer to the FSRef for the new file; may be NULL
newSpec: A pointer to the FSSpec for the new directory; may be NULL
| short FSOpenResFile | ( | const FSRef * | ref, |
| SInt8 | permission | ||
| ) |
| OSErr FSOpenResourceFile | ( | const FSRef * | ref, |
| UniCharCount | forkNameLength, | ||
| const UniChar * | forkName, | ||
| SInt8 | permissions, | ||
| SInt16 * | refNum | ||
| ) |
Summary: Opens the specified named fork as a resource fork.
Discussion: This function allows any named fork of a file to be used for storing resources. Passing in a null forkname will result in the data fork being used.
Parameters:
ref: The file containing the fork to open
forkNameLength: The length of the fork name (in Unicode characters)
forkName: The name of the fork to open (in Unicode); may be NULL
permissions: The access (read and/or write) you want
refNum: On exit the reference number for accessing the open fork
| void FSpCreateResFile | ( | const FSSpec * | spec, |
| OSType | creator, | ||
| OSType | fileType, | ||
| ScriptCode | scriptTag | ||
| ) |
| OSErr FSpOpenOrphanResFile | ( | const FSSpec * | spec, |
| SignedByte | permission, | ||
| SInt16 * | refNum | ||
| ) |
FSpOpenOrphanResFile should be used to open a resource file that is persistent across all contexts, because using OpenResFile normally loads a map and all preloaded resources into the application context. FSpOpenOrphanResFile loads everything into the system context and detaches the file from the context in which it was opened. If the file is already in the resource chain and a new instance is not opened, FSpOpenOrphanResFile will return a paramErr. Use with care, as can and will fail if the map is very large or a lot of preload resources exist. FSpOpenOrphanResFile()
| short FSpOpenResFile | ( | const FSSpec * | spec, |
| SignedByte | permission | ||
| ) |
Open resource file specified by an FSSpec.
The FSpOpenResFile function creates the file named in the spec parameter. The FSpOpenResFile function lets you open a resource file without creating a working directory. The permission parameter can contain any one of the following constants: fsCurPerm whatever is currently allowed fsRdPerm request for read permission only fsWrPerm request for write permission fsRdWrPerm request for exclusive read/write permission fsRdWrShPerm request for shared read/write permission More information about these constants can be found in the Low-Level File Manager section of the File Manager . If the FSpOpenResFile function failed to open the resource file, the reference number returned is -1. Call the ResError function to check for errors.
| Boolean FSpResourceFileAlreadyOpen | ( | const FSSpec * | resourceFile, |
| Boolean * | inChain, | ||
| SInt16 * | refNum | ||
| ) |
Returns true if the resource file is already open and known by the Resource Manager (i.e., it is either in the current resource chain or it's a detached resource file.) If it's in the resource chain, the inChain Boolean is set to true on exit and true is returned. If it's an open file, but the file is currently detached, inChain is set to false and true is returned. If the file is open, the refNum to the file is returned. FSpResourceFileAlreadyOpen()
| Boolean FSResourceFileAlreadyOpen | ( | const FSRef * | resourceFileRef, |
| Boolean * | inChain, | ||
| SInt16 * | refNum | ||
| ) |
| Handle Get1IndResource | ( | ResType | theType, |
| short | index | ||
| ) |
| void Get1IndType | ( | ResType * | theType, |
| short | index | ||
| ) |
| Handle get1namedresource | ( | ResType | theType, |
| const char * | name | ||
| ) |
| Handle Get1NamedResource | ( | ResType | theType, |
| ConstStr255Param | name | ||
| ) |
| Handle Get1Resource | ( | ResType | theType, |
| short | theID | ||
| ) |
| Handle GetIndResource | ( | ResType | theType, |
| short | index | ||
| ) |
| void GetIndType | ( | ResType * | theType, |
| short | index | ||
| ) |
Get the ResType of a resource, given its index.
GetIndType obtains the 4-byte ResType of a resource, given an arbitrarily-defined index number. rTypeis the address of a 4-byte ResType value. Upon return, it will contain the resource type code associated with the resource identified by index ; e.g., 'FONT', 'ICON', 'ICN#', etc. A value of 0 (four ASCII NULs) indicates that index was an invalid value. indexis a positive integer. It should range from 1 to the total number of distinct resources available (see CountTypes ).
none
GetIndType is usually only needed by resource-management utilities such as ResEdit. This function is the second step (following CountTypes ) in generating a list of all the different resource types, thus making it possible to look up each individual resource. Note: All the types obtained via this call are not necessarily available for access. The "indexed ResType list" contains ALL resource types while calls such as GetResource may search a subset of this list (i.e., the list of files starting with the current resource file and working chronologically backward toward the system file). See CountTypes for an example of usage.
| long GetMaxResourceSize | ( | Handle | theResource | ) |
| Handle getnamedresource | ( | ResType | theType, |
| const char * | name | ||
| ) |
| Handle GetNamedResource | ( | ResType | theType, |
| ConstStr255Param | name | ||
| ) |
| Handle GetNextFOND | ( | Handle | fondHandle | ) |
| OSErr GetNextResourceFile | ( | SInt16 | curRefNum, |
| SInt16 * | nextRefNum | ||
| ) |
GetNextResourceFile can be used to iterate over resource files in the resource chain. By passing a valid refNum in curRefNum it will return in nextRefNum the refNum of the next file in the chain. If curRefNum is not found in the resource chain, GetNextResourceFile returns resFNotFound. When the end of the chain is reached GetNextResourceFile will return noErr and nextRefNum will be NIL. GetNextResourceFile()
| short GetResAttrs | ( | Handle | theResource | ) |
| short GetResFileAttrs | ( | short | refNum | ) |
Obtain resource file attributes.
GetResFileAttrs returns a value representing the bit record that holds a resource file's attributes. In doing so, it tests whether a resource file is marked as read-only, has changed, or needs compacting. rfRefNum identifies the resource file to query. It is a value obtained from OpenResFile , HomeResFile , or CurResFile . A value of 0 refers to the system resource file.
a signed short; a bit record identifying the current resource file attributes of rfRefNum (see below). Note: Use ResError to check whether this function succeeded before assuming a valid return value.
You will want to use this function before calling SetResFileAttrs , in order to modify one or two attributes while leaving others unchanged. Resource file attributes are defined as follows: 7 6 5 4 3 2 1 0 0x01 0x02 0x04 0x08 0x10 0x20 0x40 0x80(reserved) (reserved) (reserved) (reserved) (reserved) mapChanged mapCompact mapReadOnly1= resource map will be written on update 1= file will be compacted upon update 1= file can’t be written The mapChanged attribute is set by commands such as AddResource , RmveResource , SetResAttrs and SetResInfo , and when ChangedResource tags a resource whose size has been changed. When set, the resource map will be written to the file. The mapCompact bit is set on all operations that change the size of the file (Note: on the 64K ROMs, this bit was not set if a resource simply got smaller). When set, the entire resource file is reorganized as it is rewritten and all empty space in the file is removed. The mapReadOnly attribute overrides all resource resChanged attributes in that WriteResource , UpdateResFile , and CloseResFile will NOT cause data to be written to the file.
| void getresinfo | ( | Handle | theResource, |
| short * | theID, | ||
| ResType * | theType, | ||
| char * | name | ||
| ) |
| void GetResInfo | ( | Handle | theResource, |
| short * | theID, | ||
| ResType * | theType, | ||
| Str255 | name | ||
| ) |
Given a handle, obtain resource ID, type, and name.
@par Non-Carbon CFM: in InterfaceLib 7.1 and later
| Handle GetResource | ( | ResType | theType, |
| short | theID | ||
| ) |
| long GetResourceSizeOnDisk | ( | Handle | theResource | ) |
| OSErr GetTopResourceFile | ( | SInt16 * | refNum | ) |
GetTopResourceFile returns the refNum of the top most resource map in the current resource chain. If the resource chain is empty it returns resFNotFound. GetTopResourceFile()
| void HCreateResFile | ( | short | vRefNum, |
| long | dirID, | ||
| ConstStr255Param | fileName | ||
| ) |
| short HomeResFile | ( | Handle | theResource | ) |
Given a resource handle, return a file reference number.
| rHandle | generic Handle of resource of interest In the 64K ROMs, HomeResFile can be used to make sure a resource is from the application's resource file. The "one-deep" functions (Get1Resource , Get1IndResource , etc.) of the 128K ROMs make this usage unnecessary. |
| short HOpenResFile | ( | short | vRefNum, |
| long | dirID, | ||
| ConstStr255Param | fileName, | ||
| SInt8 | permission | ||
| ) |
| short InitResources | ( | void | ) |
| OSErr InsertResourceFile | ( | SInt16 | refNum, |
| RsrcChainLocation | where | ||
| ) |
If the file is already in the resource chain, it is removed and re-inserted at the specified location If the file has been detached, it is added to the resource chain at the specified location Returns resFNotFound if it's not currently open. InsertResourceFile()
| void InvokeResErrUPP | ( | OSErr | thErr, |
| ResErrUPP | userUPP | ||
| ) |
| void MacLoadResource | ( | Handle | theResource | ) |
[Mac]LoadResource()
| ResErrUPP NewResErrUPP | ( | ResErrProcPtr | userRoutine | ) |
| short openresfile | ( | const char * | fileName | ) |
| short OpenResFile | ( | ConstStr255Param | fileName | ) |
| short openrfperm | ( | const char * | fileName, |
| short | vRefNum, | ||
| char | permission | ||
| ) |
| short OpenRFPerm | ( | ConstStr255Param | fileName, |
| short | vRefNum, | ||
| SInt8 | permission | ||
| ) |
| void ReadPartialResource | ( | Handle | theResource, |
| long | offset, | ||
| void * | buffer, | ||
| long | count | ||
| ) |
| OSErr RegisterResourceEndianFilter | ( | ResType | theType, |
| ResourceEndianFilterPtr | theFilterProc | ||
| ) |
RegisterResourceEndianFilter()
| void ReleaseResource | ( | Handle | theResource | ) |
| void RemoveResource | ( | Handle | theResource | ) |
| OSErr ResError | ( | void | ) |
Find if an error occurred in a resource operation.
You can use ResError to read that code and see if the most recent operation caused an error, and if so, what the error was.
an integer; the Error Code of the most recent resource-related operation. It may be a file system error or one of the following resource error constants: noErr(0)No Error (this constant is defined in MacTypes.h) resNotFound (-192)Resource not found resFNotFound (-193)Resource file not found addResFailed (-194)AddResource failed rmvResFailed (-196)RmveResource failed (-197)(not used) resAttrErr (-198)Attribute does not permit operation mapReadErr (-199)Error reading resource map
ResError is functionally equivalent to reading the low-memory global,
ResErr; i.e., the following are the same, except the latter generates less
code and is faster:
if ( ResError () ){ ... an error occurred ... }
if ( ResErr ) { ... an error occurred ... }
ResError may return other system errors, for instance, dskFulErr or
memFullErr . See Error Codes for a full list.
A few Resource Manager functions indicate errors by returning a NIL
handle (e.g., GetResource ). When these calls fail, ResError returns
noErr, so be sure to check for NIL handles!
| Handle RGetResource | ( | ResType | theType, |
| short | theID | ||
| ) |
| long RsrcMapEntry | ( | Handle | theResource | ) |
Obtain offset in resource map for a handle's entry.
RsrcMapEntry returns an offset from the start of the resource map . The offset specifies the location of a particular resource entry. rHandle is a valid resource handle. It is a value obtained via GetResource , GetIndResource , et. al.
a 32-bit long integer; the offset from the start of the resource map which contains the start of the resource entry for rHandle . A return value of NIL indicates an error and ResError will return resNotFound .
The low-memory global variable TopMapHndl (0xA50) contains a handle leading to the start of the resource map of the current resource file.
| void RsrcZoneInit | ( | void | ) |
| void SetResAttrs | ( | Handle | theResource, |
| short | attrs | ||
| ) |
Set resource attributes (purgeable, locked, etc.)
SetResAttrs sets resource attributes in the resource map . The modified attributes will not take effect until the next time the resource is loaded. rHandle is a resource handle. It is a handle obtained via GetResource , GetIndResource , et. al. rAttrsis a 16-bit resource attribute word - a bit record which specifies how the resource is to be handled when loaded subsequently (see below).
none
SetResAttrs is normally needed only by resource-management utilities such as ResEdit; it is a rare application that needs to modify attributes by using this function. The rAttrs parameter specifies resource attributes as follows: 7 6 5 4 3 2 1 0 0x01 0x02 0x04 0x08 0x10 0x20 0x40 0x80(reserved) resChanged resPreload resProtected resLocked resPurgeable resSysHeap (reserved)1= has changed; UpdateResFile will write to disk 1= is preloaded when file is opened 1= can’t change ID, name, contents, etc. 1= won’t be moved or purged 1= purgeable (call LoadResource before access) 1= load in system heap; 0= use application heap The new setting of resProtected takes effect immediately, so make sure you have already written any changes out to disk; other attributes take effect the next time the resource is loaded. We are warned specifically against modifying the state of the resChanged attribute directly. Use ChangedResource to flag a resource for update. A normal sequence is to use GetResAttrs to find the current settings, modifying one or more bits (without changing bit 1), then use SetResAttrs to update the resource map . This is illustrated in the following example: Example #include < Resources.h >
| void SetResFileAttrs | ( | short | refNum, |
| short | attrs | ||
| ) |
Set resource file attributes.
SetResFileAttrs sets resource file attributes. It specifies whether a resource file is marked as read-only, has changed, or needs compacting. This is needed rarely, since file attributes are modified automatically by the Resource Manager . rfRefNum identifies the resource file whose attributes you wish to modify. It is a value obtained from OpenResFile , HomeResFile , CurResFile or OpenRFPerm . A value of 0 refers to the system resource file. rfAttrsidentifies the desired attributes you wish to apply to the resource file. See below..
none (use ResError to check for success/failure)
Resource file attributes are defined as follows: 7 6 5 4 3 2 1 0 0x01 0x02 0x04 0x08 0x10 0x20 0x40 0x80(reserved) (reserved) (reserved) (reserved) (reserved) mapChanged mapCompact mapReadOnly1= resource map will be written on update 1= file will be compacted upon update 1= file can’t be written See GetResFileAttrs for related information. In the 64K ROMs, it was necessary to set mapCompact manually if you wanted to recover the file space that had been occupied by a resource after it was shortened. Since this was fixed, there was little reason to modify resource file attributes.
| void setresinfo | ( | Handle | theResource, |
| short | theID, | ||
| const char * | name | ||
| ) |
| void SetResInfo | ( | Handle | theResource, |
| short | theID, | ||
| ConstStr255Param | name | ||
| ) |
| void SetResLoad | ( | Boolean | load | ) |
Set state of automatic resource loading.
After using SetResLoad (FALSE), be sure to use SetResLoad (TRUE) as soon as possible. Some toolbox calls malfunction when resources do not automatically load. Furthermore, remember to use SetResLoad (TRUE) before exiting from your application; otherwise the Finder's code resource will not be loaded. The low-memory global variable ResLoad echoes the status of this call, but remember that any non-zero value indicates that resource loading is disabled. The following calls set ResLoad to TRUE (enable auto-loading) as a side-effect: GetFNum , GetFontName , RealFont and AddResMenu . See CountResources for an example of usage.
| void SetResourceSize | ( | Handle | theResource, |
| long | newSize | ||
| ) |
| void SetResPurge | ( | Boolean | install | ) |
Write data of one resource to disk.
WriteResource is called automatically by UpdateResFile and CloseResFile . Remember that if a resource has been purged, these file operations will write a 0-length resource to the file. Thus, a typical use of this function is in a sequence that locks a resource, changes it, writes the changes, and unlocks the resource: HNoPurge ( rHandle ); /* inhibit purging */ /*... modify the handle data... */ ChangedResource(rHandle); /* tag as changed */ if (ResError() == noErr) { /* always check this! */ WriteResource(rHandle); /* record changes to disk */ } HPurge(rHandle); /* allow purge */ Make sure you check ResError after calling ChangedResource(or AddResource) and before calling WriteResource.</ pre>
1992 Symantec Corporation
later
later
later
/
void WriteResource(Handle theResource);
/**
Force resource changes to be written before purge
SetResPurge is an attempt to avoid the "silent error" of writing a 0-length resource to disk when a resource file is updated. It is needed only by applications that modify a resource tagged as resPurgeable (see GetResAttrs ). In a memory shortage situation the Memory Manager will discard all purgeable resources and compact memory. Then, when you WriteResource , UpdateResFile , or CloseResFile , a 0-length resource is sent to disk. By calling SetResPurge (TRUE), you can avoid this problem. Another way is to set the address of a custom "purge warning handler" into the purgeProc field of the memory manager's Zone structure obtained via ApplicZone . Yet another way is: avoid changing purgeable resources altogether! Note that this does NOT keep the resource from getting purged. You must use LoadResource before each access of an unlocked purgeable resource. See HNoPurge for a way to force any purgeable handle to remain in memory.
| void TempInsertROMMap | ( | Boolean | tempResLoad | ) |
| short Unique1ID | ( | ResType | theType | ) |
1-deep, get unique resource ID
Unique1ID returns a unique, unused resource ID that will not collide with any resource of the specified type in the current resource file. rTypeis a 4-byte ResType value. It identifies the resource type for which you wish a unique resource ID (e.g., 'FONT', 'WIND', etc.)
an integer; a resource ID number that is unique with respect to resources of type rType in the current resource file.
This function is the "1-deep" version of UniqueID . It generates a resource ID that is unique with respect to resources in the current resource file (see UseResFile ). Refer to UniqueID for related details.
| short UniqueID | ( | ResType | theType | ) |
Get unique resource ID (before adding a resource)
UniqueID returns a unique, unused resource ID that will not collide with any resource of the specified type in any open resource file. rTypeis a 4-byte ResType value. It identifies the resource type for which you wish a unique resource ID (e.g., 'FONT', 'WIND', etc.)
an integer; a resource ID number that is unique with respect to all resources of type rType in all currently-open resource files.
UniqueID and Unique1ID are used by applications that create resources; especially temporary resources that are removed when the program terminates. After making this call, you can safely add to the resource list, e.g.,: newID = UniqueID ( 'MENU' ); AddResource ( myHand, 'MENU', newID, "\pMy New Menu" ); To avoid colliding with IDs of ROM-based resources (i.e., get a truly unique ID), set the RomMapInsert flag directly before calling: RomMapInsert = mapTrue ; newID = UniqueID ( 'MENU' ); See GetResource for information about ROM-based resources. This call may return IDs less than 128 which, by convention, are reserved for system resources. Just call it again until you get an ID greater than 127.
| void UpdateResFile | ( | short | refNum | ) |
Write changed resource map and data to disk.
UpdateResFile writes the resource map and all changed data of the specified resource file to disk. Data is written only if one or more resources are tagged as having been modified. rfRefNum identifies the resource file to update. It is a value obtained from OpenResFile , HomeResFile , or CurResFile . A value of 0 refers to the system resource file.
none (use ResError to determine success/failure)
All changed resource data (as tagged with the resChanged attribute set via ChangedResource ) is written to disk as described in WriteResource . All changes to the resource map of the file are recorded, including changes made by AddResource and RmveResource . The file data is compacted, if necessary. The resChanged attribute of all resources written to disk is reset. You might wish to call FlushVol to ensure that the information is really written out to disk. Be aware that using DetachResource sets the resource's handle to NIL in the resource map . Similarly, any purged resource will be saved as an empty resource (see WriteResource ). You may use CurResFile , early in your program, to obtain the rfRefNum of your application's resource file. This function is called automatically when the file is closed via CloseResFile .
| void UseResFile | ( | short | refNum | ) |
Make specified resource file the "current file".
UseResFile selects a different file (already open) as the current resource file. On subsequent resource requests, the specified file will be searched first and none of the more recently opened resource files will be searched. rfRefNum is a resource file reference number; typically a value obtained from OpenResFile , HomeResFile , or CurResFile . Use 0 to specify the system resource file.
none (use ResError to determine success/failure)
Open resource files are arranged as a linked list; the most recently opened file is at the end of the list and is the first one the Resource Manager searches when looking for a resource. UseResFile lets you start the search with a file opened earlier; the file(s) following it in the list are then left out of the search process. When a new resource file is opened, it's added to the end of the list; this overrides any previous calls to UseResFile , causing the entire list of open resource files to be searched. For example, assume that there are four open resource files (R0 through R3) and the search order is R3, R2, R1, R0. If you call UseResFile (R2), the search order becomes R2, R1, R0. Note that R3 is no longer searched. If you then open a fifth resource file (R4), it is added to the end of the list and the search order becomes R4, R3, R2, R1, R0. UseResFile does not re-order the resource file list; it causes resource searching to start at a specified file and work backwards (chronologically) down the list if it fails to find a resource in the current file. For instance, after UseResFile (0), calls such as GetResource or GetPicture will search only the system resource file. The application's resource file is implicitly set as the current file when an application is started. The OpenResFile function also sets the current resource file, thereby overriding any previous call to UseResFile . The resource search order is affected by the setting of the low-memory globals RomMapInsert and TmpResLoad . These affect whether ROM-based resources are considered to be in the normal lookup list.
| void WritePartialResource | ( | Handle | theResource, |
| long | offset, | ||
| const void * | buffer, | ||
| long | count | ||
| ) |
| rCount = CountResources('DRVR') |
Find how many of a selected resource type exist.
CountResources returns the number of resources of a specified resource type that exist among the currently-open resource files. rTypeis a 4-byte ResType value identifying the resource type you wish to count (e.g. 'FONT', 'MENU', etc.).
a positive integer; the number of resources of the specified type contained in all currently-open resource files. Returns 0 if none are found.
This function is used as the first step in generating a list of currently-available resources of a particular type. To generate the list, use GetIndResource with an index ranging from 1 to the CountResources return value. Use Count1Types and Get1IndResource to count and access only the resources in the current resource file. The following example prints a list of the names of all resources of type 'DRVR' (i.e., desk accessories). Example #include < Resources.h > short rCount, rID, j; Handle rHandle; ResType rType; Str255 rName; printf("\n"); /* ensure printf can get fonts
| rTotal = CountTypes() |
Get total number of resource types in open files.
CountTypes returns the total number of resource types in all currently-opened resource files. It can be used as a first step in a system-wide examination of resources.
a positive integer; it is the total number of distinct resource types in all open resource files.
CountTypes is only needed by resource-management utilities such as ResEdit or Resorcerer. This function is the first step in generating a list of all the different resource types, thus making it possible to look up each individual resource. Subsequent calls to GetIndType will return the ResType value for types from 1 to the return value of this call. This function operates across all open resource files while the similar Count1Types function counts just the resource types in the current resource file. The following example displays a list of resource types along with the number of such resources, contained in all open resource files. Example #include < Resources.h > #include <stdio.h> /* for printf()