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

Handle a preferences file


Those couple of lines may come back to haunt you. You've used a pathname for the system folder and while 99% of the users won't rename the system folder, some do. And Apple says its a bad idea and is prone to failure.

Better to use the toolbox FINDFOLDER.

CLEAR LOCAL MODE
LOCAL FN getWDRefNum(dirID&,vRef)
  DIM pBlk.200
  pBlk.ioWDDirID& = dirID&
  pBlk.ioWDProcID&= _"ERIK"
  pBlk.ioVRefNum = vRef
  OSErr%=FN OPENWD(@pBlk)
END FN=pBlk.ioVRefNum
'
LOCAL MODE
LOCAL FN fndPrefFile(@ptr&)
  OSErr=FN FINDFOLDER(_kOnsystemdisk,_KpreferencesFolderType,0,pVRef,pDirID&)
  LONG IF OSErr=_noErr
    prefRef=FN getWDRefNum(pDirID&,pVRef)
   POKE WORD ptr&,prefRef
  END IF
END FN=OSErr

LOCAL FN HandleDiskError:' handles the disk errors we can encounter
  SELECT ERROR AND 255:' mask out the error code itself
    CASE _fileNotFound
      FN LoadDefaultPrefs:' load the default prefs
      OSErr=FN fndPrefFile(prefVol):' find the preferences volume for us
      FN PrefsWrite:' go create the prefs file
  END SELECT
  ERROR=_noErr:' reset the error condition
END FN
'
LOCAL FN PrefsRead
  ON ERROR GOSUB 65535:' enable our own error testing
  ON ERROR FN HandleDiskError:' use my routine for handling a disk error
  DEF OPEN "PrefAPPL":' type and creator
  OPEN "I",#1,prefsName$,,prefVol:' read our pref file
  theLen=LOF(1,1):' see what the length of the file is
  LONG IF theLen<>_prefsLen:' has the size changed?
    CLOSE #1:' just close the file for us
    FN LoadDefaultPrefs:' go load in the default prefs we can use
    FN PrefsWrite:' and then write them out and replace the old ones
  XELSE
   READ FILE #1,@printFrame,_prefsLen:' read in simple variables
   CLOSE #1:' it resumes here from the error condition
  END IF
  ON ERROR RETURN:' turn off the error checking
END FN

LOCAL FN DoPrefs
  OSErr=FN fndPrefFile(prefVol):' go find the preferences volume for us
  FN PrefsRead:' and read in the prefs for this user, if there are any
END FN
'

Mel Patrick