holland@mips.csc.ti.com (Fred Hollander) (01/11/89)
I would like to access all opened resource files. I know they are in a linked list, but I can't find any documentation on how to access it. I've looked in IM, Tech Notes and MacTutor. Does someone know how to get the head of the list and the structure of each element? Another resource problem. I need to temporarily change the permission of a resource file. Right now I CloseResFile and OpenRFPerm, but I'm worried about the path number changing (especially when Apple implements preemptive multitasking :). This is inside a patch, so the application may have the path number stored somewhere. Out of curiousity does anyone know how they come up with the path number? Thanks, Fred Hollander Computer Science Center Texas Instruments, Inc. holland%ti-csl@csnet-rela The above statements are my own and not representative of Texas Instruments.
tim@hoptoad.uucp (Tim Maroney) (01/12/89)
In article <67009@ti-csl.CSNET> holland@mips.csc.ti.com (Fred Hollander) writes: >I would like to access all opened resource files. I know they are in a linked >list, but I can't find any documentation on how to access it. I've looked >in IM, Tech Notes and MacTutor. Does someone know how to get the head of the >list and the structure of each element? Sure, it's not hard, but accessing undocumented data structures is a good way to assure that you won't be compatible with future system releases. If this is an in-house program you're willing to maintain, fine, but you shouldn't do it if you don't have close control over distributed copies. So, take a look at the low-memory globals. TopMapHndl provides a handle to the top resource map in memory. This is a copy of the resource map from the resource file, the format of which is shown in IMv1 page 129. As you can see, at offset 16 there is a handle which provides the next resource map in the list of open resource files. You can iterate down until you find a next handle of zero; alternately, you can check to see when the current map is SysMapHndl (another low-memory global). At offset 20 in each map, there is a copy of the file reference number, which is probably what you're looking for. >Another resource problem. I need to temporarily change the permission of a >resource file. Right now I CloseResFile and OpenRFPerm, but I'm worried >about the path number changing (especially when Apple implements preemptive >multitasking :). This is inside a patch, so the application may have the path >number stored somewhere. Out of curiousity does anyone know how they come up >with the path number? I would strongly recommend against trying to do this. Why do you want to change the permission? The Mac has no way in the file system of changing the access permission on an open file. If you close and re-open the file, then you may very well wind up with a different reference number. Reference numbers are offsets into the file control block table; when you open a file, the offset to the lowest unused FCB is used. So, if another file has closed since the resource file was opened, you will change the reference number and the application will become confused. Not only that, but if another resource file has opened since your resource file was opened, you are changing the search path order. In my immodest opinion, a patch that does this is a broken patch. Don't. -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "I don't know that atheists should be considered citizens, nor should they be considered patriots. This is one nation under God." -- George Bush in FREE INQUIRY magazine, Fall 1988
holland@m2.csc.ti.com (Fred Hollander) (01/13/89)
In article <6265@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) writes: >In article <67009@ti-csl.CSNET> holland@mips.csc.ti.com (Fred Hollander) write > >>Another resource problem. I need to temporarily change the permission of a >>resource file. Right now I CloseResFile and OpenRFPerm, but I'm worried >>about the path number changing > >I would strongly recommend against trying to do this. Why do you want >to change the permission? The Mac has no way in the file system of >changing the access permission on an open file. If you close and >re-open the file, then you may very well wind up with a different >reference number. Reference numbers are offsets into the file control My concern exactly. I was also alerted to the fact that handles to open resources would be invalidated. I didn't intend to use this method, it was a temporary hack to test the effect of write-protecting a file. I was hoping someone could tell me the proper way to change the file protection. >block table; when you open a file, the offset to the lowest unused FCB >is used. So, if another file has closed since the resource file was >opened, you will change the reference number and the application will >become confused. Not only that, but if another resource file has >opened since your resource file was opened, you are changing the search >path order. In my immodest opinion, a patch that does this is a broken >patch. Don't. Ok, I won't. Thanks for telling me that the Mac file system cannot change the permission of an open file. At least I can stop looking. Anyway, I think I I have another approach that's a little cleaner. >-- >Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim Fred Hollander Computer Science Center Texas Instruments, Inc. holland%ti-csl@csnet-rela The above statements are my own and not representative of Texas Instruments.
jcl@hpausla.HP.COM (Jeff Laing) (01/16/89)
Fred Hollander (holland@mips.csc.ti.com) writes in comp.sys.mac.programmer: > I would like to access all opened resource files. I know they are in a linked > list, but I can't find any documentation on how to access it. I've looked > in IM, Tech Notes and MacTutor. I have a related question. I want to be able to do the 'reverse' of Get1Resource(); that is, I want to be able to access a particular resource, which is NOT in the current resource file. Does anyone know how I can take the current application (and all resource files after it in the list) out of the resource search? I figure that the solution will be in the constructive use of the form oldfile = CurResFile(); UseResFile( ... some tricky expression ... ); ... my code to use the resource ... UseResFile(oldfile); but I don't know what the tricky expression will look like to identify the resource file BEFORE the current one. Any clues, pointers, sample code, free lunches, etc would be appreciated
brecher@well.UUCP (Steve Brecher) (01/18/89)
In article <2580007@hpausla.HP.COM>, jcl@hpausla.HP.COM (Jeff Laing) writes: > I want to be able to do the 'reverse' of Get1Resource(); that is, I want to > be able to access a particular resource, which is NOT in the current resource > file. Does anyone know how I can take the current application (and all > resource files after it in the list) out of the resource search? The refNum of a resource file is stored at an offset of 20 decimal from the start of the file's resource map in RAM; a handle to the map of the most recently opened resource file is stored in system global variable TopMapHndl at 0xA50. Calling UseResFile on the most recent file's refnum will include all open files in the search performed by a subsequent GetResource. HomeResFile(rsrcHandle) will return the resource's file's refnum; comparison with your application's refnum can be used to determine whether the resource came from your application file. If you must follow the chain yourself, note that offset 16 decimal from the start of a resource map contains a handle to the next map in the chain or nil for the last map in the chain. -- brecher@well.UUCP (Steve Brecher)