[futurebasic] [FB] WD Confusion?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2003 : Group Archive : Group : All Groups

From: mckernon <mckernon@...>
Date: Mon, 27 Jan 2003 13:40:15 -0500
Dear friends,

I fear I'm caught in the VRefNum vs. WDRefNum vs. FSSpec tangle,
hopefully one of you smart folks can see where I'm screwing up.

What I'm trying to do is make a list of all the files (of certain types)
within a specified folder within my application's folder. Then, I let the
user select one of those files from a pop-up menu and display it onscreen
or print it using USR IMAGEFILETOPICT.

I call FN CheckFolderApp, which calls FN ProcessFolder, which calls FN
AddToFileList. However, when I use the filenames and volume numbers that
are sent to FN AddToFileList with USR IMAGEFILETOPICT, I first check to
see if they exist and they don't. The filenames are all correct, but the
VolNum is always the same, no matter which sub-folder the routines have
been asked to process. My guess is the scanStuff.ScanSpec.vRefNum isn't
what I need, or it needs converting to a WDRefNum, but I don't know how
to do that.

I'm running this in OSX, with the PG runtime (not Appearance), but it has
the same problem in a PPC compile. All of the functions I'm using are out
of the Examples folders included with R7 of FB^3.

Any hints?

-- John


Here are the relevant code snippets:

LOCAL FN CheckFolderApp(SearchKind, fldName As Str63 ,FindType$)
DIM fldSpec As FSSpec

#IF Def _appearanceRuntime
    Fn FBMakeFSSpec( System( _aplVRefNum ), ¬
                   System( _aplParID ), ¬
                               fldName, ¬
                               fldSpec )
#ELSE
    Fn FBMakeFSSpec( System( _aplVol ), ¬
                                 0, ¬
                           fldName, ¬
                           fldSpec )
#ENDIF

FN ProcessFolder( SearchKind,fldSpec,FindType$ )

END FN

CLEAR LOCAL FN ProcessFolder( SearchKind,inFldSpec As .FSSpec,FindType$ )
DIM scanStuff As FileScanRec

inFldSpec.parID     = FN GetFolderDirID( inFldSpec, _zTrue )
scanStuff.ScanSpec  = inFldSpec
scanStuff.ScanIndex = 0
WHILE USR SCANFOLDER( scanStuff ) >= 0

   FN AddToFileList(scanStuff.ScanSpec.name,scanStuff.type,¬

scanStuff.ScanSpec.parID,scanStuff.ScanSpec.vRefNum)
WEND

END FN


CLEAR LOCAL MODE
LOCAL FN GetFolderDirID( inFldSpec As .FSSpec, canCreateFolder As Boolean
)
Dim @ dirID   As Long
Dim   fldSpec As FSSpec
Dim   pb      As CInfoPBRec

LONG IF FN FSMakeFSSpec( inFldSpec.vRefNum, ¬
                           inFldSpec.parID, ¬
                            inFldSpec.name, ¬
                                   fldSpec ) = _fnfErr
  LONG IF canCreateFolder
    LONG IF FN FSpDirCreate(         fldSpec, ¬
                        _smCurrentScript, ¬
                                   dirID ) != _noErr
      EXIT FN
    END IF
  END IF
XELSE
  pb.ioNamePtr   = @inFldSpec.name
  pb.ioVRefNum   = inFldSpec.vRefNum
  pb.ioDirID     = inFldSpec.parID
  pb.ioFDirIndex = 0
  IF FN PBGetCatInfoSync( pb ) THEN EXIT FN
  dirID = pb.ioDirID
END IF

END FN = dirID

CLEAR LOCAL FN AddToFileList(FileName$,FilTyp&,fParID&,fVrefNum)
    'This just puts the info into arrays for storage & display by the
pop-up,
    'nothing of interest here

     '(Note that although I collect the fParID&, I haven't actually found
a use for it yet.)
END FN

CLEAR LOCAL FN ShowPictToUser(F$,vRef%)
DIM OKToDraw
DIM PictH as ..Picture
DIM PictRect as rect
DIM OKToDraw


OKToDraw=FN DoesFileExist(F$,vRef%)

'This always returns _false!

LONG IF OKToDraw
    PictH = USR IMAGEFILETOPICT(F$,vRef%)
    LONG IF PictH<>0
        PictRect = PictH..picFrame//PictRect;8 = @PictH..picFrame%
        CALL OFFSETRECT (PictRect, T, L)
        CALL DRAWPICTURE(PictH, PictRect)'draw PICT
        DEF DISPOSEH(PictH)
    END IF
END IF

END FN


CLEAR LOCAL MODE
LOCAL FN DoesFileExist (fName$, fVol%)
DIM Result%
DIM pbBlk.128,OSErr%
DIM filename as STR63
DIM wdRefNum as int

filename=fName$
wdRefNum=fVol%

Result%=FN IsFileThere (filename, wdRefNum)

LONG IF Result%<>0'OSErr% <> _noErr
  Result%=_false
XELSE
  Result%=_zTrue
END IF

END FN=Result%

#If CarbonLib = 0
   CLEAR LOCAL MODE
   LOCAL FN IsFileThere (filename As Str63, wdRefNum As Int)
   '---> Variables
   Dim pb.128
   '---> Does this file exist?
   pb.ioNamePtr&  = @filename
   pb.ioVRefNum%  = wdRefNum

   END FN = FN GetFileInfo (pb)

#Else

   CLEAR LOCAL MODE
   LOCAL FN IsFileThere (filename As Str63, wdRefNum As Int)
   '---> Variables
   Dim pb.128
   '---> Does this file exist?
   pb.ioNamePtr&  = @filename
   pb.ioVRefNum%  = wdRefNum
   Fn FBWDToPBWD(pb)
   END FN = FN PBHGetFInfoSync (pb)
#Endif


===  John McKernon Software  ===
==   mckernon@...   ==
==      www.mckernon.com      ==