Pararena2/Sources/Prefs.c

1 line
9.7 KiB
C
Raw Normal View History

/*============================================================*/ /*============================================================*/ /*== ==*/ /*== Preferences Handling File ==*/ /*== ==*/ /*============================================================*/ /*============================================================*/ /*======================================================== Includes */ #include "Globals.h" #include "UnivUtilities.h" #include "Prefs.h" #include <Folders.h> #include <GestaltEqu.h> #include <Script.h> #include "FileError.h" /*======================================================== Globals */ extern macEnvironment thisMac; /*======================================================== CanUseFindFolder */ Boolean CanUseFindFolder (void) { OSErr theErr; long theFeature; if (!thisMac.hasGestalt) return(FALSE); theErr = Gestalt(gestaltFindFolderAttr, &theFeature); if (theErr != noErr) return(FALSE); if (!BitTst(&theFeature, 31 - gestaltFindFolderPresent)) return(FALSE); return(TRUE); } /*======================================================== GetPrefsFPathSyst7 */ Boolean GetPrefsFPathSyst7 (long *prefDirID, short *systemVolRef) { OSErr theErr; theErr = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder, systemVolRef, prefDirID); if (theErr != noErr) return(FALSE); return(TRUE); } /*======================================================== CreatePrefsFolder */ Boolean CreatePrefsFolder (short *systemVolRef) { HFileParam fileParamBlock; Str255 folderName; OSErr theErr; GetIndString(folderName, rPrefsStringsID, kPrefsFNameIndex); if (folderName[0] == 0) PasStringCopy((StringPtr)&folderName, (StringPtr)kDefaultPrefFName); fileParamBlock.ioVRefNum = *systemVolRef; fileParamBlock.ioDirID = 0; fileParamBlock.ioNamePtr = folderName; fileParamBlock.ioCompletion = kNilPointer; theErr = PBDirCreate((HParmBlkPtr)&fileParamBlock, FALSE); if (theErr != noErr) { CheckFileError(theErr, "\pPreferences"); return(FALSE); } return(TRUE); } /*======================================================== GetPrefsFPathSyst6 */ Boolean GetPrefsFPathSyst6 (short *systemVolRef) { Str255 folderName; SysEnvRec thisWorld; CInfoPBRec catalogInfoPB; DirInfo *directoryInfo = (DirInfo *) &catalogInfoPB; HFileInfo *fileInfo = (HFileInfo *) &catalogInfoPB; WDPBRec workingDirPB; long prefDirID; OSErr theErr; GetIndString(folderName, rPrefsStringsID, kPrefsFNameIndex); if (folderName[0] == 0) PasStringCopy((StringPtr)&folderName, (StringPtr)kDefaultPrefFName); theErr = SysEnvirons(2, &thisWorld); if (theErr != noErr) return(FALSE); *systemVolRef = thisWorld.sysVRefNum; fileInfo->ioVRefNum = *systemVolRef; fileInfo->ioDirID = 0; fileInfo->ioFDirIndex = 0; fileInfo->ioNamePtr = folderName; fileInfo->ioCompletion = kNilPointer; theErr = PBGetCatInfo(&catalogInfoPB, FALSE); if (theErr != noErr) { if (theErr != fnfErr) { CheckFileError(theErr, "\pPreferences"); return(FALSE); } if (!CreatePrefsFolder(systemVolRef)) return(FALSE); directoryInfo->ioVRefNum = *systemVolRef; directoryInfo->ioFDirIndex = 0; directoryInfo->ioNamePtr = folderName; theErr = PBGetCatInfo(&catalogInfoPB, FALSE); if (theErr != noErr) { CheckFileError(theErr, "\pPreferences"); return(FALSE); } } prefDirID = directoryInfo->ioDrDirID; workingDirPB.ioNamePtr = nil; workingDirPB.ioVRefNum = *systemVolRef; workingDirPB.ioWDIndex = 0; workingDirPB.ioWDProcID = 0; workingDirPB.ioWDVRefNum = 0; workingDirPB.ioCompletion = kNilPointer; theErr = PBGetWDInfo(&workingDirPB, FALSE); if (theErr != noErr) { CheckFileError(theErr, "\pPreferences"); return(FALSE); } *systemVolRef = workingDirPB.ioWDVRefNum; workingDirPB.ioNamePtr = nil; workingDirPB.ioWDDirID = prefDirID; workingDirPB.ioVRefNum = *systemVolRef; workingDirPB.ioWDProcID = 0; workingDirPB.ioCompletion = kNilPointer; theErr = PBOpenWD(&workingDirPB, FALSE); if (theErr != noErr) { Che