[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to find System folder?



>I'm using the find-special-folder to find #$kPreferencesFolderType.
>It works fine in System 7 but gives "unimplemented trap" error in
>System 6.07. How to make it running in both?

At 11:40 AM 94.11.03 -0500, Steve Strassmann wrote:
>I think Preference Folders were invented with System 7. Before
>that, all preferences just cluttered up your System Folder.

Here's a C function to do it; I don't remember where I originally found it
(probably the  CD-ROM from Apple Developer Support)...

#include <GestaltEqu.h>

#define BTstQ(arg, bitnbr)        (arg & (1 << bitnbr))

static OSErr findPrefFolder( short *foundVRefNum, long *foundDirID )
{
  long          gesResponse;
  SysEnvRec     envRec;
  WDPBRec       myWDPB;
  unsigned char volName[34];
  OSErr         err;

  *foundVRefNum = 0;
  *foundDirID = 0;
  if ( !Gestalt( gestaltFindFolderAttr, &gesResponse )
                && BTstQ( gesResponse, gestaltFindFolderPresent ) )
  { /* Folder Manager exists */
    err = FindFolder( kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
                       foundVRefNum, foundDirID );
  }
  else
  { /* Gestalt can't give us the answer, so we resort to SysEnvirons */
    if ( !(err = SysEnvirons( curSysEnvVers, &envRec )) )
    {  myWDPB.ioVRefNum = envRec.sysVRefNum;
       volName[0] = '\000';                   /* Zero volume name */
       myWDPB.ioNamePtr = volName;
       myWDPB.ioWDIndex = 0;
       myWDPB.ioWDProcID = 0;
       if ( !(err = PBGetWDInfo( &myWDPB, 0 )) )
       { *foundVRefNum = myWDPB.ioWDVRefNum;
         *foundDirID = myWDPB.ioWDDirID;
       }
    }
  }
  return (err);
}