[futurebasic] Re: [FB] Opening Files from Finder

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2004 : Group Archive : Group : All Groups

From: Alain Pastor <apastor@...>
Date: Mon, 06 Sep 2004 19:09:57 +0200
BrucesFB3@... wrote:

> Hello All,
> 
> Given the code below:
> 
> I understand this has something to do with opening files by
> double clicking icons in the Finder.
> 
> I have been able to use the functions successfully. Everything
> works.
> 
> My problem is that I don't know why it works. Obviously,
> FN FBWDToFSSpec() is checking for a particular type of error. 
> What kind of error? What is the trigger?
> 
> Also in FN FBWDToFSSpec(), what are the purposes of
> FN FBWDToPBWD( pb ) and FN PBGetCatInfoSync( pb). 
> What is the CInfoPBRec?
> 
> What is the meaning of the syntax, AS .Str63? (period before Str63).
> 

Bruce,

First, I think I would encourage you to abandon the code you have 
posted because it was meant to ease the path for the conversion of 
old FB Code. As you have probably noticed it makes use of the 
obsolete Working Directory Reference Number which was the FB way to 
designate files for so many years. But, this WDRefNum doesn't exist 
anymore in Macdom under Carbon, it is just that Andy G. has 
resurrected this entity (it is fake) so that old FBers wouldn't have 
to rewrite the parts of their code in their apps that deal with file 
handling.

FBWDToFSSpec is a utility function that receives a name (actually a 
pointer to a string) a working directory reference number and a 
pointer to an FSSpec structure.

Local Fn FBWDToFSSpec(@namePtr As .Str63, ¬
                        vRefNum As Int, ¬
                          fSpec As .FSSpec)

Starting with the file name and the VRefNum the function builds the 
FSSpec filling first a couple of fields of a CInfoPBRec record,

pb.ioNamePtr = namePtr
pb.ioVRefNum = vRefNum

structure expected by the PBGetCatInfoSync Toolbox function that 
returns info on any file item; you can find the definition of the 
CInfoPBRec with a quick search in the FB headers.

In conditional compile structure, you'll find a call to an 
undocumented runtime function that does the magic that Andy has put 
in there to maintain the compatibility with old FB code. After that 
call, the CInfoPBRec structure will contain the correct values to 
pass onto the Carbon Toolbox.

#If CarbonLib
   Fn FBWDToPBWD( pb )
#Endif

The PBGetCatInfoSync alters the fields of the structure passed as a 
parameter (called pb here). After the call to that Toolbox, the 
FSSpec is built with some values found in specific fields of the 
CInfoPBRec structure.

fSpec.name    = namePtr.nil$
fSpec.vRefNum = pb.ioVRefNum
fSpec.parID   = pb.ioFlParID

But as shown in the code you have posted there's something simpler, 
that is to use the runtime function called FBMakeFSSpec that should 
do exactly the same thing.

Fn FBWDToFSSpec( fileName$, vRefNum%, fSpec )
can be replaced I think with:
Fn FBMakeFSSpec( vRefNum%, 0, fileName, fSpec )


Finally, the following statements are equivalent:

As .Str63
As @Str63
As ^Str63
As Ptr To Str63
As Pointer To Str63


In addition, note also that there is a runtime internal array, 
namely gFBInfoSpec(), that contains the FSSpecs of all the files 
that want to come in through your FinderInfo vector. Since the 
arrays always start at index 0 in FB, you can retrieve the maximum 
usable index in that array with gFBFndrInfoCount - 1. This might 
spare some conversion work from old file reference numbers to new 
FSSpec references.

I have given up trying to understand your code, it seems too much 
convoluted to me. I wonder where it comes from.

Alain