poleary@BONNIE.ICS.UCI.EDU (Peter O'Leary) (06/03/89)
An application that I am working on needs to save information on a file so that that file may be opened later. What is the minimum amount of information that is needed in order to get at a file? So far, I have been storing the file's name and volume reference number. I call SetVol and everything seems to work fine until I save this info, exit the program and restart. The SetVol call then fails with a "Volume not found". I know that under HFS, there is a directory reference number floating around out there that I may need to use, but I haven't had any success at playing around with these either. Any hints? Pete O'Leary.
rang@cpsin3.cps.msu.edu (Anton Rang) (06/03/89)
In article <16464@paris.ics.uci.edu> poleary@BONNIE.ICS.UCI.EDU (Peter O'Leary) writes: An application that I am working on needs to save information on a file so that that file may be opened later. What is the minimum amount of info [] that is needed in order to get at a file? So far, I have been storing the file's name and volume reference number. It depends on how much later you need the file, to some extent, but what I'd recommend storing is: Volume name (refnum is only valid for one session) Directory ID (for an HFS volume) File name For an MFS volume, you can assume that the file version is 0 without problems unless some other weird software is changing the version. Also, in theory, all you should need is: Volume name Directory ID File number but I don't know of any file system call to open a file by number, so I think you need to use the filename. +---------------------------+------------------------+ | Anton Rang (grad student) | "VMS Forever!" | | Michigan State University | rang@cpswh.cps.msu.edu | +---------------------------+------------------------+
spector@vx2.GBA.NYU.EDU (David HM Spector) (06/06/89)
In article <16464@paris.ics.uci.edu> poleary@BONNIE.ICS.UCI.EDU (Peter O'Leary) writes: >An application that I am working on needs to save information on a file so >that that file may be opened later. What is the minimum amount of information >that is needed in order to get at a file? So far, I have been storing the >file's name and volume reference number. I call SetVol and everything >seems to work fine until I save this info, exit the program and restart. >The SetVol call then fails with a "Volume not found". I know that under >HFS, there is a directory reference number floating around out there that I >may need to use, but I haven't had any success at playing around with these >either. The vRefNum you are getting is actually a WDRefNum (working directory). As such it will go stale every time you quit your app. You can store a fully qualified pathname instead. This will work until someone changes the folder organization. That's not too bad- if you can't find the folder ask the user where he put it (most programs do this- Think products, like LSP, for example). You can also get the folder number. I haven't looked at this in ages, but I think you want either PBHGetVol or PBGetCatInfo (on the other hand, those names don't look exactly right. Regardless, it shouldn't be too hard to fish out of Inside Mac). Once System 7 comes out life will be much easier, but I doubt you want to wait that long. --- Alexis Rosen temporarily at spector@vx2.gba.nyu.edu alexis@rascal.ics.utexas.edu (last resort)
awd@dbase.UUCP (Alastair Dallas) (06/09/89)
In article <3264@cps3xx.UUCP>, rang@cpsin3.cps.msu.edu (Anton Rang) writes: > In article <16464@paris.ics.uci.edu> poleary@BONNIE.ICS.UCI.EDU (Peter O'Leary) writes: > > An application that I am working on needs to save information on a file so > that that file may be opened later. What is the minimum amount of info [] > that is needed in order to get at a file? So far, I have been storing the > file's name and volume reference number. > > It depends on how much later you need the file, to some extent, but > what I'd recommend storing is: > > Volume name (refnum is only valid for one session) > Directory ID (for an HFS volume) > File name > Like another current thread in comp.sys.mac.programmer, I think the answer here is: "There is already a Macintosh way of doing this." The minimum amount of information to store is whatever the user enters to name the file in the first place. If she renames the file or shuffles directories between the time she writes the file and the time she reads the file, the program should just politely pull up SFGetFile and say "where the H*ll is <filename>?". Of course, if she navigates in SFPutFile, you might want the Volume and Directory, but you want to ignore those things if the user ignored them (used the default working directory) when she saved the file. The way to detect navigation in SFPutFile is to compare the working directory before and after the SFPutFile call (that's off the top of my head, I'll be corrected if I'm wrong, I'm sure). User brings up your program, writes out a file by doing nothing more than typing Foo in the SFPutFile dialog. Back at Finder, realizes that Foo is now in same folder as the program. Moves Foo to a floppy. Months later, inserts floppy, dbl-clicks Foo--your program tells him forget it because Volume and Directory don't match? Wouldn't be friendly... (Long-winded today, aren't I?) /alastair/