Specifications

Apple II Technical Notes
Apple IIGS
8 of 6 #71: DA Tips and Techniques
NDAs Can Have Resource Forks
Following is the recommended way for a New Desk Accessory to use its file’s resource fork.
In the NDA’s Open routine, do the following. Steps that are obsolete (and safely omitted) with
System Software 6.0 and later are marked with an asterisk (*):
1. Call GetCurResourceApp and keep the result.
2. If the NDA does not already know its Memory Manager user ID, call MMStartUp to
get it.
3. Call ResourceStartUp using the NDA’s user ID.
4. Call the Loader function LGetPathname2 with the NDA’s user ID (and a
fileNumber of $0001) to get a pointer to the NDA’s pathname. (The result is a
pointer to a class-one GS/OS string.)
*5. Use GetLevel to get the current file level, then use SetLevel to set it to zero. This
helps protect your resource fork from being closed accidentally.
6. Use GetSysPrefs to get the current OS preferences, then use SetSysPrefs to
ensure that the user is prompted, if necessary, to insert the disk containing your
resource fork. (To compute the new preferences word, take the current one, AND it
with $1FFF, and ORA it with $8000. This tells GS/OS to deal with volume-not-found
conditions by putting up a please-insert-disk dialog with an OK button and a Cancel
button.)
7. Call OpenResourceFile using the result from LGetPathname2. Save the
returned fileID—you need it when closing the file. (Be prepared to deal with an
error, such as $0045, Volume Not Found.)
8. Use SetSysPrefs to restore the OS preferences saved in step six.
*9. Use SetLevel to restore the file level to its old value (saved in step five).
10. Call SetCurResourceApp with the old value saved in step one.
In the NDA’s action routine, no special calls are necessary—the Desk Manager calls
SetCurResourceApp automatically before calling your action routine, so your NDA’s own
resource search path is already in effect.
Run queue routines and NDA installs with AddToRunQ are treated the same way—the NDA’s
resource search path is automatically in effect when the run queue routine is called.
In the NDA’s Close routine, do the following:
1. Call CloseResourceFile with the fileID that was returned when you
opened it.
2. Call ResourceShutDown with no parameters.