[futurebasic] Ok, where's the bug?

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : July 2002 : Group Archive : Group : All Groups

From: Pete Beaumont <furbies@...>
Date: Wed, 31 Jul 2002 01:48:06 +1000
In the code below, I can pick a file, save a file, choose a 
folder, but when I open a file, I can't get the path.

I'm trying to write a single FN that will do:
fName = FILES$(_FSSpecOpen,, "Open file...", FSSpec)
fName = FILES$(_FSSpecSave, "Save as...", defaultFName, FSSpec)
fName = FILES$(_FSSpecFolder, "Choose folder...",, FSSpec)

so I can do a PBGETCATINFOSYNC and then my app can do it's thing.


Can someone see what I did wrong ?

(Sorry about the size of the post)

Run the code in Console Mode in PPC


/* Code Begins */

gFBUseNavServices = _zTrue

include "Util_Files.incl"


'~'4


Begin Record CInfoPBRec
DIM qLink AS PTR//queue link in header
DIM qType AS short//type byte for safety check
DIM ioTrap AS short//FS: the Trap
DIM ioCmdAddr AS Ptr//FS: address to dispatch to
DIM ioCompletion AS PROC//completion routine addr (0 for synch calls)
DIM ioResult AS WORD//result code
DIM ioNamePtr AS PTR//ptr to Vol:FileName string
DIM ioVRefNum AS short//volume refnum (DrvNum for Eject and MountVol)
DIM ioFRefNum AS short
DIM ioFVersNum AS SInt8
DIM filler1 AS SInt8
DIM ioFDirIndex AS short
DIM ioFlAttrib AS SInt8
DIM ioACUser AS SInt8
Begin Union
DIM ioFlFndrInfo AS FInfo
DIM ioDrUsrWds AS DInfo
End Union
Begin Union
DIM ioDirID AS long
DIM ioDrDirID AS long
End Union
Begin Union
DIM ioFlStBlk AS unsigned short
DIM ioDrNmFls AS unsigned short
End Union
DIM ioFlLgLen AS long
DIM ioFlPyLen AS long
DIM ioFlRStBlk AS unsigned short
DIM ioFlRLgLen AS long
DIM ioFlRPyLen AS long
Begin Union
DIM ioFlCrDat AS unsigned long
DIM ioDrCrDat AS unsigned long
End Union
Begin Union
DIM ioFlMdDat AS unsigned long
DIM ioDrMdDat AS unsigned long
End Union
Begin Union
DIM ioFlBkDat AS unsigned long
DIM ioDrBkDat AS unsigned long
End Union
Begin Union
DIM ioFlXFndrInfo AS FXInfo
DIM ioDrFndrInfo AS DXInfo
End Union
Begin Union
DIM ioFlParID AS long
DIM ioDrParID AS long
End Union
DIM ioFlClpSiz AS long
End Record

#DEFINE CInfoPBPtr AS POINTER TO CInfoPBRec


'~'4


dim gCInfoPBRec         as CInfoPBRec
dim gCInfoPBRecFileName as str255

def blockfill(@gCInfoPBRec, sizeof(CInfoPBRec), _nil)

gCInfoPBRec.ioNamePtr = @gCInfoPBRecFileName
gCInfoPBRecFileName = ""


'~'4


clear local mode
local fn GenericFILES(filesDoWhat as int, CInfoPBRecPtr as ptr 
to CInfoPBRec)

dim FSSpec             as FSSpec
dim osErr              as int
dim fileFolderSelected as int
dim defaultFName       as str255
dim fName              as str255

dim errMsg as str255

'~';

long if pstr$(CInfoPBRecPtr.ioNamePtr) <> ""
defaultFName = pstr$(CInfoPBRecPtr.ioNamePtr)
xelse
defaultFName = "Untitled Document"
end if

'~';

select filesDoWhat
case _FSSpecOpen
fName = FILES$(filesDoWhat,, "Open file...", FSSpec)

case _FSSpecSave
fName = FILES$(filesDoWhat, "Save as...", defaultFName, FSSpec)

case _FSSpecFolder
fName = FILES$(filesDoWhat, "Choose folder...",, FSSpec)
end select

'~';

long if fName <> ""

select filesDoWhat
case _FSSpecOpen
pstr$(CInfoPBRecPtr.ioNamePtr) = FSSpec.name
CInfoPBRecPtr.ioFDirIndex = 0

case _FSSpecSave/* The file doesn't yet exist so don't specify a 
file name */
pstr$(CInfoPBRecPtr.ioNamePtr) = ""
CInfoPBRecPtr.ioFDirIndex = 0

case _FSSpecFolder
pstr$(CInfoPBRecPtr.ioNamePtr) = FSSpec.name
CInfoPBRecPtr.ioFDirIndex = -1
end select

CInfoPBRecPtr.ioVRefNum = FSSpec.vRefNum
CInfoPBRecPtr.ioDrDirID = FSSpec.ParID

osErr = fn pbgetcatinfosync(CInfoPBRecPtr)

long if osErr = _noErr
select filesDoWhat
case _FSSpecOpen/* The file is already in the CInfoPBRec */
case _FSSpecSave/* Pass back the file name the user entered */
pstr$(CInfoPBRecPtr.ioNamePtr) = FSSpec.name
case _FSSpecFolder/* The file is already in the CInfoPBRec */
end select
fileFolderSelected = _true
xelse
// FN showGetCatInfoErr(osErr)
beep
errMsg = "pbGetCatInfoSync error:" + str$(osErr)
def debugstring(errMsg)
end if

end if

end fn = fileFolderSelected


'~'4


local fn showResults

dim d1$, d2$, err%

d1$ = pstr$(gCInfoPBRec.ioNamePtr)

err = usr GetFullPathName(gCInfoPBRec.ioVRefNum, 
gCInfoPBRec.ioDirID, d2$)
if err <> _noErr then d2$ = "ERROR:" + str$(err)

print "File Name", d1$//pstr$(gCInfoPBRec.ioNamePtr)
print "Folder Path", d2$
print
print "ioVRefNum & ioDirID", gCInfoPBRec.ioVRefNum, gCInfoPBRec.ioDirID
print

end fn


'~'4


print "Open a file"
long if fn GenericFILES(_FSSpecOpen, @gCInfoPBRec)
fn showResults
end if


print "========================================================="
print "Save a file"
long if fn GenericFILES(_FSSpecSave, @gCInfoPBRec)
fn showResults
end if


print "========================================================="
print "Choose a folder"
long if fn GenericFILES(_FSSpecFolder, @gCInfoPBRec)
fn showResults
end if
print "========================================================="


'~'4

/* Code Ends */


Pete...                          (the other one)