Path: utzoo!mnetor!uunet!husc6!mailrus!ames!pasteur!ucbvax!dewey.soe.berkeley.edu!oster
From: oster@dewey.soe.berkeley.edu (David Phillip Oster)
Newsgroups: comp.sys.mac.programmer
Subject: Re: Writing resources to a file
Message-ID: <23980@ucbvax.BERKELEY.EDU>
Date: 8 May 88 15:58:17 GMT
References: <51379@sun.uucp> <600@kinetics.UUCP>
Sender: usenet@ucbvax.BERKELEY.EDU
Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster)
Distribution: na
Organization: School of Education, UC-Berkeley
Lines: 29

In article <600@kinetics.UUCP> markw@kinetics.UUCP (Mark Wittenberg) writes:
>1.  How do you tell if a resource file is already open?
>    OK, I know you can run through the FCB list, but this doesn't seem like
>    a very good idea, from the compatibility point of view.
Well, one easy way to do it is, before opening the file with
OpenResFile(), try opening it with PBOpenRF(). If it is already open,
since you are opening it for read/write you get back the vRef of the
existing access path and an "already open" error code. Close the file in
either case and open it with OpenResFile().  There probably is a better
way to solve this problem.

Another good thing to do is forbid you r application to open files of type
ZSYS or APPL. (This makes sense for many applications like MacPaint or
MacWrite, but not for applications like ResEdit.)  That way, when the
reviewer from InfoWorld trys to save-as on top of his System file, your
prgram won't clobber it. (They are beginning to give programs demerits
that don't include this bit of foolproofing.)

>2.  How do you tell if a resource has already been loaded?  I'd prefer to know
>    without loading it, but I'll settle for just knowing whether or not I
>    should unload it.  It's not sufficient to call SetResLoad(FALSE) before
>    the GetResource, and check to see if the handle was NULL.
Why isn't this sufficient? According to the Resource manager
documentation, this should work just fine.  (Though, for this application
you may want to use Get1Resource()).

--- David Phillip Oster            --When you asked me to live in sin with you
Arpa: oster@dewey.soe.berkeley.edu --I didn't know you meant sloth.
Uucp: {uwvax,decvax,ihnp4}!ucbvax!oster%dewey.soe.berkeley.edu