FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

DISK I/O

Force standard dialog to open on a given directory


Here are some clips from a quick and dirty program I wrote in FBII - PG. It remembers two locations: A folder where it is getting a file and a folder where it is saving a file. It will set the directory so the Open and Save dialogs reflect the correct folder. By way of a hint, setting the directry for Open or Save will break if your user has "Last Folder" chosen in General Controls. This little program works fine, even if the folders are on different volumes. I have used the Usealias- GetWDrefNum- SetFolder successfully to mount a volume and set the directory for GetFile when a volume in a different zone. MakeAlias and UseAlias are in the PG HSFUtil.fltr in PG Fn GetWDRefNum is Rick Brown's SetFIlesFolder is Andy G's The rest of the spagetti is mine. The myFSSpec.fsSpec and myFSSpec.fsSpec1 stuff was to keep from getting an already dimmed error when I was trying to convert to FB^3. I just left it. 1003 and 1004 are the Resources where I store the two alias
_myProcID = _"BSCA"        '  the app's type
'-------------------------------------------------
CLEAR LOCAL
DIM iopb.52
DIM OSErr
LOCAL FN GetWDRefNum(volumeID, dirID&,OSErrAddr&)
'Call as follows:
'  wdRefNum = FN GetWDRefNum(volumeID, dirID&, @OSErr)
'Returns a Working Directory Reference Number, given a
'_true_ volume reference number (volumeID) and a directory
'ID (dirID&).  The wdRefNum should be used in most places
'where FB documentation talks about a "volume reference number".
  iopb.ioCompletion& = 0
  iopb.ioNamePtr& = 0
  iopb.ioVRefNum% = volumeID
  iopb.ioWDDirID& = dirID&
  iopb.ioWDProcID& = _myProcID
  OSErr = FN OPENWD(@iopb)
  POKE WORD OSErrAddr&, OSErr
END FN = iopb.ioVRefNum%

CLEAR LOCAL MODE
DIM pBlock.128
DIM Noerr&
LOCAL FN SetFilesFolder(Vref%)
  pBlock.ioVRefNum% = Vref%

  LONG IF FN GETCATINFO(@pBlock) = _NoErr
    & _CurDirStore , pBlock.ioDirID&
    pBlock.ioWDProcID&  = 0
    pBlock.ioWDVRefNum% = 0
    LONG IF FN GETWDINFO(@pBlock) = _NoErr
      % _SFSaveDisk , -pBlock.ioWDVRefNum%
    END IF
    NoErr&=FN FLUSHVOL(@pBlock)
  END IF
END FN

CLEAR LOCAL
DIM osErr
DIM useAlias
DIM RECORD fsSpec
DIM fsVrefNum%
DIM fsParID&
DIM 63 fsName$
DIM END RECORD .fsSpec

DIM myFSSpec.fsSpec

LOCAL FN MySave

  osErr=FN useAlias(1003,myFSSpec)
    LONG IF osErr=0
      PARENTID=myFSSpec.fsParID&
      gSaveVol=FN GetWDRefNum(myFSSpec.fsVrefNum%,myFSSpec.fsParID&,@OSErr)
    END IF
    IF gSaveVol<>0 THEN FN SetFilesFolder(gSaveVol)
'
END FN

CLEAR LOCAL
DIM osErr
DIM useAlias
DIM RECORD fsSpec1
DIM fsVrefNum1%
DIM fsParID1&
DIM 63 fsName1$
DIM END RECORD .fsSpec1

DIM myFSSpec.fsSpec1

DIM osErr%
DIM pickupVol,makeAlias
DIM type$
LOCAL FN mySave

  IF gSaveName$<>"" THEN KILL gSaveName$,gSaveVol
  LONG IF gMyVol%=0
    osErr=FN useAlias(1004,myFSSpec)
    gmyVol%=FN GetWDRefNum(myFSSpec.fsVrefNum1%,myFSSpec.fsParID1&,@OSErr)
    LONG IF gmyVol%<>0
      FN SetFilesFolder(gMyVol%)
    END IF
'
  END IF
All this is presupposes you have done something like this before:
makeAlias=FN makeAlias(YourFileName$,gSaveVol,1003)
and
makeAlias=FN makeAlias(YourFileName$,gSaveVol,1004)
George

cwordVRefNum% = FOLDER("Crosswords",SYSTEM(_aplVol))
<snip>
LOCAL FN savecross
FN SetOpenFolder(cwordVRefNum%)
I don't see, in you code, where you are picking up the At Ease Documents Folder reference. Assuming you have that number, or think you have that number, I will tell you what I have learned about volRefs and the like. If you don't have it, perhaps someone smarter than me will tell you where it is hiding.

Once you try to begin using this number, here are the pitfalls I found in school settings.

Getting Macs to set OpenFiles has been a real chore for me. Rick Brown was such a huge help that after struggling for almost two years (off and on) I have my apps able to set the Open Folder * most of the time * . I am sure Rick can shed more light on this than I. What I want to do here is attempt to summarize what Rick taught me.

I am not familiar with At Ease's way of setting the folder. I would not be overly shocked if they are using an alias. (We tried At Ease 2.0 on our network years ago and it just would not work for us with AppleShare.) Hopefully in my meanderings below, we will figure all this out.

When I said * most of the time * it works like this : If you set FN SetFilesFolder(Vref%) [this is Andy's routine. I put it below as it is a little fuller than the routine you are currently using] it works if :

1) In 7.5 + the General Settings are not set to "Last Folder Used"
2) In 7.5 + General Settings are set to "Last Folder Used" but the user has not called anything that uses the standard GetFile toolbox routine.
3) Before System 7.5

Number 2 is where I think many of the Folder setting get confused :

What I wanted, and finally accomplished, was to have a "Get Last File" menu item that resolved an alias I had created and stored. If the alias resided on a network volume, the volume was mounted (along with password dialog) and the file was opened. Now came the tricky part. If the wanted to open another file, I wanted the dialog to be set to the folder where the file pointed to by the alias resided. That broke. And broke. And broke. Until Rick rescued me.
The first routine below is Rick Brown's It uses the information from the alias to get the Vref% (wdRefNum) that Andy's routine (and most FB file operations) need. Once I had the Vref% Andy's routine worked...unless an open dialog was called * Before * I had a chance to run my routine.
To explain that last sentence, If a user started my app, and used the Get Last File menu item, the volume was mounted, directories set and all was well. If, however, first thing in the morning they launch the App and try to use Open, they find the server is not mounted. Then they think, Oh, I should have used get last file. They do, the alias is resolved, the volume is mounted and the file opened. Now comes the bad part. When the next open is called, the directory is set according to the settings in General Settings. If Last File setting is used, the finder now thinks the last file used was the Open attempted at when they first launched the app. The Last File Used only works if the volume is mounted before an open dialog. It does not remember volumes as an alias does.

Rick's Routine

_myProcID = _"PGGP"
' ------------------------------------------------- 
CLEAR LOCAL
  DIM iopb.52
  DIM OSErr
LOCAL FN GetWDRefNum(volumeID, dirID&,OSErrAddr&)
'Call as follows : 
' wdRefNum = FN GetWDRefNum(volumeID, dirID&, @OSErr)
'Returns a Working Directory Reference Number, given a
'_true_ volume reference number (volumeID) and a directory
'ID (dirID&). The wdRefNum should be used in most places
'where FB documentation talks about a "volume reference number".
  iopb.ioCompletion& = 0
  iopb.ioNamePtr& = 0
  iopb.ioVRefNum% = volumeID
  iopb.ioWDDirID& = dirID&
  iopb.ioWDProcID& = _myProcID
  OSErr = FN OPENWD(@iopb)
  POKE WORD OSErrAddr&, OSErr
END FN = iopb.ioVRefNum%
Andy's Routine available at the STAZ site.
CLEAR LOCAL MODE
  DIM pBlock.128
  DIM Noerr&
LOCAL FN SetFilesFolder(Vref%)
  pBlock.ioVRefNum% = Vref%

  LONG IF FN GETCATINFO(@pBlock) = _NoErr
    & _CurDirStore , pBlock.ioDirID&
    pBlock.ioWDProcID& = 0
    pBlock.ioWDVRefNum% = 0
    LONG IF FN GETWDINFO(@pBlock) = _NoErr
      % _SFSaveDisk , - pBlock.ioWDVRefNum%
    END IF
    NoErr& = FN FLUSHVOL(@pBlock)
  END IF
END FN
Part of my Alias Resolution
CLEAR LOCAL
  DIM osErr
  DIM useAlias
  DIM RECORD fsSpec
    DIM fsVrefNum%
(This is NOT the VolRefNum used by FB or Andy's routine. Took Rick and David two or three tries to get that in my head)
  DIM fsParID&
  DIM 63 fsName$
DIM END RECORD .fsSpec

DIM myFSSpec.fsSpec
DIM test
LOCAL FN SeeAboutAQuickOpen

osErr = FN useAlias(1003,myFSSpec) ' A PG Routine
I call Rick's Routine right here and then Andy's upon getting the file successfully open. Remember, at this point I am only using an alias and no Open Dialog has been called.

I hope this gets you a few steps closer.

George