[comp.sys.mac.programmer] Volume RefNum Problems

topix@gpu.utcs.utoronto.ca (R. Munroe) (06/07/91)

I am having some difficult volume refnum trouble.  I have a situation where it
is necessary to store the parameters of certain files into my apps prefs file
so I can easily access the files from a menu (much like ResEdit's Open Special
menu).  If I'm running my app and add a new file to the menu, I can open that
file from the menu with no trouble.  Before quitting, I store the file's
name and volume refnum in my prefs file.  When I restart my app, I can no longer
open the file - the vol refnum is the same as when I stored it, but the system
can't find the file.  If I reload the file, I find that, sure enough, the vol 
refnum is different this time around (which explains why I can't reopen the
file when I restart my app.  What else do I have to store in my prefs
file?  Am I storing the right stuff (file name and vol refnum)?

As always, any help is much obliged.

Bob Munroe
topix@utcs.utoronto.ca

keith@Apple.COM (Keith Rollin) (06/08/91)

In article <1991Jun7.093153.5509@gpu.utcs.utoronto.ca> topix@gpu.utcs.utoronto.ca (R. Munroe) writes:
>I am having some difficult volume refnum trouble.  I have a situation where it
>is necessary to store the parameters of certain files into my apps prefs file
>so I can easily access the files from a menu (much like ResEdit's Open Special
>menu).  If I'm running my app and add a new file to the menu, I can open that
>file from the menu with no trouble.  Before quitting, I store the file's
>name and volume refnum in my prefs file.  When I restart my app, I can no longer
>open the file - the vol refnum is the same as when I stored it, but the system
>can't find the file.  If I reload the file, I find that, sure enough, the vol 
>refnum is different this time around (which explains why I can't reopen the
>file when I restart my app.  What else do I have to store in my prefs
>file?  Am I storing the right stuff (file name and vol refnum)?

Storing a vRefNum in a preferences file is a Bad Idea(tm). VRefNums
are allocated dynamically; there is no guarantee that a volume
will recieve the same vRefNum it had the last time it was mounted.

Instead, save the volume's name. To differentiate between two
volumes with the same name, also save the volume's creation date.

You should also consider saving the file's dirID. That way you'll
know where on the volume your file is!

-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc. 
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"But where the senses fail us, reason must step in."  - Galileo