chet@arc.UUCP (Chet Wood) (02/14/90)
Hi,
I feel a little sheepish about not being able to translate a little
pascal to c. but why beat my head against the wall, when maybe
somebody else has been there? So there's this technote 67 that tells
how to do it, right? And yes, the compiler pointed out a coupla gotchas
in my first try at translating it. Now can somebody point out the
others?
Here's the code (Think C 4.0)
Str255 prefFileName = "\pMy Prefs";
/*extern int FSFCBLen :0x3f6;*/
public void OpenPrefs()
{
OSErr errnum = 0;
int OldVol;
/* try to open resource file */
/* before that, find out refnum of application's resource file */
applResFile = CurResFile();
if (OpenResFile(prefFileName) == -1)
errnum = ResError();
if ( errnum == fnfErr ) /* create it */
{
/* first find blessed folder */
/* from TN 67 */
HParamBlockRec myHPB; /* for the PBHGetVInfo call */
WDPBRec myWDPB; /* for the PBHSetVol call */
Str255 vName;
int *HFS; /* to check to see if we're running HFS */
HFS = &FSFCBLen;
if ( *HFS > 0 )
{
vName[0] = 0;
myHPB.volumeParam.ioCompletion = NULL;
myHPB.volumeParam.ioNamePtr = vName;
/* get for default volume */
/* Note: TN67 sets this to 0.
* I tried it that way, but the default
* volume is the one the application started
* up from, right? And the active system
* folder may well be on another volume
* (in my debugging environment, it is)
*/
myHPB.volumeParam.ioVRefNum = BootDrive;
/* we're not making indexed calls */
myHPB.volumeParam.ioVolIndex = 0;
errnum = PBHGetVInfo( &myHPB, FALSE);
if ( errnum )
/* what? */;
}
myWDPB.ioCompletion = NULL;
myWDPB.ioNamePtr = NULL;
myWDPB.ioVRefNum = 0;
myWDPB.ioWDDirID = myHPB.volumeParam.ioVFndrInfo[1];
errnum = GetVol(NULL, OldVol);
errnum = PBHSetVol(&myWDPB,FALSE);
if (errnum)
;
CreateResFile(prefFileName);
if (OpenResFile(prefFileName) == -1)
errnum = ResError();
SetVol( NULL, OldVol); /* restore */
}
}
Thanks for any help.
Chet.
--
Chet Wood ~ (408)727-3357
arc!chet@apple.COM . Advansoft Research Corporation
chet@arc.UUCP . 4301 Great America Parkway
apple!arc!chet . Santa Clara, CA 95054, USAbeard@ux1.lbl.gov (Patrick C Beard) (02/14/90)
If you want a working directory for the blessed folder, use SysEnvirons. It's so much easier. SysEnvRec theWorld; short sysFolderWD; SysEnvirons(2, &theWorld); sysFolderWD = theWorld.sysVRefNum; Use whatever calls you want to create and open your file in the system folder. ------------------------------------------------------------------------------- - Patrick Beard, Macintosh Programmer (beard@lbl.gov) - - Berkeley Systems, Inc. ".......<dead air>.......Good day!" - Paul Harvey - -------------------------------------------------------------------------------